group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_2697_cpp
Problem K Runner and Sniper You are escaping from an enemy for some reason. The enemy is a sniper equipped with a high-tech laser gun, and you will be immediately defeated if you get shot. You are a very good runner, but just wondering how fast you have to run in order not to be shot by the sniper. The situation is as ...
[ { "submission_id": "aoj_2697_2139713", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ndouble PI=acos(-1);\ndouble eps=1e-7;\ntypedef complex<double> P;\n\ndouble modf(double x){\n while(x>2*PI){\n x-=2*PI;\n }\n while(x<0){\n x+=2*PI;\n }\n return x;\n}\n\ndouble x,y,a,b;\n\ndoub...
aoj_2696_cpp
Problem J New Game AI Aoba is a beginner programmer who works for a game company. She was appointed to develop a battle strategy for the enemy AI (Artificial Intelligence) in a new game. In this game, each character has two parameters, hit point ($hp$) and defence point ($dp$). No two characters have the same $hp$ and ...
[ { "submission_id": "aoj_2696_10319485", "code_snippet": "// AOJ #2098 Two-finger Programming\n// 2025.3.23\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst int NMAX = 50005;\n\nint n, c;\nint usd[NMAX] = {0};\nint flag[NMAX] = {0};\nint nw = 1, tp = 1;\nint stk[NMAX];\nint c...
aoj_2693_cpp
Problem G JAG-channel II JAG (Japan Alumni Group) is a group of $N$ members that devotes themselves to activation of the competitive programming world. The JAG staff members talk every day on the BBS called JAG-channel. There are several threads in JAG-channel and these are kept sorted by the time of their latest posts...
[ { "submission_id": "aoj_2693_10866702", "code_snippet": "//ΔAIZU2693\n#include<iostream>\n#include<cstdio>\n#include<fstream>\n#include<algorithm>\n#include<vector>\n#include<map>\n#include<set>\n#include<queue>\n#include<bitset>\n#include<cmath>\n#include<cstring>\n#include<cstdlib>\nusing namespace std;\n...
aoj_2698_cpp
Problem L Wall Making Game The game Wall Making Game , a two-player board game, is all the rage. This game is played on an $H \times W$ board. Each cell of the board is one of empty , marked , or wall . At the beginning of the game, there is no wall on the board. In this game, two players alternately move as follows: A...
[ { "submission_id": "aoj_2698_10850936", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define nn 22\n\nint n,m;\nchar _map[nn][nn];\nint dp[nn][nn][nn][nn];\n\n\nint dfs(int x1,int y1,int x2,int y2){\n\tif(x1>x2 or y1>y2) return 0;\n\tif(dp[x1][y1][x2][y2]>-1) return dp[x1][y1][x2][y2];\n\...
aoj_2700_cpp
Airport Codes 空港コード JAG王国では国内の空港にそれぞれ空港コードを割り当てて識別をしている. 空港コードは,小文字の英語アルファベットで表記した空港の名前をもとに以下の規則で割り当てられる: 名前の最初の文字と,母音 (a,i,u,e,o) の直後の文字を順に取り出す. 取り出した文字列が k 文字未満ならそれを空港コードとし, k 文字以上なら,その取り出した文字列の先頭 k 文字を空港コードとして使う. 例えば k = 3 のとき,haneda には hnd , oookayama には ooo , tsu には t というコードが割り当てられる. しかしこのコードの割り当て方では,違う名前の空港でも同じコー...
[ { "submission_id": "aoj_2700_10609632", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<ll, 2>;\nusing a3 = array<ll, 3>;\n\ntemplate <typename A> void chmin(A &l, const A &r) {\n if(r < l)\n l = r;\n}\ntemplate <typename A> void chmax(A &l,...
aoj_2695_cpp
Problem I Midpoint One day, you found $L + M + N$ points on a 2D plane, which you named $A_1, ..., A_L, B_1, ...,B_M, C_1,...,C_N$. Note that two or more points of them can be at the same coordinate. These were named after the following properties: the points $A_1,...,A_L$ were located on a single straight line, the po...
[ { "submission_id": "aoj_2695_10850559", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n#define nn 65536*8\nstruct point{\n\tll x,y;\n\tpoint (ll xx=0,ll yy=0){\n\t\tx=xx,y=yy;\n\t}\n};\npoint operator-(point a,point b){\n\treturn point(a.x-b.x,a.y-b.y);\n}\npoint opera...
aoj_2701_cpp
Falling Block Puzzle ブロック落とし あなたはある落ち物パズルで遊んでいる. このパズルのフィールドは,下図のように各段に立方体のセルが2マス×2マスに並び,段が上に無限に並んでいる形をしている. それぞれのセルは,セルにぴったり収まるブロックが1つ存在するか,何もないかのどちらかである. このパズルは以下のように進行する. 初期状態としていくつかのブロックが設置されている. 2マス×2マス×2マスに収まるブロックの塊を上から落とす.ただし,落とす前に,ブロックがフィールドからはみ出さないようにして塊を水平方向に平行移動することができる. 落としたブロックのうち,ある1つの下面が,すでに置かれているブロックまたは...
[ { "submission_id": "aoj_2701_9359705", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing vll = vector<ll>;\nusing vvll = vector<vll>;\nusing vvvll = vector<vvll>;\n#define rep(i,n) for(ll i=0;i<ll(n);i++)\n#define all(A) A.begin(),A.end()\n\nvoid chmax(ll& p, ll q)...
aoj_2702_cpp
Alternate Escape アリスハウス AliceとBobはボードゲームで遊んでいる. このボードゲームは, H 行 W 列のマス目が書かれた盤面と1つのコマを使って遊ぶ. このゲームでは,盤面の左上のマスを1行1列目として,下方向に行を,右方向に列を数える. マス同士が隣接する辺と,マスが盤面の外側と接する辺には壁を置けるようになっていて,ゲームの開始時にはそれぞれの辺について壁の有無が指定されている.また,ゲームの開始時には,コマが盤面のマスのいずれか1箇所に置かれている. AliceとBobは交互に手番をこなすことでゲームを進める. ゲームはAliceの手番から始まる. Aliceの目的は,コマを盤面の外まで動かして,...
[ { "submission_id": "aoj_2702_10946050", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <vector>\n#include <iostream>\n\nusing namespace std;\n\nint n, m, row, col;\n\nconst int N = 600;\n\nint ver[N][N];\nint hor[N][N];\nint visit[N][N][2][2];\nint deg[N][N][2][2];\n\nstruct Node {\n\tint ...
aoj_2705_cpp
Kuru Kuru Door くるくるドア ACM (Automatic Cleaning Machine) 社が2011年に開発した全自動円形掃除機 ICPC (Intelligent Circular Perfect Cleaner) は, 日中に自動で動き出し,自分が通り過ぎた場所のゴミを掃除する機能を備えている. 加えて,この ICPC は,バッテリー残量が低下した場合に自動的に電源の位置まで戻る機能も備えている. この度,JAG (Japan Alumni Group) と名乗る謎の組織から, ACM 社に対し大量の ICPC の発注があった. しかし,その発注には条件が付いていた. それは,彼らが本拠地としているビルの内...
[ { "submission_id": "aoj_2705_6022652", "code_snippet": "/*\tauthor: Kite_kuma\n\tcreated: 2021.11.01 22:38:19 */\n\n// #ifdef LOCAL\n// #define _GLIBCXX_DEBUG\n// #endif\n#include <bits/stdc++.h>\nusing namespace std;\n\n#pragma region macros\n\n#define foa(s, v) for(auto &s : v)\n#define all(v) (v).begin(...
aoj_2703_cpp
Dice Stamp サイコロスタンプ あなたは地元の縁日で,今までに見たことがないゲームの出店を発見した. N 個の6面サイコロを,ボード上に落として転がすゲームだ. より正確には, N 個のボタンが N 個のサイコロに1対1に紐付いており,ボタンを押すことで対応したサイコロがボードに落ちる. ボタンを好きなように N 回押し,サイコロを N 回落として転がすことで得点を得るゲームである. ゲームのより詳細なルールを説明しよう. ゲームで使用する N 個のサイコロはすべて各辺の長さが1の立方体であり,ボードは長さが1の正方形のマスに区切られた十分に広い平面である. ゲーム開始前,ボードの各マスにはすべて0が書かれている. 各サイコ...
[ { "submission_id": "aoj_2703_10853814", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<vector>\n#include<cstring>\n#include<algorithm>\nusing namespace std;\nint dx[4] = {1, 0, 0, -1};\nint dy[4] = {0, 1, -1, 0};\n//l r f b d u\n//0 1 2 3 4 5\nint go[4][6] = {\n {5, 4, 2, 3, 0, 1},\n ...
aoj_2704_cpp
Stamp Rally スタンプラリー 日本アミューズメントグループ (Japan Amusement Group, JAG) では,島国を模したテーマパークでのイベントを企画している. このイベントでは,参加者は橋を渡るたびに橋ごとに決められたスタンプをスタンプ帳に順番に押していく. 用意されたスタンプは以下の7種類のどれかである. a ( ) [ ] + * スタートからゴールまで橋を渡り歩いて,押されたスタンプの列が正しい数式になればクリアである. ただし橋を渡る向きは決まっていて,逆向きに渡ることはできない. 同じ橋を何度も渡ってよく,最終的にゴール地点に到着するのであれば一度ゴール地点に着いた後に引き続きスタンプを集めても...
[ { "submission_id": "aoj_2704_10848353", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst int N = 205;\nint id(char c) {\n\tif (c == 'a') return 0;\n\tif (c == '+') return 1;\n\tif (c == '*') return 2;\n\tif (c == '(') return 3;\n\tif (c == ')') return 4;\n\tif (c == '[') return 5;\n\tr...
aoj_2707_cpp
監獄 無限人の囚人たちがいる。はじめ、囚人たちは 0, 1, 2, ... と番号が振られている。 次の操作を N 回行う。 0 番目の囚人を釈放し、 k, 2k, 3k, ... 番目の囚人たちを処刑する。 その後、残った囚人たちに番号を振り直す。このとき、元の番号が小さい囚人から順に 0, 1, 2, ... と番号を振る。 N 回目の操作で釈放される囚人がはじめに振られていた番号を求めよ。 Constraints 1 ≤ N ≤ 10^5 2 ≤ k ≤ 10^5 答えは 10^{18} 以下である。 Input Format 入力は以下の形式で標準入力から与えられる。 N k Output Format 答えを一行に出力せよ...
[ { "submission_id": "aoj_2707_10865966", "code_snippet": "//#define __USE_MINGW_ANSI_STDIO 0\n#include <bits/stdc++.h>\n\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> VI;\ntypedef vector<VI> VVI;\ntypedef vector<ll> VL;\ntypedef vector<VL> VVL;\ntypedef pair<int, int> PII;\n\n#define FOR(...
aoj_2706_cpp
幾何問題を解こう A君は今日も幾何の問題を解いている。 幾何の問題を解く時は浮動小数点誤差に気をつけることが大事である。 浮動小数点誤差とは、2進法の有限小数で数を表す際におこる丸めによって起きる誤差である。 例えば、10進法での 0.1 は2進法では 0.00011001100110011 ... という無限小数になるが、 これを有限の桁で丸める際に誤差が発生してしまう。 正の整数 p , q が10進法で与えられる。 有理数 p / q を有限桁数の小数で表現することができるような b 進法( b は2以上の整数)を求めよ。 複数ある場合は最も小さいものを出力せよ。 Constraints 0 < p < q < 10^9 In...
[ { "submission_id": "aoj_2706_5768373", "code_snippet": "#include <bits/stdc++.h>\n\n#define lol long long\n#define gcd(x, y) __gcd(x, y)\n#define mt make_tuple\n#define mp make_pair\n#define fi first\n#define se second\n#define fixed(x) fixed << setprecision(x)\n#define all(x) x.begin(),x.end()\nusing names...
aoj_2708_cpp
ABC Gene 文字列 ABC で表される遺伝子配列がある。あなたは次の操作を何回か行い、この遺伝子配列を書き換えていくことができる。 文字 A , B , C のうち 1 つを選ぶ。これを x とおく。遺伝子配列に含まれるすべての x をそれぞれ ABC へ同時に置き換える。 A , B , C だけからなる文字列 S が与えられる。遺伝子配列を S に一致させられるか判定せよ。 Constraints 1 ≤ |S| ≤ 5,000 S は A , B , C だけからなる。 Input Format 入力は以下の形式で標準入力から与えられる。 S Output Format 遺伝子配列を S に一致させられるならば Yes ...
[ { "submission_id": "aoj_2708_10848475", "code_snippet": "//#define __USE_MINGW_ANSI_STDIO 0\n#include <bits/stdc++.h>\n\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> VI;\ntypedef vector<VI> VVI;\ntypedef vector<ll> VL;\ntypedef vector<VL> VVL;\ntypedef pair<int, int> PII;\n\n#define FOR(...
aoj_2710_cpp
坑道数式 ある日廃坑を探検していたあなたは、坑道に長い数式 S が書かれているのを発見した。大きな数が好きなあなたは、チョークを取り出し、数式を計算した結果ができるだけ大きくなるように ( または ) を書き加えることにした。書き加えた後も数式になっていなければならないとすると、最大でいくつにできるか。 文字と文字の間は十分広く空いていて、 ( または ) であればいくつでも書き加えることができる。最終的に数式になっていれば、最初のかっこの対応が崩れるように ( または ) を書いてもよい(Sample 2参照)。 また、ここでは以下のBNFで定義される<expr>を数式と呼ぶ。数式中の数は全て一桁である。 <expr> ::= ...
[ { "submission_id": "aoj_2710_10849109", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\n\nusing P = pair<int, int>;\n\nconstexpr int INF = 1e9;\n\nP memo[201][201];\n\nP rec(int l, int r, string const& s) {\n P& res = memo[l][r];\n if(res != make_pair(-INF, IN...
aoj_2709_cpp
真っ暗な部屋 目を覚ますと、A君は真っ暗な部屋の中にいた。 どうやらA君は N 個の部屋から構成されたダンジョンに迷い込んでしまったようだ。 あなたはA君がどの部屋に迷い込んだのかを知ることはできなかったが、幸いにもダンジョンのマップを手に入れることができた。 A君の進むべき道を示し明るい部屋に導こう。 N 個の部屋のうち M 個の部屋が真っ暗な部屋であり、それぞれ D_1 , D_2 , ..., D_M 番目の部屋が真っ暗な部屋であることが分かっている。 また、全ての部屋からちょうど K 本の一方通行の道が順に並んでおり、 i 番目の部屋から出る道はそれぞれ v_{i,1} , v_{i,2} , ..., v_{i,K} 番目...
[ { "submission_id": "aoj_2709_10889003", "code_snippet": "#include<bits/stdc++.h>\n// #include<atcoder/all>\n// #include<boost/multiprecision/cpp_int.hpp>\n\nusing namespace std;\n// using namespace atcoder;\n// using bint = boost::multiprecision::cpp_int;\nusing ll = long long;\nusing ull = unsigned long lo...
aoj_2719_cpp
Problem C: Kuru Kuru Sushi Zephir is an owner of the kuru kuru sushi restaurants. In these restaurants, sushis are placed on a rotating circular belt conveyor and delivered to customers. Zephir owns $n$ restaurants numbered from $0$ to $n - 1$. Due to his passion for rotation, these restaurants are placed on the circum...
[ { "submission_id": "aoj_2719_10323024", "code_snippet": "// AOJ #2719 Kuru Kuru Sushi\n// 2025.3.25\n\n#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tdo n = 10*n + (c & ...
aoj_2712_cpp
Escape 頂点に正の値を持つ無向グラフが与えられる。 頂点には 1 から N の番号がついており、 i 番目の頂点は w_i の値を持っている。 1 番目の頂点からスタートし、直前に通った辺を通ることができないという制約のもとでグラフ上を移動することができる。 各頂点では,初めて訪れた時に限りその頂点が持つ値の点数を得られる。 取得できる点数の総和の最大値を求めよ。 Constraints 1 ≤ N ≤ 100000 N − 1 ≤ M ≤ 100000 1 ≤ w_i ≤ 1000 1 ≤ u_i, v_i ≤ N 多重辺・自己辺は存在しない グラフは連結である Input Format 入力...
[ { "submission_id": "aoj_2712_10858280", "code_snippet": "#include<iostream>\n#include<vector>\n#include<utility>\n\nusing namespace std;\n\ntypedef pair<int, int> Pii;\n\nvector<int> graph[100001];\nvector<int> dim(100001, 0);\nvector<Pii> nodes(100001);\nvector<bool> used(100001, false);\n\nint dfs(int nod...
aoj_2713_cpp
H - Bit Operation Game N 頂点の根付き木が与えられる。 頂点には 0 から N − 1 の番号がついており、 0 番目の頂点が根を表す。 根には T = 0 が、それ以外の頂点には T=T&X T=T&Y T=T|X T=T|Y T=T^X T=T^Y のいずれかの操作が書かれている。 ここでの演算子 &, |, ^ はそれぞれビット演算子 and, or, xor, を意味する。 A君とB君はこの木を使って以下のゲームを M 回行った。 二人は根からスタートし、子頂点を選び進むという操作を、A君から始め葉に到達するまで交互に行う。 通ったノードに書かれている操作を、通った順に適用した時の、最終的な T の値...
[ { "submission_id": "aoj_2713_10853981", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nmap<vector<int>, int> memo;\nvector<int> op;\n\nusing graph = vector<vector<int>>;\n\nint proc(int state, int op) {\n if(state == 0) {\n if(op == 0 || op == 1) {\n return 0;\n ...
aoj_2711_cpp
ほぼ周期文字列 文字列 S が与えられる。この文字列 S に対し、 Q 個のクエリに答えよ。 i 番目のクエリでは、 S[l_i,\ r_i] から1文字まで変えてよいとき、 S[l_i,\ r_i] を周期 t_i の文字列にできるかどうかを判定せよ。 S[l,\ r] は文字列 S の l 文字目から r 文字目までの部分文字列を表す。 文字列 W が周期 t の文字列であるとは、 i\ =\ 1,\2,\... ,\ |W| − t に対し、 W_{i} = W_{i+t} となることとする。 Constraints 1 ≤ |S| ≤ 10^5 1 ≤ Q ≤ 10^5 1 ≤ l_i ≤ r_i ...
[ { "submission_id": "aoj_2711_9799895", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)...
aoj_2716_cpp
Leapfrog Problem Statement N 個のマスが円状に並んでいる。マスは時計回りに 1,\ 2,\ ... ,\ N と番号が振られている。各 i ( 1 ≤ i ≤ N−1 ) について、 i 番目のマスと i+1 番目のマスは隣り合う。また、 N 番目のマスと 1 番目のマスは隣り合う。 これらのうち M 個のマスには、互いに区別できない駒が 1 個ずつ置かれている。はじめ、 x_1,\ x_2,\ ... ,\ x_M 番目のマスに駒が置かれている。次の操作を何回か行い、 y_1,\ y_2,\ ... ,\ y_M 番目のマスに駒が置かれているようにしたい。 時計回りまたは反時計回りに連続する 3 個...
[ { "submission_id": "aoj_2716_10853361", "code_snippet": "#include <string>\n#include <vector>\n#include<iostream>\n#include<cstdio>\n#include<cstdlib>\n#include<stack>\n#include<queue>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<list>\n#include<deque>\n#include<bitset>\n#include<se...
aoj_2717_cpp
Problem A: Where is the Boundary An island country JAGAN in a certain planet is very long and narrow, and extends east and west. This long country is said to consist of two major cultural areas | the eastern and the western. Regions in the east tend to have the eastern cultural features and regions in the west tend to ...
[ { "submission_id": "aoj_2717_10518617", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <cassert>\n#include <vector>\n#include <algorithm>\n#include <utility>\n#include <numeric>\n#include <tuple>\n#include <ranges>\nnamespace ranges = std::ranges;\nnamespace views = std::views;\n// #incl...
aoj_2718_cpp
Problem B: Vector Field In 20015, JAG (Jagan Acceleration Group) has succeeded in inventing a new accelerator named Force Point for an experiment of proton collision on the two-dimensional $xy$-plane. If a proton touches a Force Point, it is accelerated to twice its speed and its movement direction is veered. A proton ...
[ { "submission_id": "aoj_2718_10856665", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_2720_cpp
Problem D: Identity Function You are given an integer $N$, which is greater than 1. Consider the following functions: $f(a) = a^N$ mod $N$ $F_1(a) = f(a)$ $F_{k+1}(a) = F_k(f(a))$ $(k = 1,2,3,...)$ Note that we use mod to represent the integer modulo operation. For a non-negative integer $x$ and a positive integer $y...
[ { "submission_id": "aoj_2720_10946047", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_2721_cpp
Problem E: Enclose Points There are $N$ points and $M$ segments on the $xy$-plane. Each segment connects two of these points and they don't intersect each other except at the endpoints. You are also given $Q$ points as queries. Your task is to determine for each query point whether you can make a polygon that encloses ...
[ { "submission_id": "aoj_2721_11060906", "code_snippet": "#ifdef NACHIA\n#define _GLIBCXX_DEBUG\n#else\n#define NDEBUG\n#endif\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <set>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(...
aoj_2729_cpp
Delete Files You are using an operating system named "Jaguntu". Jaguntu provides "Filer", a file manager with a graphical user interface. When you open a folder with Filer, the name list of files in the folder is displayed on a Filer window. Each filename is displayed within a rectangular region, and this region is cal...
[ { "submission_id": "aoj_2729_4293550", "code_snippet": "#include <iostream>\n#include <vector>\n\ntemplate <class T>\nstd::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }\n\nconstexpr int INF = 1 << 30;\n\nvoid solve() {\n int n;\n std::cin >> n;\n\n std::vector<bool> erase(n);...
aoj_2725_cpp
Problem I: Live Programming A famous Japanese idol group, JAG48, is planning the program for its next live performance. They have $N$ different songs, $song_1$, $song_2$, ..., and $song_N$. Each song has three integer param- eters, $t_i$, $p_i$, and $f_i$: $t_i$ denotes the length of $song_i$, $p_i$ denotes the basic s...
[ { "submission_id": "aoj_2725_8170564", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define overload2(a, b, c, ...) c\n#define overload3(a, b, c, d, ...) d\n#define overload4(a, b, c, d, e ...) e\n#define overload5(a, b, c, d, e, f ...) f\n#define overload6(a, b, c, d, e, f, g ...) g\n#d...
aoj_2726_cpp
Problem J: Black Company JAG Company is a sweatshop (sweatshop is called "burakku kigyo" in Japanese), and you are the CEO for the company. You are planning to determine $N$ employees' salary as low as possible (employees are numbered from 1 to $N$). Each employee's salary amount must be a positive integer greater than...
[ { "submission_id": "aoj_2726_10849700", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_2728_cpp
Change a Password Password authentication is used in a lot of facilities. The office of JAG also uses password authentication. A password is required to enter their office. A password is a string of $N$ digits '0'-'9'. This password is changed on a regular basis. Taro, a staff of the security division of JAG, decided t...
[ { "submission_id": "aoj_2728_11021300", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<ll, 2>;\nusing a3 = array<ll, 3>;\n\nbool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }\nbool chmax(auto& a, const auto& b) { return a < b ? a = b...
aoj_2722_cpp
Problem F: Marching Course Since members of Kitafuji High School Brass Band Club succeeded in convincing their stern coach of their playing skills, they will be able to participate in Moon Light Festival as a marching band. This festival is a prelude in terms of appealing their presence for the coming domestic contest....
[ { "submission_id": "aoj_2722_10853940", "code_snippet": "#include<bits/stdc++.h>\n\n#define clr(x,y) memset((x),(y),sizeof(x))\n\nusing namespace std;\ntypedef long long LL;\n\nconst int INF = 1000000000;\nconst int maxn = 200 + 10;\n\nstruct Edge {\n int to,dist,v;\n};\n\n\nvector <Edge> G[maxn+5];\ndoubl...
aoj_2730_cpp
Line Gimmick You are in front of a linear gimmick of a game. It consists of $N$ panels in a row, and each of them displays a right or a left arrow. You can step in this gimmick from any panel. Once you get on a panel, you are forced to move following the direction of the arrow shown on the panel and the panel will be r...
[ { "submission_id": "aoj_2730_10295503", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)\n#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)\n#define ...
aoj_2724_cpp
Problem H: Laser Cutter Ciel is going to do woodworking. Ciel wants to make a cut in a wooden board using a laser cutter. To make it simple, we assume that the board is a two-dimensional plane. There are several segments on the board along which Ciel wants to cut the board. Each segment has a direction and Ciel must cu...
[ { "submission_id": "aoj_2724_10850438", "code_snippet": "#include<cstdio>\n#include<cstdlib>\n#include<algorithm>\n#include<cstring>\n#include<cmath>\n#define cl(x) memset(x,0,sizeof(x))\n#define read(x) scanf(\"%d\",&(x));\nusing namespace std;\n\ninline double sqr(int x){ return x*x; }\n\nconst int N=305;...
aoj_2731_cpp
Shifting a Matrix You are given $N \times N$ matrix $A$ initialized with $A_{i,j} = (i - 1)N + j$, where $A_{i,j}$ is the entry of the $i$-th row and the $j$-th column of $A$. Note that $i$ and $j$ are 1-based. You are also given an operation sequence which consists of the four types of shift operations: left, right, u...
[ { "submission_id": "aoj_2731_10867660", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair<ll, ll> P;\n\n#define each(i,a) for (auto&& i : a)\n#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)\n#define RFOR(i,a,b) for (ll i=(b)-1,__last_#...
aoj_2735_cpp
Shortest Bridge There is a city whose shape is a 1,000 $\times$ 1,000 square. The city has a big river, which flows from the north to the south and separates the city into just two parts: the west and the east. Recently, the city mayor has decided to build a highway from a point $s$ on the west part to a point $t$ on t...
[ { "submission_id": "aoj_2735_10323059", "code_snippet": "// AOJ #2735 Shortest Bridge\n// 2025.3.25\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ld = long double;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tdo n = 10*n + (c & 0xf), c = gc(); while (c >= '0');...
aoj_2734_cpp
Donut Decoration Donut maker's morning is early. Mr. D, who is also called Mr. Donuts, is an awesome donut maker. Also today, he goes to his kitchen and prepares to make donuts before sunrise. In a twinkling, Mr. D finishes frying $N$ donuts with a practiced hand. But these donuts as they are must not be displayed in a...
[ { "submission_id": "aoj_2734_10851292", "code_snippet": "#include<vector>\n#include<cstdio>\n#include<cstdlib> \n#include<cstring>\n#include<algorithm>\nusing namespace std;\n#define M 800010\n#define rep(i,x,y) for(int i=(x);i<=(y);i++)\n#define For(i,x,y) for(int i=(x);i<(y);i++)\ninline int read(){\n\tch...
aoj_2732_cpp
Modern Announce Network Today, modern teenagers use SNS to communicate with each other. In a high school, $N$ students are using an SNS called ICPC (International Community for Programming Contest). Some pairs of these $N$ students are 'friends' on this SNS, and can send messages to each other. Among these $N$ students...
[ { "submission_id": "aoj_2732_10866710", "code_snippet": "#include <queue>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <iostream>\n#include <algorithm>\ntypedef long long ll;\n#define rep(i, a, b) for (int i = a; i <= b; ++ i)\nconst int maxn = 10005, maxm = 2000005, inf = 1000000007...
aoj_2736_cpp
Longest Shortest Path You are given a directed graph and two nodes $s$ and $t$. The given graph may contain multiple edges between the same node pair but not self loops. Each edge $e$ has its initial length $d_e$ and the cost $c_e$. You can extend an edge by paying a cost. Formally, it costs $x \cdot c_e$ to change the...
[ { "submission_id": "aoj_2736_10854093", "code_snippet": "#include <stdio.h>\n#include <algorithm>\n#include <vector>\n#include <queue>\nusing namespace std;\n\nconst int non = 10000000;\n\nstruct edge {\n\tint x, y, f, c, r;\n};\nvector<edge> E[202];\n\nvoid add(int x, int y, int f, int c) {\n\tint p = E[x]...
aoj_2740_cpp
C - みさわさんの根付き木 Problem Statement あなたは親友であるみさわさんの誕生日が近いことに気づき,根付きの二分木をプレゼントすることにした. ここで,根付きの二分木とは,以下のようなグラフ構造である.(図 1) 各頂点には,その頂点の親と呼ばれる頂点がちょうど 1 つだけ存在し,親と辺で結ばれている.ただし,根と呼ばれる 1 つの頂点のみ,例外的に親を持たない. 各頂点は,左の子と呼ばれる頂点をちょうど1つ持つか,あるいは持たない.左の子を持つ場合,左の子とは辺で結ばれており,左の子の親はその頂点である. 各頂点は,右の子と呼ばれる頂点をちょうど1つ持つか,あるいは持たない.右の子を持つ場合,右の子とは辺で結...
[ { "submission_id": "aoj_2740_3532990", "code_snippet": "#include <string>\n#include <iostream>\n#include <vector>\n\nusing namespace std;\n#define vec vector<int>\n\nconst int SIZE=10000000;\n\nvec Aar(SIZE,-1);\nvec Bar(SIZE,-1);\nvec Xar(SIZE,-1);\n\n\nvoid input(vec & ar,const string & str,int & i,int k)...
aoj_2733_cpp
Cube Dividing Pablo Cubarson is a well-known cubism artist. He is producing a new piece of work using a cuboid which consists of $A \times B \times C$ unit cubes. He plans to make a beautiful shape by removing $N$ units cubes from the cuboid. When he is about to begin the work, he has noticed that by the removal the cu...
[ { "submission_id": "aoj_2733_10319512", "code_snippet": "// AOJ #2733 Cube Dividing\n// 2025.3.23\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() { // 整数の入力\n\tint n = 0; int c = gc();\n\tif (c == '-...
aoj_2741_cpp
D - インビジブル Problem Statement あなたは友達と" インビジブル "というカードゲームを遊ぼうとしている. このカードゲームでは," 得点カード "と" 妨害カード "という2種類のカードを使う. それぞれの得点カードには,正の値が書かれている.このカードゲームのルールは次の通りである. ゲームはプレイヤー1とプレイヤー2の2人のプレイヤーで行われる.ゲームはプレイヤー1のターンから始まる. 場には,1つのスタックと2つのデッキがある.スタックは,2人のプレイヤーが置いたカードからなる.また,それぞれのプレイヤーが持つデッキはそのプレイヤーが持つ得点カードと妨害カードからなる.プレイヤーは自分,もしくは相手デ...
[ { "submission_id": "aoj_2741_10946046", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_2737_cpp
Optimal Tournament In 21XX, an annual programming contest "Japan Algorithmist GrandPrix (JAG)" has been one of the most popular mind sport events. You, the chairperson of JAG, are preparing this year's JAG competition. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tourname...
[ { "submission_id": "aoj_2737_10867807", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXN = 1005;\nconst int INF = 1e9;\nint n, K;\nint s[MAXN];\nint f[MAXN][MAXN][55], g[MAXN][MAXN][55];\n\nint main() {\n scanf(\"%d %d\", &n, &K);\n for (int i = 1; i <= n; i++)\n ...
aoj_2742_cpp
E - 選挙活動 Problem Statement あなたは次回の選挙の候補者であるX氏の支援者である. X氏は駅前での街頭演説を予定しており,できるだけ多くの有権者に見てもらえる場所で演説しようと考えている. 駅前は $N$ 個の障害物と $M$ 人の有権者が存在している二次元平面として与えられる. 各障害物は多角形であらわされ,その多角形の内側の領域が障害物となる.多角形の辺上は障害物に含まれない. また,有権者は平面上の点としてあらわされる. ある有権者の位置とX氏の位置を結ぶ線分上に障害物が存在しないとき,その有権者はX氏を見ることができる. あなたの仕事は,駅前の障害物と有権者の情報をもとに,もっとも多くの有権者に見ても...
[ { "submission_id": "aoj_2742_10851262", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_2750_cpp
百人一首 百人一首は日本の伝統的なゲームである. このゲームでは N 枚のカードが用いられ,それぞれのカードには1つの文字列が書かれている.細かいルールは省略するが, A君は N 枚のカードに書かれている文字列を何らかの順序でそれぞれちょうど1回ずつ読むことになった. 百人一首ではその接頭辞が非常に重要である.百人一首で使用される文字列として接頭辞は似ている言葉が多く, 連続して似たような文字列を読むとA君も混乱してしまう. そこでA君は,連続する二つのカードの文字列の接頭辞ができるだけ異なるように,カードを並べ替えようと考えた. A君の目標は,「山札の読みやすさ」と呼ばれる指標を最小化するような山札を求めることである.ここで山札と...
[ { "submission_id": "aoj_2750_7136839", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nint main(){\n int n;\n while(cin >> n && n!=0){\n vector<string> s(n);\n for(int i=0;i<n;i++)cin >> s[i];\n sort(s.begin(),s.end());\n vector<int> lcp(n-1);\n for(i...
aoj_2743_cpp
F - 土地相続 Problem Statement ある $N$ 人の兄弟は親の遺産相続の話し合いをしていた. 彼らの親の残した莫大な遺産の中には広大な土地も含まれていた. その土地は南北に $H$ km, 東西に $W$ km に広がる長方形の形をしている. この土地は 1 km 四方の区画単位で管理されており, 土地の北端から $i$ 〜 $i+1$ km かつ西端から $j$ 〜 $j+1$ km の範囲にある 1 km 四方の区画を区画 $(i, j)$ と呼ぶ. ($i$, $j$ は $0 \leq i < H$, $0 \leq j < W$ を満たす整数である.) 土地の価格は区画ごとに決まっており,区画 $(i,...
[ { "submission_id": "aoj_2743_10493832", "code_snippet": "// AOJ 2743 Land Inheritance\n// 2025.5.16\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() {\n\tint n = 0; int...
aoj_2744_cpp
G - リングと紐 Problem Statement 芸術家のみさわさんは新しい作品を作ろうとしている. 新しい作品の材料として,みさわさんは金属の輪と白黒2色の紐を大量に用意した. みさわさんは,異なる 2 つの輪をいずれかの色の紐で結ぶことを繰り返すことによって作品を作ることが出来る. 1 つの輪を複数の輪と繋ぐことも可能であるが,それぞれの輪のペアを結ぶ紐は高々 1 本である. みさわさんは,せっかく作品を作るからにはよい作品を作りたいと考えた. みさわさんの考える「よい作品」とは,以下のように定義されるものである. 1 つの輪は 1 つのよい作品である. 2 つのよい作品を用意したとき,それらに含まれている紐で繋がれていな...
[ { "submission_id": "aoj_2744_9731980", "code_snippet": "#line 1 \"library/Template/template.hpp\"\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(),...
aoj_2757_cpp
F : 卵 / Eggs 問題文 1 か月前のことである. 小学生の肉西君は夏休みの宿題をやっていなかった. そこで自由研究は家にあった卵の強度を調べることにした. この研究において,卵を高さ H から落としても割れず, 高さ H+1 から落とすと割れるとき, その卵の強度は H であると定義する. ここで H は非負整数であり,非負整数以外の高さから落とすことは無いとする. 肉西くんは卵を 1 つ落下させる実験を行う. 実験の結果は割れるか割れないかのいずれかである. また,卵の強度は全て同じである.つまり,どの卵を用いても実験の結果は同じである. 肉西くんは高さ 1 から N までの整数の高さの段からなる階段と, 強度が不明な ...
[ { "submission_id": "aoj_2757_3355114", "code_snippet": "#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nlong long Q, dp[60][200009], A[2000009];\n\nvoid init() {\n\tfor (int i = 1; i <= 2000000; i++) {\n\t\tlong long V1 = A[i - 1] + 1;\n\t\tlong long V2 = 1LL * i * (i - 1) / 2LL + 1;\n\t\...
aoj_2748_cpp
夏合宿の朝は早い JAG夏合宿の朝は早い. 正確にはそこまで早くないが,早いと感じる参加者が多いという. 例年合宿の会場となる施設では,退去時に参加者がシーツの回収や掃除をしなければならない. 1 つの部屋でも退去が遅れると,来年以降の施設の利用に関わるため,参加者は一人たりとも寝坊してはならない. そうは言っても皆人間,寝坊することもある. しかし,起きた人が連絡先を知っている人にモーニングコールをすることで,一人も寝坊しないよう努めることができるはずだ. JAG夏合宿の運営を任されたあなたは,寝坊を絶対に防ぐ手を打つための前準備として,どのくらいの確率で全員がきちんと起きられるのかを調べることにした. 準備としてまず,各参加者の...
[ { "submission_id": "aoj_2748_10648019", "code_snippet": "#pragma GCC target(\"avx2\")\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\n\n// #ifndef ONLINE_JUDGE\n// #define _GLIBCXX_DEBUG // 配列外参照のエラー\n// #endif\n\n// スタンダードライブラリ\n#include <bits/stdc++.h>\nusing namespace std;\n\n// 型関...
aoj_2747_cpp
カーテン もうすぐ夏がやってくる.あなたは夏に向けて部屋の模様替えをすることにした.今年の夏はとても日差しが強いことが予想されており,まぶしいのが苦手なあなたには辛い季節になりそうだ.そこで,あなたは部屋の明るさを調節するために,部屋の窓にカーテンを取り付けようと考えた. 取り付けるカーテンは長方形であり,辺が地面に対して垂直,もしくは平行であるように取り付ける.また,あなたの部屋の窓は非常に特殊な形をしており,各辺が地面に平行または垂直であるような N 角形で表される.そのため,カーテンを取り付けたときにカーテンに覆われていない窓の面積がどのくらいになるのかを求めるのは難しい.部屋の明るさを調節するためにも,カーテンを取り付ける位...
[ { "submission_id": "aoj_2747_10683663", "code_snippet": "#include <bits/stdc++.h>\n#include <unordered_map>\n#include <stdlib.h>\nusing namespace std;\n#define rep(i, a, n) for(ll i = a; i < n; i++)\n#define rrep(i, a, n) for(ll i = a; i >= n; i--)\n#define ll long long\n#define pii pair<int, int>\n#define ...
aoj_2749_cpp
ぼくのかんがえたさいきょうのおふとん あなたは新生活に備え,おふとんを N 枚買った. i 番目のおふとんは s i のぬくもり供給力をもつ. これから M 日間の気温の予測から, j 日目には d j のぬくもり需要が予想される. ぬくもりが足りなくても多すぎても快適さが損なわれるので, j 日目に掛けているおふとんのぬくもり供給力の総和と d j の差の絶対値を j 日目の不快度と呼ぶことにする. この M 日分の不快度の合計ができるだけ少なくなるようにしたい. ところで,あなたの部屋は残念ながらとても狭く,ベッドと押入れしかない. そのため,ベッドにおふとんを 1 枚増やすには,そのとき押入れの一番上にあるおふとんをベッドの一...
[ { "submission_id": "aoj_2749_10848993", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_2751_cpp
野球観戦 先日,あなたの競技プログラミング仲間であるOさんは野球観戦に出かけた. 観戦した試合は,チームXとチームYの合計 4 試合の対戦だったが,一方的な展開となり,全試合でチームXが勝利した. しかも,4 試合を通じたXの合計得点は 33 点だったのに対し,Yの合計得点はたったの 4 点だった. あまりに一方的な内容のため,試合内容への興味が薄れてしまったOさんは,試合を観戦している間も競技プログラミングの作問ネタをついつい考えてしまっていた. その甲斐もあって,Oさんは以下のような問題を思いついた. 野球チームXとYが対戦し,Xが勝った試合数,Yが勝った試合数,引き分けの試合数がそれぞれ A, B, C 試合だったとする. ま...
[ { "submission_id": "aoj_2751_10855496", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\n\nll mod = 1000000007;\n\nll kai[3000010];\nll inv_kai[3000010];\n\nll beki(ll x, ll a)\n{\n\tif(x==0) return 0;\n\tif(a==0) return 1;\n\tif(a==1) return x;\n\tll tmp=beki(x, a/2...
aoj_2754_cpp
C : 壺 / Pots 問題文 ここに N 個の不思議な形の壺がある. i 番目の壺は K_i 個の直円柱を下から順に鉛直に繋げた形状である. 繋がっている順番は変えることができない. A 氏は体積 M の水を持っている. この水をそれぞれの壺に好きな量ずつに分けて注ぐ. 水が全く入っていない壺が存在しても構わない. また,全ての壺が水で満たされたとき,それ以上水を注ぐ事はできない.それぞれの壺の水面の高さの総和の最大値を求めよ. 入力 N \ M K_1 \ S_{11} \ H_{11} \ … \ S_{1 K_1} \ H_{1 K_1} K_2 \ S_{21} \ H_{21} \ … \ S_{2 K_2} \ H_...
[ { "submission_id": "aoj_2754_10850464", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define FOR(i,s,t )for(int i = s; i <t ; i++)\nusing LL = long long; using ll = LL;\nusing PLL = pair<LL, LL>; using pll = PLL;\nusing PII = pair<int, int>; using pii = PII;\n#define SZ(a) (int)a.size...
aoj_2761_cpp
D: みゃんぱすーれつ - Myampus Sequence - 物語 みゃんぱすー. ウチ,田舎の分校に通う小学一年生なん. あんなー,今日の授業はプログラミングだったん. みんな苦戦してたけど,まっつんのにぃにぃ,凄い勢いでタイピングしてたん. さすが中三なんなー. にぃにぃ,プログラムが完成してどこか行ってしまったん. そんで,画面見たら,色んな数列が出力されてたん. だんだん出力と同じような数列を書きたくなったん,ウチ,出力テキストに同じような数列をいくつも書き加えてたん. そしたら,にぃにぃが戻ってきて,すごい怒られたん. ウチ,にぃにぃの声初めて聞いたから,びっくりしたん. でな,にぃにぃに謝ってプログラムを見せてもらっ...
[ { "submission_id": "aoj_2761_3000665", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint N, M;\nint x[110], a[15], b[15], c[15];\nint dp[15][110][110];\n\nint solve(int idx, int l, int r) {\n assert(r - l > 0);\n\n int val = dp[idx][l][r];\n if(val >= 0) return val;\n\n val = 0;\n ...
aoj_2756_cpp
E : 台風 / Typhoon 問題文 南北方向に H ,東西方向に W の大きさの町がある. 町には一辺の長さが 1 の正方形の区画に隙間なく整備されており,全ての区画に 1 軒ずつ家が建っている. この町のある区画の上空で台風が発生し,被害を与えた後,ある区画の上空で温帯低気圧に変化した. 変化した後は被害を与えない. 下図のように,台風は高さ 3 , 幅 3 の正方形であり, ★のついたマスを中心と呼ぶことにする.台風は 8 近傍に区画単位で移動する. つまり,台風の中心は辺または頂点を共有する区画(現在の区画を含む)に移るように,全体を伴って移動する. ただし,町の外に台風がはみ出ることはなく, 台風の中心は,下の図の網...
[ { "submission_id": "aoj_2756_10853236", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define FOR(i,s,t )for(int i = s; i <t ; i++)\nusing LL = long long; using ll = LL;\nusing PLL = pair<LL, LL>; using pll = PLL;\nusing PII = pair<int, int>; using pii = PII;\n#define SZ(a) (int)a.size...
aoj_2765_cpp
A: 秤 / Steelyard 問題文 情太くんは長さ $2L$ の棒を使って下の図のような秤を作った. 棒には等間隔に $2L+1$ 個の穴があけられ,左から順に $-L, -L+1, \cdots, -1, 0, 1, \cdots, L-1, L$ という番号が付けられている.そして $0$ 番の穴の場所を天井から紐で吊るしてある. 情太くんは,秤の穴に $N$ 個のおもりを吊るした.$i$ 番目のおもりを吊るした穴の番号は $x_i$ で,おもりの重さは $w_i$ である.おもりが $1$ つも吊るされない穴や,複数のおもりが吊るされる穴も存在しうる. 情太くんが吊るしたおもりによっては,秤が傾いているかもしれない.姉の...
[ { "submission_id": "aoj_2765_4968352", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\n\n\nint main(void){\n long long L,N;\n long long weight=0;\n\n cin >> L >> N;\n for(int i=0;i<N;i++){\n long long x,w;\n cin >> x >> w;\n weight += x*w;\n ...
aoj_2760_cpp
C: 買い出し - Shopping - 物語 磯野の姉であるサゾエさんは,『あれ』や『あれ』で遊んでいる磯野と中島のために夕食を作ってあげることにしました.あいにく,冷蔵庫には食材が残り僅かしか無く,サゾエさんは買い出しに行くことにしました.幾つか食材を買おうとしているサゾエさんですが,大変陽気であるため一度に一品のみレジで会計してしまいます.このままでは遊んでいた磯野と中島が買い物を終える前に帰ってきてしまい,夕食を準備することが出来ないかもしれません.そこで,サゾエさんの友人であるあなたは,サゾエさんのためにサゾエさんの買い物にかかる最小の時間を求めてください. 問題 とあるスーパーに N 個のレジがあり,それぞれ 1 〜 N...
[ { "submission_id": "aoj_2760_10401979", "code_snippet": "// AOJ #2760 Shopping\n// 2025.4.21\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0, c = gc();\n\tdo n = 10*n + (c & 0xf), c = gc(); while (c >= '0');\n\treturn n;...
aoj_2771_cpp
G: 塗るだけ / Paint 問題文 情太くんと立子さんは, 平面の世界にある庭付きの家に住んでいる.二人は点とみなせ, 庭は $N$ 頂点の単純多角形 (隣り合わないどの $2$ 辺も交差も接触もしない多角形) の形をしている. ある日,二人は一本の伸び縮みするローラーを手に入れた. ローラーは線分とみなせ,ローラーが通過した領域に色を塗ることができる. 二人はローラーを使って庭全体に色を塗りたいと思っている. 作業の前に,二人は以下のような準備を上から順に行う. 庭の内部の任意の $1$ 箇所に杭を打つ. 庭の外部のある $1$ 点に集まる. 十分に長い紐を用意し,片方の端を情太くん,もう一方の端を立子さんの体に結ぶ. 情太く...
[ { "submission_id": "aoj_2771_4964531", "code_snippet": "#include <cmath>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n\n#include <algorithm>\n#include <bitset>\n#include <complex>\n#include <iostream>\n#include <map>\n#include <numeric>\n#include <queue>\n#include <set>\n#include <stack>\n#in...
aoj_2764_cpp
G: 旅費支給 - Travel Support - 物語 私,香坂穂乃果16歳!学生アイドルをやっています!! 学生アイドルの良さをみんなに伝えるためのライブをやろうと,たくさんの学生アイドルの人たちを呼んでアキバスタジアムでライブをします. だけど,遠くから来るライブ参加者もいてとっても電車賃がかかるの.だからu’sのメンバーでバイトをして,ライブ参加者たちに電車賃を渡すことにしたんだ!ただ,バイト代が入るのが遅いから電車賃を渡すのがライブ参加者の出発に間に合わないことがあったり,バイト代が足りなくて電車賃の全額は渡せないことがあるんだ.そんな時は,ライブ参加者に足りない分のお金を事前に用意してもらうのだけど,どのくらい用意して...
[ { "submission_id": "aoj_2764_10593094", "code_snippet": "#include <iostream>\n#include <vector>\n#include <queue>\n#include <algorithm>\n#include <climits>\n\nusing namespace std;\n\nconst int MAX_N = 100000;\nconst int MAX_D = 20;\ntypedef long long ll;\nconst ll INF = 1LL << 60;\n\nstruct Edge {\n int ...
aoj_2763_cpp
F: みこみー文字列 - Miko Mi String - 物語 みっこみっこみ〜!みんなのアイドル,田澤みこみこ!今日は〜,みこと一緒に〜,文字列アルゴリズムの練習,しよ☆ みこのとっておきの キャラ作り 合言葉,「みっこみっこみ〜」は,ローマ字にすると “MikoMikoMi” になるみこ!つまり, A= “Mi”, B= “Ko” とすると, ABABA の形で書けるってことなの!こんな風に,適切に A と B を決めると ABABA の形に分解できる文字列のことを「みこみー文字列」って言うわ!文字列の名前にまでなっちゃうなんて,みこはみんなの人気者みこね! みんなでみこみー文字列をも〜っと使っていくために,与えられた文字列が...
[ { "submission_id": "aoj_2763_8469801", "code_snippet": "/* -*- coding: utf-8 -*-\n *\n * 2763.cc: Miko Mi String\n */\n\n#include<cstdio>\n#include<algorithm>\n \nusing namespace std;\n\n/* constant */\n\nconst int MAX_N = 1000000;\nconst int P = 4073;\nconst int MOD = 1000000009;\n\n/* typedef */\n\ntempla...
aoj_2770_cpp
F: リレー / Relay 問題文 湖に浮かぶ $N$ 個の小島からなるビワコという村がある. ビワコ村には $N-1$ 本の簡単な作りの橋がある. 島には $0$ から $N-1$ まで,橋には $0$ から $N-2$ までの番号が付けられている. $i$ 番の橋は $i+1$ 番の島と $p_i$ 番の島を直接つなぎ,長さは $w_i$ である. 村人はどの島の間もいくつかの橋を通って相互に移動できるようになっている. ある村人の提案により,ビワコ村でリレー大会が開催されることとなった. しかし,ビワコ村には閉路がなくトラックを用意できないため, 現在ある橋を $1$ つだけ掛け替えることによって閉路を作ろうと考えた. この...
[ { "submission_id": "aoj_2770_10401948", "code_snippet": "// AOJ #2770 Relay\n// 2025.4.21\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0, c = gc();\n\tif (c == '-') {\tc = gc();\n\t\tdo n = 10*n + (c & 0xf), c = gc(); w...
aoj_2768_cpp
D: スキャナー / Scanner 問題文 ここに $N$ 枚の紙がある。あなたは $3$ 台のスキャナーを並列に用いることで、 全ての紙をスキャンしたいと考えている。それぞれの紙はスキャンにかかる時間が決まっており、 $i$ 番目の紙をスキャンするのにかかる時間は $T_i$ である。 紙をスキャンする順番は任意であるが、$1$ 台のスキャナーで複数の紙を同時にスキャンすることはできない。 全ての紙のスキャンが終了し、スキャンを行っているスキャナーがなくなるまでにかかる時間を最小化しなさい。 入力 $N$ $T_1$ $T_2$ $T_3$ $\vdots$ $T_N$ 制約 $1 \leq N \leq 50$ $1 \leq...
[ { "submission_id": "aoj_2768_10851361", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define FOR(i,s,t) for(int i = s; i< t ;i++)\n\n#define SZ(x) (int)x.size()\nusing LL = long long; using ll = LL;\nconst int INF = 1e9; const LL LINF = 1e18;\n\n#define MAXT 1005\nll N;\nvector<int> T;\nb...
aoj_2769_cpp
E: 28 問題文 トランプゲームの大富豪において,ランクが $2$, $8$ のカードは強力です. そこで,$10$ 進数表記で数字の $2$, $8$ のみからなる整数を 良い整数 と呼ぶことにします. 良い整数を小さいものから列挙すると $2, 8, 22, 28, 82, 88, \cdots$ となります. $n$ を正の整数とします.$n$ が良い整数の積の形で表現できるとき, 最大でいくつの積になるか求めてください.できないなら $-1$ と出力してください. 入力 $n$ 制約 $1 \leq n \leq 10^{18}$ 出力 答えを $1$ 行で出力してください. サンプル サンプル入力1 1 サンプル出力1 ...
[ { "submission_id": "aoj_2769_5972328", "code_snippet": "#include<bits/stdc++.h>\n#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)\n#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);-...
aoj_2773_cpp
B: 周期数列 - Periodic Sequence - 問題 H大学の教授を務めているPeriod博士は、万物に潜むとされる周期と呼ばれる性質を研究している。一般的に知られている基本的な周期としては、数列に潜む周期が考えられるだろう。すなわち、長さ N の数列 S = S_1, S_2, ... , S_N が以下の性質を満たすならば、周期 t ( t \≤ N ) を持つという事実である。 1 \≤ i \≤ N − t について、 S_i=S_{i+t} である。 今、Period博士が着目しているのは、周期を用いてより簡易な記述ができる数列である。例えば、長さ N の数列が周期 t ( \≤ N ) を持つとき、ある整数 ...
[ { "submission_id": "aoj_2773_10865813", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing LL = long long; using ll = LL;\nusing PII = pair<int, int>; using pii = PII;\nusing PLL = pair<LL, LL>; using pll = PLL;\nusing VI = vector<int>; using VL = vector<LL>;\nconst ll LINF = 1e18;\ncon...
aoj_2774_cpp
C: 成長する点 - Growing Point - 問題 粘菌コンピュータというものがある。 ある種の粘菌には「餌を求め、餌と餌の最短距離をつなぐ形に変形する」 という性質がある。 これを利用し、餌を「入力」、形を「出力」とみなして コンピュータとして利用することができる。 今、二次元平面上に1つの粘菌の拠点と N 個の餌が存在する。それぞれの餌には 1 から N までの異なる番号が与えられ、拠点には番号0が与えられている。 この粘菌はある餌を食べるために、その餌と最も近い拠点の最短距離を結ぶ管状に 成長し、食べた位置に新たに拠点を形成する。 新たに形成した拠点は拠点を形成する直前に食べた餌と同じ番号を持つ。 粘菌は拠点以外の場所...
[ { "submission_id": "aoj_2774_10858226", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing LL = long long; using ll = LL;\nusing PII = pair<int, int>; using pii = PII;\nusing PLL = pair<LL, LL>; using pll = PLL;\nusing VI = vector<int>; using VL = vector<LL>;\nconst ll LINF = 1e18;\ncon...
aoj_2775_cpp
D: Complex Oracle - Complex Oracle - 問題 ※この問題はリアクティブ問題です.すなわち,サーバー側に用意されたプログラムと対話的に応答することで正答を導くプログラムを作成する必要があります. また、サーバー側のプログラムも計算機資源を共有する関係上、サーバーだけで最大 3 sec程度の実行時間、最大 300 MB程度のメモリを使用する場合がありますので、TLE・MLEにお気をつけください。 あいずにゃんは若ヶ松高校のプログラミングコンテスト部、通称ぷろこん部に所属する2年生である。見目麗しい。あいずにゃんはその小さな体も無限に存在するチャームポイントの1つであるが、本人はコンプレックスを感じている...
[ { "submission_id": "aoj_2775_10850453", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing LL = long long; using ll = LL;\nusing PII = pair<int, int>; using pii = PII;\nusing PLL = pair<LL, LL>; using pll = PLL;\nusing VI = vector<int>; using VL = vector<LL>;\n#define FOR(i,s,t) for(int...
aoj_2776_cpp
E: Arai's - Arai's - 問題 スクールアイドル時代から、国民的人気を誇ってきた女性アイドルグループArai's。今では、たくさんの「あらい」さんが所属する大規模なグループとして、世界レベルで活躍している。そして今日、新たなるプロジェクトの始動が決定した。彼女たちは、小さなユニットをいくつか結成することで、さらなる売上の向上を試みることになったのである。 Arai'sには「荒井」さんが A 人,「新井」さんが B 人在籍しており、合計で A+B 人の「あらい」さんからなる。新ユニットは、「荒井」さん一人と「新井」さん一人のペアで構成する。(ここで、同じ「あらい」さんが複数のユニットに所属していはいけない。)ただし、あ...
[ { "submission_id": "aoj_2776_10851385", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing LL = long long; using ll = LL;\nusing PII = pair<int, int>; using pii = PII;\nusing PLL = pair<LL, LL>; using pll = PLL;\nusing VI = vector<int>; using VL = vector<LL>;\nconst ll LINF = 1e18;\ncon...
aoj_2777_cpp
F: きっちり - Kitsuchiri - 問題 若ヶ松高校二年へ組の合津千里(あつちり)さんは数列が「きっちり」していなければ気がすまない。 合津さんによると、「きっちり」した数列とは、長さが偶数で左右対称である数列のことである。 すなわち、長さ N ( N は偶数)の数列 S について、次の条件を満たせば数列 S は「きっちり」している。 S_1 = S_N, S_2 = S_{N − 1}, ... , S_{N/2} = S_{N − N/2 + 1} 二年へ組の数学担当の先生は、合津さんから「きっちりしてください。」と要望され、授業で用いる数列を作り直さなければならない。 先生は、数列の l 番目から r 番目までのそれ...
[ { "submission_id": "aoj_2777_10850964", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing LL = long long; using ll = LL;\nusing PII = pair<int, int>; using pii = PII;\nusing PLL = pair<LL, LL>; using pll = PLL;\nusing VI = vector<int>; using VL = vector<LL>;\nconst ll LINF = 1e18;\ncon...
aoj_2779_cpp
H: われわれの努力について - About Our Effort - 問題 ※この問題はおまけの問題と捉えていただけるとありがたく、 できれば先に他の問題のほうをお楽しみいただければと思っておりまして,ですので他の問題を通し終えて暇になり,かつその暇を このコンテストで潰そうという気になってくれた方に挑戦していただければと思います。 D問題のクエリが遅くてすみませんでした。 しかし我々といたしましても決してただ怠慢をしていたわけではないのです。 私たちなりに努力したのです。 その努力の片鱗を味わっていただくため、このような問題を出題した次第であります。 問題: D問題のサーバー側の処理をするプログラムを作成せよ。 なおこの問題は本...
[ { "submission_id": "aoj_2779_4926964", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing ll = long long;\n\n#define SIZE 200000\n#define SQ 300\n#define LLINF 100000000000000\n\nstruct BIT {\n vector<int> data;\n\n BIT(int n): data(n + 2, 0) {};\n\n void add(int k, int x) {\n k+...
aoj_2778_cpp
G: 運命力 - Destiny Draw - 問題 Mr. D はカードゲームで勝負をすることになった。 このカードゲームでは、 N 枚のカードの山を用いる。 また、山のカードには、上から順に 1, 2, 3, ... , N の番号がついている。 D で始まるものすべてを背負う彼に敗北は許されないが、不幸にも Mr. D はカードゲームが不得手である。 そこで、自分が引くカードをコントロールすることで勝利を手にすることにした。 Mr. D は K 種類のシャッフルが可能である。 K 種類のうち i 番目のシャッフルでは上から a_i 枚目から a_i+b_i − 1 枚目までのちょうど b_i 枚を引き抜き、上に重ねる。 i 番...
[ { "submission_id": "aoj_2778_10259979", "code_snippet": "// AOJ #2778 Destiny Draw\n// 2025.3.2\n\n#include <bits/stdc++.h>\nusing namespace std;\nconst long long MOD = 1000000007;\n\nint main(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n int n, K, C, T;\n cin >> n >> K >> C >> T;\n vector<...
aoj_2780_cpp
Best Matched Pair You are working for a worldwide game company as an engineer in Tokyo. This company holds an annual event for all the staff members of the company every summer. This year's event will take place in Tokyo. You will participate in the event on the side of the organizing staff. And you have been assigned ...
[ { "submission_id": "aoj_2780_10295740", "code_snippet": "// AOJ #2780 Best Matched Pair\n// 2025.3.14\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() { // 整数の入力\n\tint n = 0; int c = gc();\n\tdo n = ...
aoj_2782_cpp
We don't wanna work! ACM is an organization of programming contests. The purpose of ACM does not matter to you. The only important thing is that workstyles of ACM members are polarized: each member is either a workhorse or an idle fellow. Each member of ACM has a motivation level. The members are ranked by their motiva...
[ { "submission_id": "aoj_2782_10851164", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define D(x) cout << #x \" = \" << (x) << endl\n#define un(x) x.erase(unique(x.begin(), x.end()), x.end())\n#define sf(n) scanf(\"%d\", &n)\n#define sff(a,b) scanf(\"%d %d\", &a, &b)...
aoj_2781_cpp
Help the Princess! The people of a certain kingdom make a revolution against the bad government of the princess. The revolutionary army invaded the royal palace in which the princess lives. The soldiers of the army are exploring the palace to catch the princess. Your job is writing a program to decide that the princess...
[ { "submission_id": "aoj_2781_10730387", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nint n, m;\nint x, y;\nchar str[210][210];\nchar tmp[210][210];\nint dirx[] = {1, -1, 0, 0};\nint diry[] = {0, 0, 1, -1};\nint val (int a, int b) {\n if (a<0 || b<0 || a>=n || b>=m) return 0;\n retu...
aoj_2783_cpp
Parentheses Dave loves strings consisting only of '(' and ')'. Especially, he is interested in balanced strings. Any balanced strings can be constructed using the following rules: A string "()" is balanced. Concatenation of two balanced strings are balanced. If $T$ is a balanced string, concatenation of '(', $T$, and '...
[ { "submission_id": "aoj_2783_4919488", "code_snippet": "#include <random>\n#include \"bits/stdc++.h\"\n//#include <atcoder/all>\n\nusing namespace std;\n// using namespace atcoder;\n\nusing ll = long long;\nusing ld = long double;\nusing P = pair<int, int>;\nconstexpr ld eps = 1e-12;\nconstexpr int inf = nu...
aoj_2784_cpp
Similarity of Subtrees Define the depth of a node in a rooted tree by applying the following rules recursively: The depth of a root node is 0. The depths of child nodes whose parents are with depth $d$ are $d + 1$. Let $S(T, d)$ be the number of nodes of $T$ with depth $d$. Two rooted trees $T$ and $T'$ are similar if ...
[ { "submission_id": "aoj_2784_10946041", "code_snippet": "#include <bits/stdtr1c++.h>\n\n#define MAX 100100\n#define clr(ar) memset(ar, 0, sizeof(ar))\n#define read() freopen(\"lol.txt\", \"r\", stdin)\n#define dbg(x) cout << #x << \" = \" << x << endl\n\nusing namespace std;\n\nconst unsigned long long base...
aoj_2786_cpp
Share the Ruins Preservation Two organizations International Community for Preservation of Constructions (ICPC) and Japanese Archaeologist Group (JAG) engage in ruins preservation. Recently, many ruins were found in a certain zone. The two organizations decided to share the preservation of the ruins by assigning some o...
[ { "submission_id": "aoj_2786_10850971", "code_snippet": "#include<bits/stdc++.h>\n\n#define PB push_back\n#define MP make_pair\n#define F first\n#define S second\n\n#define FRI freopen(\"zin.txt\",\"r\",stdin)\n#define FRO freopen(\"out.txt\",\"w\",stdout)\n#define DB(x) #x\" =>\",x\n#define debug(args...) ...
aoj_2785_cpp
Escape from the Hell One day, Buddha looked into the hell and found an office worker. He did evil, such as enforcing hard work on his subordinates. However, he made only one good in his life. He refused an unreasonable request from his customer to save the lives of his subordinates. Buddha thought that, as the reward o...
[ { "submission_id": "aoj_2785_10946038", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define si(a) scanf(\"%d\",&a)\n#define f first\n#define s second\n#define mp(a,b) make_pair(a,b)\n#define MAX 100005\n#define INF 1LL<<50\ntypedef pair <int, int> Pii;\n\nstruct Less {\n bool ope...
aoj_2787_cpp
Pipe Fitter and the Fierce Dogs You, a proud pipe fitter of ICPC (International Community for Pipe Connection), undertake a new task. The area in which you will take charge of piping work is a rectangular shape with $W$ blocks from west to east and $H$ blocks from north to south. We refer to the block at the $i$-th fro...
[ { "submission_id": "aoj_2787_10851470", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <string>\n#include <map>\n#include <set>\n#include <cassert>\nusing namespace std;\n#define rep(i,a,n) for (int i=a;i<n;i++)\n#define per(i,a,n)...
aoj_2796_cpp
F: 紙の折りたたみ / Folding Paper 問題文 高さ $H$ マス、幅 $W$ マスの格子状に区切られた長方形の紙がある。 $0$ から数えて上から $i$ 行目、左から $j$ 列目のマスには整数 $i \times W+j$ が書かれている。 $H=2, W=3$ の例を下の図に示す。 AOR イカちゃんは、この紙に対して次のような操作を順に行った。 $1$ マス分の面積になるまでマスの区切り線に沿って繰り返し折る。この時の折る線や山谷、順番などは任意である。紙を破らない任意の折り方ができる。 $4$ 辺を切り落として $H \times W$ 枚の紙に分割する。 上から順にめくっていき、書かれていた整数を並べた数...
[ { "submission_id": "aoj_2796_4958013", "code_snippet": "#include<iostream>\n#include<string>\n#include<cstdio>\n#include<vector>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<iomanip>\n#include<queue>\n#include<ciso646>\n#include<random>\n#include<map>\n#include<set>\n#include<bitset...
aoj_2792_cpp
B: イカったー / SNS 問題文 AOR イカちゃんは最近少し機嫌が悪い。 どうやら、”イカったー”のフォロー数とフォロワー数の比が気に入らないようだ 。現在、AOR イカちゃんのフォロー数は $A$ 人、フォロワー数は $B$ 人であり、比は $A:B$ である。 そこで、AOR イカちゃんはフォロー数とフォロワー数の比が気に入った整数比になるように、 フォロー数 を増減させることにした。 なお気に入った整数比とは、比に含まれるどちらの値も $1$ 以上 $N$ 以下の整数となるように表せる比である。 しかし、AOR イカちゃんはできるだけフォロー数を変更したくないので、変更前との差の絶対値をできるだけ小さくしたい。 AOR ...
[ { "submission_id": "aoj_2792_2000870", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nlong long cl(long long a,long long b,long long n){\n long long na=a+(b-a%b);\n if(na/b>n){\n na=n*b;\n return abs(a-na);\n }else{\n long long na2=a-a%b;\n if(na2==0) return abs(a-na);\n ...
aoj_2788_cpp
Multisect We are developing the world's coolest AI robot product. After the long struggle, we finally managed to send our product at revision $R_{RC}$ to QA team as a release candidate. However, they reported that some tests failed! Because we were too lazy to set up a continuous integration system, we have no idea whe...
[ { "submission_id": "aoj_2788_10853223", "code_snippet": "#include <bits/stdc++.h>\n//#include <ext/pb_ds/assoc_container.hpp>\n//#include <ext/pb_ds/tree_policy.hpp>\nusing namespace std;\n//using namespace __gnu_pbds; //new version c++\n//using namespace pb_ds;\n\n#define PB push_back\n#define MP make_pair...
aoj_2797_cpp
G: DAG トリオ / DAG Trio この問題は D: DAG Trio (Easy) と制約のみが異なる同じ設定の問題です。 プロローグ 弟は最近「だぐとりお」が欲しいとしきりに呟いています。 心配になった兄が調べたところ、弟のクラスでは $k$-DAG (有向グラフであって、ある $k$ 個の辺を削除すると、辺の向きを無視したときの連結成分数を $k$ にでき、かつそれら全てが DAG である) が流行っており、 3-DAG を特に DAG トリオと呼ぶことを突き止めました。 弟に尊敬されたい兄は、与えられたグラフが DAG トリオかどうかを判別するプログラムを作成することにしました。 問題文 $N$ 頂点 $M$ 辺の有...
[ { "submission_id": "aoj_2797_2238723", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define MAX_N 500\n#define MAX_M 50000\nstruct edge{ int from,to,id; };\n\nint N,M;\nint a[MAX_M],b[MAX_M];\n\nvector<edge> G[MAX_N];\n\nbool visited[MAX_N];\nint depth[MAX_N];\nint cnt[MAX_N];\nint par[MA...
aoj_2794_cpp
D: DAG トリオ / DAG Trio この問題は G: DAG Trio (Hard) と制約のみが異なる同じ設定の問題です。 プロローグ 弟は最近「だぐとりお」が欲しいとしきりに呟いています。 心配になった兄が調べたところ、弟のクラスでは $k$-DAG (有向グラフであって、ある $k$ 個の辺を削除すると、辺の向きを無視したときの連結成分数を $k$ にでき、かつそれら全てが DAG である) が流行っており、 3-DAG を特に DAG トリオと呼ぶことを突き止めました。 弟に尊敬されたい兄は、与えられたグラフが DAG トリオかどうかを判別するプログラムを作成することにしました。 問題文 $N$ 頂点 $M$ 辺の有...
[ { "submission_id": "aoj_2794_2503049", "code_snippet": "#include <bits/stdc++.h>\n#define int long long\n#define N 1000\n#define V_MAX 1000\nusing namespace std;\nconst int INF = 1LL<<55;\nconst int mod = (1e9)+7;\nconst double EPS = 1e-8;\nconst double PI = 6.0 * asin(0.5);\ntemplate<class T> T Max(T &a,T ...
aoj_2789_cpp
Compressed Formula You are given a simple, but long formula in a compressed format. A compressed formula is a sequence of $N$ pairs of an integer $r_i$ and a string $s_i$, which consists only of digits ('0'-'9'), '+', '-', and '*'. To restore the original formula from a compressed formula, first we generate strings obt...
[ { "submission_id": "aoj_2789_10865828", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i, n) for(ll i=0; i <ll(n); i++)\ntemplate <class T> using V = vector<T>;\ntemplate <class A, class B>\nbool chmax(A &a, B b) { return a < b ...
aoj_2795_cpp
E: 札 / Fuda この問題はリアクティブ問題です。 サーバー側に用意されたプログラムと対話的に応答することで正答を導くプログラムを作成する必要があります。 問題文 湖に浮かぶ $N$ 個の小島からなるビワコという村がある。 各小島には $0$ から $N-1$ まで番号が振られている。 村には島と島の間に架かる橋が $M$ 本あり、$0$ から $M-1$ まで番号が振られている。 橋は双方向に移動可能である。 ここで言う橋とは単に島と島の間の通り道ということであり、取り除くと互いに到達不可能な島の組が増える意味ではない。 最近、橋の両端に掲示板を設置し、その橋を渡った先の島から橋を $1$ 本だけ使って移動できる島 (今いる...
[ { "submission_id": "aoj_2795_2258530", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)\n#define rep(i,n) repl(i,0,n)\n#define mp(a,b) make_pair((a),(b))\n#define pb(a) push_back((a))\n#define all(x) (x).begin(),(x).end()\n#define uniq(x...
aoj_2790_cpp
Non-redundant Drive The people of JAG kingdom hate redundancy. For example, the N cities in JAG kingdom are connected with just $N - 1$ bidirectional roads such that any city is reachable from any city through some roads. Under the condition, the number of paths from a city to another city is exactly one for all pairs ...
[ { "submission_id": "aoj_2790_10907762", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i,n) for(ll i=0; i<ll(n); i++)\ntemplate <class T> using V = vector<T>;\ntemplate <class A, class B> void chmax(A& l, const B& r){ if(l < r) ...
aoj_2800_cpp
C : Mod!Mod! 物語 じゃん!探してますよ目撃証言! 会津に怪盗が現れた!みんなのウマウマ棒が盗まれた!犯人は誰だ!? 解きあかせ!Mod!Mod! 問題文 "アイズ"...それは選ばれし者の心に膨らむ奇跡のつぼみ...。特殊能力"アイズ"を使えばどんなものだって盗むことができる。 会津一の大怪盗、あいずまるは世界を謎で満たすために n 人の探偵から「ウマウマ棒」を盗むことにした。ウマウマ棒とはあいずまるが大好きなただのお菓子であり、 n 人の探偵はそれぞれ数本のウマウマ棒を持っている。また、あいずまるは強欲なためそれぞれの探偵からウマウマ棒を盗むとき、その探偵が所持する全てのウマウマ棒を盗む。 ウマウマ棒の3本同時食いに...
[ { "submission_id": "aoj_2800_8322213", "code_snippet": "#include <iostream>\nusing namespace std;\n\nlong long N;\nlong long A[1 << 19];\nlong long C[3];\n\nint main() {\n\t// Step 1. Input\n\tcin >> N;\n\tfor (int i = 1; i <= N; i++) cin >> A[i];\n\tfor (int i = 1; i <= N; i++) C[A[i] % 3] += 1;\n\n\t// St...
aoj_2801_cpp
D: 日焼け - Suntan - 物語 あいずにゃんは若ヶ松高校のプログラミングコンテスト部、通称ぷろこん部に所属する2年生である。天使のようにかわいい。 あいずにゃんは今年の夏フェスに参加する予定なので、聴きに行くバンドのスケジュールを立てた。 ここで心配なのが日焼けだ。 ライブはすべて野外で行われるが、あいずにゃんは日焼けしやすい体質なので長時間野外で紫外線を浴びすぎるとすぐ日焼けしてしまう。 ライブがない間は屋内に避難することでできるだけ紫外線を回避するつもりだが、ライブ中はどうしても日に当たってしまう。 そこであいずにゃんは日焼け止めを塗ることで紫外線対策をすることを考えた。 問題 日焼け止めを塗ると、塗った時間から T ...
[ { "submission_id": "aoj_2801_10570469", "code_snippet": "#include<bits/stdc++.h>\n#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)\n#define all(v) begin(v),end(v)\nusing namespace std;\nusing ll = long long;\n\nbool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }\nbool chmax(auto &a, auto...
aoj_2806_cpp
B: 重さの範囲 問題 重さの異なる $N$ 色のボールがキューにたくさん入っています。キューには、先頭から $1,2,3, \dots ,N-1,N,1,2,3, \dots ,N-1,N,1,2,3, \dots$ というふうに昇順にボールが並んでいて、 色 $N$ のボールの後ろにはまた色 $1$ のボールから順に入っています。 同じ色のボールはそれぞれ同じ重さであり、色 $i$ のボールの重さは $A_i$ です。 この状態から、キューの先頭からボールを $M$ 個取り出し、これを 1 つのグループとする作業を繰り返します。 そして、キューから取り出した各色のボールの総数がすべて等しくなったときにグループを作る作業をやめます...
[ { "submission_id": "aoj_2806_3448657", "code_snippet": "#include<iostream>\n#include<queue>\nusing namespace std;\n#define inRange(x,a,b) (a <= x && x < b)\n\nint main(){\n int n, m;\n cin >> n >> m;\n int a[n];\n for(int i = 0; i < n; i++) cin >> a[i];\n priority_queue<pair<int,int>> l, r;\...
aoj_2807_cpp
C: Fractal Tree 問題 AORイカちゃんは、フラクタルな(自己相似的な)構造を持つ根付き木が好きである。 $N$ 頂点から成る重み付き根付き木 $T$ を用いて、以下のようなフラクタル構造を持つ根付き木 $T'$ を表現することを考える。 $T'$ は、$T$ の各頂点 $x$ に対して、$x$ を根として $T$ と同様の木構造 (コストも同じ) を持つ木を付け加えたものである。 $T'$の根は $T$ のものと同じものである。 こうして表現される木は例えば下図のようになる。 AOR イカちゃんは、$T'$ に対して深さ優先探索をしようとしているが、全ての頂点を辿ると時間がとてもかかることに気づいた。 そこで、深さ優...
[ { "submission_id": "aoj_2807_9117947", "code_snippet": "#include <bits/stdc++.h>\n#include <vector>\nusing namespace std;\nint inf=100000000;\nusing ll=long long;\nusing pint=pair<int,int>;\nusing pll=pair<ll,ll>;\nusing pque_int=priority_queue<int>;\n#define rep(i,n) for (int i=0; i < (int) n; i++)\n#defin...
aoj_2804_cpp
G: 最小包含矩形 - Minimum Enclosing Rectangle - 物語 みんなぁ、こんにちは! 八森中ぷろこん部の藍座あいりだよぉ。 突然だけど、あいりがこの前解けなかった問題をみんなに解いて欲しいんだぁ~。 この前部活で ICPC2010のA問題 を解いたんだけど、その時の問題が難しかったんだぁ。 あ、ICPCについて説明しなきゃ! ICPCは、い、いんたーなしょなる……ちゅうがくせい……ぷろぐらみんぐ……こんてすとの略で、日本語に直すと、国際中学生対抗プログラミングコンテストらしいよぉ! あいりにはちょっとむずかしい言葉がいっぱいだよぉ。 あいり達はこの世界大会に出るために毎日頑張ってるんだぁ! 部活から帰った...
[ { "submission_id": "aoj_2804_8322784", "code_snippet": "#include <iostream>\n#include <cmath>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nstruct Point {\n\tlong long px, py;\n};\n\nPoint operator-(const Point& a1, const Point& a2) {\n\treturn Point{ a1.px - a2.px, a1.py - a2.py };\n}\n...
aoj_2808_cpp
D: パスワード 問題 AOR イカちゃんは英小文字のみからなる強力なパスワードを作りたいと思っています。 友達から $N$ 個の危険なパスワードの例を教えてもらった AOR イカちゃんは、 以下の条件を全て満たすようなパスワードを作ることにしました。 長さは1文字以上である。 どの危険なパスワードの、どの連続した部分文字列とも異なる。 1, 2 の条件を満たした中で、最も短い文字列である。 1,2,3の条件を満たした中で、辞書順に並べたとき先頭に来る文字列である。 AOR イカちゃんに代わって強力なパスワードを生成するプログラムを書いてください。 入力 入力は以下の形式で標準入力から与えられる。 $N$ $S_1$ $\vdots...
[ { "submission_id": "aoj_2808_10853905", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef unsigned long long ull;\n\nstruct RollingHash\n{\n\tvector<ull> hash, pow;\n\tRollingHash(string s, ull _b = 1000000007)\n\t{\n\t\t_b = _b;\n\t\tint sz = s.length();\n\t\thash.assign(sz + 1, 0)...
aoj_2810_cpp
F: カードゲーム 問題 カードを使ったゲームを $Q$ 回行います。 カードには $1 \cdots N$ の数が書かれており、各数が書かれたカードはゲームを行うのに十分な枚数があります。 $i$ 回目のゲームでは、はじめに手札として 2 枚のカードが配られます。 それぞれのカードに書かれている数字は $x_i$ と $y_i$ です。 カードはルールに従って交換することができます。 $j$ 番目 $(1 \le j \le M)$ のルールでは、カード $a_j$ を手数料 $c_j$ 円で別のカード $b_j$ に交換することができます。 各ルールは何回でも用いることができます。また、手数料が足りなくて交換できない場合はありま...
[ { "submission_id": "aoj_2810_10412963", "code_snippet": "// AOJ #2810 Card Game\n// 2025.4.23\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = (ll)1e18;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tdo n = 10*n + (c & 0xf), c = gc();...
aoj_2803_cpp
F: 風呂がオーバーフロー - Overflow of Furo - 物語 温泉宿・パロは自慢の温泉に全ての情熱を注いでおり、風呂のプロフェッショナルを集めている。 風呂のプロたちは主に温泉の配管を管理しており、複数の源泉から1つの大浴場へと繋がる、複雑に入り組んだ配管網を管理・調整している。 配管網の管理・調整業務もなかなかに大変なのだが、風呂のプロたちはその合間を縫って、さらに多くの湯を浴槽へと供給できるよう日々努力を積み重ねていた。 結果、風呂のプロたちは「1本だけ配管をオーバーフローさせることができる」という荒技を習得した。 すなわち、自由に配管1本を選び、その配管の湯量の制限をなくすことができるようになったのだ。 今まで最...
[ { "submission_id": "aoj_2803_8322658", "code_snippet": "#include <iostream>\n#include <queue>\n#include <vector>\nusing namespace std;\n\nstruct Edge {\n\tint to, cap, rev;\n};\n\nclass MaxFlow {\npublic:\n\tvector<Edge> G[109];\n\tint Dist[109];\n\tbool Used[109];\n\n\tvoid add_edge(int u, int v, int c) {\...
aoj_2802_cpp
E: 鬼畜ババ抜き - Unbalanced Old Maid - 物語 高坂さんと園田さんと南さんは子供の頃からの仲良し3人組だ。3人は沖縄に修学旅行に行くも、台風が来てしまい、海で遊ぶことができないのでババ抜きをすることにした。 園田さんは勝負事には強いが、ポーカーフェイスが苦手なため、自分のカードが引かれるときに無意識にかわいらしい顔芸を披露してしまう。園田さんを愛して止まない高坂さんと南さんは、園田さんの顔芸を見るだけで園田さんの手札が分かってしまうため、園田さんのカードを引くときは、自分が有利になるように引くことができる。 一方、高坂さんと南さんは特に顔芸をしたりはしないので、手札がばれることはない。 よって、高坂さんと南...
[ { "submission_id": "aoj_2802_8322461", "code_snippet": "#include <iostream>\n#include <tuple>\n#include <vector>\nusing namespace std;\n\nint N;\nint M[3], P[3][409];\nint Cnt[3][109];\ndouble prevs[109][109][109][3];\ndouble dp[109][109][109][3];\ndouble Answer = 0.0;\n\nint main() {\n\t// Step 1. Input\n\...
aoj_2809_cpp
E: 卒業式 背景 ある日 Y さんはプログラミングコンテストに参加するため,会場がある大学に向かいました. ところが大学に着くと人がたくさん!なんと今日は卒業式だったのです. 会場に向かおうにも人に押し流されてしまい,自分の進みたい方向に進むことすらできません. 人混みから抜け出すために,Y さんは今いる場所から少しでも遠くに行きたいと考えました. そこで Y さんは状況を以下のような問題として定式化し,競技プログラミングを役に立てることにしました. なお,以下の問題文では Y さんは点 $P$ としてモデル化されています. 問題 座標平面上の原点に点 $P$ が置かれている. 点 $P$ を動かし,できるだけ原点からのマンハッタ...
[ { "submission_id": "aoj_2809_9117771", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\n\n#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)\n#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)\n\ntemplate <typename T> bool chmin(T &a, const...
aoj_2813_cpp
I: Islands Survival 問題 $N$ 頂点 $M$ 辺の単純連結無向グラフがある. 頂点には $1, 2, \dots, N$ と番号がつけられている. 辺には $1, 2, \dots, M$ と番号がつけられており,辺 $i$ は頂点 $a_i$ と $b_i$ をつないでいる. また,辺 $i$ は時刻 $t_i$ に消える.どの辺も通過するために単位時間がかかる. あなたは最初,時刻 0 において頂点 1 にいる. あなたは最適に行動することで,時刻 $T$ までに得られるスコアを最大化したい. スコアは最初 0 であり,イベントは以下に従って起きる. 今の時刻 $t'$ が $t' \geq T$ を満た...
[ { "submission_id": "aoj_2813_10413041", "code_snippet": "// AOJ #2813 Islands Survival\n// 2025.4.23\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tdo n = 10*n + (c & 0xf), c = gc(); while (c >= '0');\...
aoj_2811_cpp
G: 雨降りバス乗り換え 背景 今日は AOR イカちゃんにとって初となるデートの日だ。 AOR イカちゃんは駅からバスを乗り継ぎ、待ち合わせ場所のバス停に向かう予定である。 AOR イカちゃんが駅に着いた時、不幸にも雨が降ってきた。当初予定していた経路ではバスの待ち時間で濡れてしまい、せっかく整えた身だしなみが台無しになってしまう可能性がある。 そこで、バスの待ち時間が最も少なくなるような経路でバス停まで向かうことにした。 AOR イカちゃんは、待ち合わせ場所のバス停に着くまでにどの程度濡れるのか心配している。 問題 AOR イカちゃんは時刻 $0$ に $S$ 番目のバス停におり、そこから $G$ 番目のバス停まで行き...
[ { "submission_id": "aoj_2811_9752318", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int M = 200001;\nint u[M], v[M], t[M], c[M];\nvector<int> start[M], dest[M], busy_time[M];\n\nint main() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n #ifdef BACKER\n ...
aoj_2812_cpp
H: ジャンプパーティ 問題 とあるダンスホールで $N$ 人の参加するダンスパーティーが行われる。 そのダンスホールは縦方向に $H$ 個、横方向に $W$ 個のグリッドに分けられており、 左上を $(0,0)$、上から $r$ マス、左から $c$ マス目のグリッドの座標を $(r,c)$ と表す。 $i$ 番目の参加者の初期位置は $(R_i, C_i)$ であり、$(i,j)$ のグリッドには $(r_{ij}, c_{ij})$ が書かれている。 各参加者は、無限に続く音楽に合わせて次のように同時に移動を行う。 その時にいる座標が $(i,j)$ のとき、$(r_{ij}, c_{ij})$ へジャンプで移動する。 それぞ...
[ { "submission_id": "aoj_2812_10191609", "code_snippet": "// AOJ #2812\n// Jump Party 2025.2.5\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() { // 整数の入力\n\tint n = 0, c = gc();\n\tif (c == '-') {\tc = gc();\n\t\tdo n = 10*...
aoj_2817_cpp
B: だんすなうwww - Dance Now! - 物語 前回のラボライフ!ダイガクイン!! マスターアイドルたちが競う最大の大会「ラボライフ」の前哨戦ともいえるイベント「マスターアイドルワールド」で9位を取ってしまったドサンコスノー。 キレのあるダンスは「9位の舞」、渾身の決めポーズも「9位の構え」などと冷やかされてしまい、心に深い傷を負ってしまう。 来たるラボライフ予備予選では絶対に9位をとるわけにはいかない…… 決意を新たにしたドサンコスノーは、自分たちの特技「セルフコントロール」に磨きをかけ、決戦の地へと向かうのだった。 問題 N 組のユニットが競う大会「ラボライフ」が開かれる。 この大会では、スマイル・ピュア・クールの3...
[ { "submission_id": "aoj_2817_10195234", "code_snippet": "// AOJ #2817\n// Dance Now! 2025.2.5\n\n#include <bits/stdc++.h>\nusing namespace std;\n \nint main(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n \n int N; \n cin >> N;\n \n vector<int> r(N);\n for (int i = 0; i < N; i++) cin >...
aoj_2814_cpp
J: エナジードリンク 問題 ixmel、Pulmn 兄弟は $N$ 種類のエナジードリンクをそれぞれ 1 本ずつ持っています。 現在、ixmel と Pulmn のエネルギーはともに 0 で、時刻は午前 0 時です。 ixmel と Pulmn はエネルギーが 0 以下のまま正午になると「たいへんなこと」になります。 エネルギーが正の数では「たいへんなこと」にはなりません。 ixmel とPulmn は「たいへんなこと」にならないために、 毎日朝 6 時に 1 本のエナジードリンクを 2 人で分けて飲むことにしました。 i 番目のエナジードリンクを ixmel が飲むとエネルギーが $a_i$ 増えますが、副作用として 24 時間...
[ { "submission_id": "aoj_2814_9118078", "code_snippet": "#line 2 \"/Users/noya2/Desktop/Noya2_library/template/template.hpp\"\nusing namespace std;\n\n#include<bits/stdc++.h>\n#line 1 \"/Users/noya2/Desktop/Noya2_library/template/inout_old.hpp\"\nnamespace noya2 {\n\ntemplate <typename T, typename U>\nostrea...
aoj_2815_cpp
K: AOR イカちゃんの成績 問題 AOR イカちゃんは $N$ 回のレポートの点数のみで成績が決まる授業を受けている。 AOR イカちゃんは同じ授業を受けている友達が $M$ 人いて、自分が苦手なテーマのレポートは、そのテーマが得意な友達のレポートを写すことで、その友達と同じ点数を取ることができる。 ただし、他人のレポートを写していることを先生に気付かれてはいけないので、 $N$ 回のうち少なくとも $K$ 回は他人のレポートを写さず、自力でレポートを仕上げなくてはならない。 また、 AOR イカちゃんは友達に迷惑をかけたくないと思ったので友達 $i$ に対してレポートを写すのは $T_i$ 回以下にすることにした。 ...
[ { "submission_id": "aoj_2815_5147669", "code_snippet": "#line 1 \"test/aizu-online-judge/2815.test.cpp\"\n#define PROBLEM \"https://onlinejudge.u-aizu.ac.jp/problems/2815\"\n\n#include <iostream>\n\n#line 2 \"src/graph/directed/flow/min_cost_flow.hpp\"\n\n/**\n * @file min_cost_flow.hpp\n * @brief Minimum C...