group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_2818_cpp
C: 今川焼きマン - Imagawayaki Man - 物語 今川焼きマンは、正義のヒーローである。顔は直径 1 メートルの今川焼き(主に小麦粉でできた生地の中にたっぷりと餡を詰めて焼いた食べ物であり、見た目は円形であり、美味しい。北海道では、単に「お焼き」と呼ばれることも多い。餡として小豆餡のほかに、カスタードクリームなどを用いることもあり、さまざまな味のバリエーションがある。そのため、いくつ食べても飽きない。小豆餡やカスタードクリームのほかに、抹茶餡やりんごジャムなども美味しい。中にタコを入れたたこ焼きのようなものもあるようだ。どの味も美味しい。下の写真は標準的な今川焼きである。左はクリーム餡、右は小豆餡が入っている。美味し...
[ { "submission_id": "aoj_2818_6938743", "code_snippet": "#include <bits/stdc++.h>\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nusing std::cout;\nusing std::cin;\nusing std::endl;\nusing ll=long long;\nusing ld=long double;\nll ILL=2167167167167167167;\nconst int INF=2100000000;\nconst ll mod=1e9+7...
aoj_2819_cpp
D:歪みの国 - Country In Distortion - 物語 アリスはすっかり退屈していました。いつも一緒に遊んでいる白ウサギが、トランプ城へ出かけているからです。(あーあ、こんなことなら一緒に出かければよかったわ。)とアリスは思いました。けれども、ここは歪みの国。そうやすやすと出かけては、ひどく疲れてしまいます。どういうことかというと— 白ウサギは困っていました。トランプ城への道中、ちょっとだけ道を間違えてしまったのです。(困ったなあ。一度戻って、道を良く知っているアリスに案内してもらうことにしよう。)と白ウサギは考えました。それにしても、白ウサギはとっても疲れているみたい。白ウサギは懐中時計を見ながら、 「なんだってこ...
[ { "submission_id": "aoj_2819_6938832", "code_snippet": "#include <bits/stdc++.h>\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nusing std::cout;\nusing std::cin;\nusing std::endl;\nusing ll=long long;\nusing ld=long double;\nll ILL=2167167167167167167;\nconst int INF=2100000000;\nconst ll mod=1e9+7...
aoj_2821_cpp
F: 木を隠すのなら森の中 物語 「木はいいです」 喫茶店「タートルハウス」を経営するチコちゃんは、木に並々ならぬ愛情を持っている。なんでも、木の不動のあり方に心が洗われるらしい。。。そんなチコちゃんの木への愛情を確かめるため、同じ喫茶店でバイトをしているココロちゃんはチコちゃんにいたずらを仕掛けることにした。 ココロちゃんは、チコちゃんのために森を用意して、喫茶店近くに生えていた木を何本か森の中に隠し、チコちゃんの木への愛情を試すことにした。具体的には、チコちゃんに、隠した木を森の中から見つけてもらうことにした。木をこよなく愛するチコちゃんなら、一度見たことがある木は、心の洗われ方の違いでわかるのだが、木を移動してしまったため、木...
[ { "submission_id": "aoj_2821_10191617", "code_snippet": "// AOJ #2821\n// Trees in a Forest 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 ...
aoj_2824_cpp
海岸線 海岸には毎秒波が押し寄せる.基準点 P を超えて何 m の地点まで波が押し寄せたかを, T 秒の間だけ毎秒観測し記録したデータがある.データは T 個の整数 x 1 , ... , x T からなり,各 i (1 ≤ i ≤ T) に対し,観測を始めてから i 秒後には地点 P からちょうど x i m の地点までの波が押し寄せ,海水に浸っていたことを表す. 海岸は,最後に海水に浸ってから D 秒後に乾くことが分かっている.ここで,乾くまでの時間は最後に海水に浸った時間のみに依存し,それ以前に波に浸っていた回数や時間には依存しないことに注意せよ. 基準点 P から,陸の方向に距離 L だけ離れた地点が,観測を開始してから ...
[ { "submission_id": "aoj_2824_10852979", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\nconst int INF = 1e9;\nconst ll LINF = 1e18;\ntemplate<class S,class T> ostream& operator << (ostream& out,const pair<S,T>&...
aoj_2822_cpp
G: 恋のジュンレツRun!Run!Run! - Love Permutation, Run run run! - 物語 おおきなジュンレツ らんらんらんでぶー♪ Hello, 星空蘭にゃ! 好きなデータ構造は Starry Sky Tree にゃ! 蘭は最近物理学科に入学したんだけど、どうやらそこでもプログラミングをやらないといけないらしいんだ。 蘭、アルゴリズムやデータ構造の理論は好きなんだけど、実装はどうも苦手なんだよね…… だいたい蘭達は人間なのに、どうして機械の言葉を勉強しなくちゃいけないの!? とはいえ、課題をやらないことには単位が出ないしやるしかないにゃ。 今回出た課題は順列の run とかいうのが関係しているらしいん...
[ { "submission_id": "aoj_2822_4877140", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n\t// freopen(\"input.txt\", \"r\", stdin);\n\t// freopen(\"output.txt\", \"w\", stdout);\n\tint n; cin >> n;\n\tvector<int> a(n);\n\tfor(int i=0;i<n;i++){\n\t\tcin >> a[i];\n\t}\n\tint m; c...
aoj_2825_cpp
クイズ あなたはクイズ番組のディレクターである. クイズ番組には解答者として N 人が出演予定であり,それぞれ 1 から N まで番号付けられている. 問題は M+1 問出題する予定であり,それぞれの問題は 1 から M+1 まで番号付けられている. 問題は番号順に出題され,それぞれ早押しで最初に正解した人にのみ得点が入る. i 問目の問題の得点は整数 S i である. M+1 問目の問題を終えた時点で総合得点が最大の人が優勝する. ただし,最大得点の人が複数人存在する場合,優勝者は存在しない. 現在 M 問目まで配点を決めたので, M+1 問目の配点を決めようと考えている. 最後の問題は,誰でも逆転できる点数にするのがクイズ番組...
[ { "submission_id": "aoj_2825_10852965", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\nconst int INF = 1e9;\nconst ll LINF = 1e18;\ntemplate<class S,class T> ostream& operator << (ostream& out,const pair<S,T>&...
aoj_2831_cpp
A: 丸付け 問題 AORイカちゃんはテストに合格するため勉強しています。 AORイカちゃんは、 $N$ 問、問題を解きました。 その後、解いた問題の丸付けを以下の手順で行います。 解答の正誤を確認する。 解答が正しい場合はマル印、誤っていた場合はバツ印を解答用紙に書き込む。 解答が $2$ 問連続で誤りであるとわかった瞬間、テストに不合格になってしまう恐怖から、AORイカちゃんは失神してしまいます。そして、それ以降丸付けを行うことはできません。 失神は手順 $1$ と $2$ の間で起こります。 AORイカちゃんが解いた問題の数を表す整数 $N$ と、解答の正誤を表した長さ $N$ の文字列 $S$ が与えられます。 文字列は '...
[ { "submission_id": "aoj_2831_4778533", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <utility>\n#include <string>\n#include <vector>\n#include <set>\n#include <stack>\n#include <queue>\n#include <map>\n#include <math.h>\n#include <string.h>\n#include <iomanip>\n#include <numeric>\n#in...
aoj_2826_cpp
ゲームバランス あなたは冒険ゲームを作成している.このゲームのプレイヤーは,主人公を操作して敵モンスターを倒し,主人公のレベルを上げることで冒険を進めていく.主人公の初期レベルは 1 である. このゲームには N 種類の敵モンスターが用意されており,弱い順で i 番目の種類の敵モンスターの強さは s i である.主人公が 1 回の戦闘を行うときには,次に戦う敵モンスターの種類を自由に選び,ちょうど 1 体の敵モンスターと戦闘を行う.主人公は同じ種類の敵モンスターと何回でも戦うことができ,何回でも倒すことができる. あなたはいま,このゲームのバランスを調整するために,あるパラメーター X を決めようとしている.パラメーター X は正の...
[ { "submission_id": "aoj_2826_10865783", "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 VI = vector<int>;\nusing VL = vector<LL>; using VVI = vector<VI>;\nconst LL LINF = 1e18; const int INF = 1e9;\n#define SZ(a)...
aoj_2827_cpp
凸多角形柱工業都市 凸多角形柱工業都市 (Industrial Convex Pillar City, ICPC) はいくつかの凸多角形柱の形状をした建物からなる街である.あなたはこの街の中を現在地 S から目的地 T に向けて歩こうとしている.今日は日差しが強いので,出来る限りひなたを通らずに目的地へ向かいたい.あなたが立っている地点と太陽を一直線に結んだ線上に建物がある場合,あなたは建物の陰にいるので日差しを受けずにすむ.また,この街の建物の外周には全てひさしが付いているので,建物の外周に沿って歩いている間は,日が当たる縁に沿って歩いても日差しを受けることはない.あなたは建物の内部以外はこの街をどこでも自由に歩くことができる. ...
[ { "submission_id": "aoj_2827_10946036", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\nconst int INF = 1e9;\nconst ll LINF = 1e18;\ntemplate<class S,class T> ostream& operator << (ostream& out,const pair<S,T>&...
aoj_2820_cpp
E:バイナリ列 - Binary Sequence - 物語 わしはバイナリ大好きBonald.Brvin.Bnuthじゃ! オフトゥンフォード大学でバイナリ列の性質を研究しておってのお、Bnuthおじさんと呼ばれて、親しまれておるぞい! ちなみに、わしの名前「Bonald.Brvin.Bnuth」をASCIIコードからバイナリ化すると「1000010 1101111 1101110 1100001 1101100 1100100 101110 1000010 1110010 1110110 1101001 1101110 101110 1000010 1101110 1110101 1110100 1101000」になるぞい! 楽...
[ { "submission_id": "aoj_2820_8106271", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, buckets, y) for (int i = (buckets); i < (y); ++i)\n#define debug(buckets) #buckets << \"=\" << (buckets)\n#ifdef DEBUG\n#define _GLIBCbucketsbuckets_DEBUG\n#define print(buckets) ...
aoj_2828_cpp
マトリョーシカ マトリョーシカはロシアの民芸品として有名な人形である. マトリョーシカは上下に分割でき,開くと中により小さい別の人形が入っている. 現れた小さい人形を開くとさらに小さい人形が入っている,というような入れ子構造になっている. あなたは旅行先で珍しい形のマトリョーシカを見つけ, N 体の人形を購入した. i 番目の人形の形状は, x i × y i × z i の直方体である. ひとしきりマトリョーシカを鑑賞したあなたは,マトリョーシカを仕舞おうとしている. その前に,いくつかの人形を別の人形に格納することによって必要なスペースを減らしたい. 人形を格納する際には,まだ中にひとつも人形を格納していない人形にだけ,他の人形...
[ { "submission_id": "aoj_2828_10853033", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\nconst int INF = 1e9;\nconst ll LINF = 1e18;\ntemplate<class S,class T> ostream& operator << (ostream& out,const pair<S,T>&...
aoj_2832_cpp
B: 全日本帰りたい協会 問題 株式会社 AOR (Association Of Return home)には $N$ 人の社員がいる。 社員 $i$ はエレベーターを使って $1$ 階に下りたいと考えており、時刻 $t_i$ に $F_i$ 階のエレベーター前にやってくる。あなたは時刻 $0$ に $1$ 階に $1$ 基だけあるエレベーターを遠隔操作し、すべての社員を $1$ 階に送ることにした。エレベーターには $D$ 人までしか乗せられない。 エレベーターは単位時間に一階分移動するかその場にとどまる事ができる。 社員 $i$ はエレベーターが時刻 $t_i$ に $F_i$ 階にあって、自分が乗っても定員を超過しない...
[ { "submission_id": "aoj_2832_8107774", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n\nmt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());\nll myRand(ll B) {\n return (u...
aoj_2839_cpp
B: えびちゃんと数列 - Ebi-chan and Integer Sequences - 問題 えびちゃんは数列が好きです。中でも等差数列が特に好きです。 今回は以下の条件を満たす数列を作ることにしました。 長さ n の等差数列である 数列の i 番目の要素を s_i と定める時、全ての s_i (1 \leq i \leq n) が 0 \leq s_i \leq m を満たす整数である 上の条件を満たすような数列はいくつあるでしょうか? ただし答えは非常に大きくなることがあるので、 10^9 + 7 で割った余りを出力してください。 入力形式 入力は一行で与えられる。 n m n は数列の長さを表す。 制約 1 \leq n...
[ { "submission_id": "aoj_2839_3419924", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\ntemplate<int mod> struct ModInt {\n\tusing ll = long long;\n\tint x;\n\ttemplate<class T>\n\tModInt(T a) {\n\t\tx = a % mod;\n\t\tif (x < 0) {\n\t\t\tx += mod;\n\t\t}\n\t}\n\tModInt() : x(0) {}\n\tinl...
aoj_2836_cpp
F: Steps 問題 AORイカちゃんは株式会社AORの視察に訪れた。 株式会社AORは $N$ 階建てのビルであり、地下階は存在しない。 AORイカちゃんは $1$ 階から視察を開始し、ちょうど $M$ 回移動することにした。 $1$ 回の移動で $i$ 階から $i + 1$ 階、あるいは $i - 1$ 階に移動することができる。 ただし、 移動先が $0$ 階や $N + 1$ 階となるように移動することはできない。 AORイカちゃんが全ての階に一度以上訪れる移動方法の通り数を $1000000007 (= 10^9 + 7)$ で割った余りを求めよ。 なお、 $1$ 階にはすでに訪れたものとする。 制約 $2 \leq ...
[ { "submission_id": "aoj_2836_5964592", "code_snippet": "//#define _GLIBCXX_DEBUG\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define endl '\\n'\n#define lfs cout<<fixed<<setprecision(10)\n#define ALL(a) (a).begin(),(a).end()\n#define ALLR(a) (a).rbegin(),(a).rend()\n#define UNIQUE(a) (a).erase(uni...
aoj_2829_cpp
へやわり! N+1 部屋が1列に並んだ新築の建物がある.各部屋はすべて1人用の住居であり,現在どの部屋も空室だが,来月から新たに N 人がここに住む予定である.したがって彼らが暮らし始めると1室は空き部屋になる. あなたは大家として,彼らの嗜好に合わせた部屋割りを多く提案したいと考えている.ここで部屋割りとは,それぞれの人がどの部屋に住むのかを与える表である.例えば N = 3 のとき,「1人目は4号室,2人目は1号室,3人目は2号室」がありうる一つの部屋割りである. もちろん,ありうるすべての部屋割りを提案すれば話は早いが,それでは提案の意味がないため,大家の手間と住人の嗜好を考慮していくつか制約を設ける. まず,提案された部屋割...
[ { "submission_id": "aoj_2829_10670429", "code_snippet": "#include <bits/extc++.h>\n\nusing ll = long long;\nusing namespace std;\n#define REP(i, n) for (ll i = 0; i < ll(n); i++)\n#define ALL(n) (n).begin(), (n).end()\n#define FOR(i, j, n) for (ll i = j; i < ll(n); i++)\nll MOD = 1000000007ll;\n\nll powmod(...
aoj_2830_cpp
Big Maze あなたは Jumbo Amusement Garden,略して「JAG」と呼ばれる巨大な遊園地で働いている.この遊園地の敷地は広大で,アトラクションもことごとく巨大なものが設置される. この度JAGに,新たな巨大迷路アトラクション「Big Maze」が導入されることになった. Big Maze の形状は,平面図で見ると,縦横共に N マスの正方形状の迷路 M 個を,隣接する左右の辺同士を繋ぎ合わせ,縦 N マス,横 NM マスの長方形状になる予定である. M 個の迷路を左からどの順番で繋ぎ合わせるかはあらかじめ決まっているが,隣り合う迷路のどの辺同士を繋ぎ合わせるかは未定である. M 個の迷路を繋ぎ合わせる前に,各...
[ { "submission_id": "aoj_2830_10607120", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nnamespace atcoder {\n\tstruct dsu {\n\tpublic:\n\t\tdsu() : _n(0) {}\n\t\texplicit dsu(int n) : _n(n), parent_or_size(n, -1) {}\n\n\t\tint merge(int a, int b) {\n\t\t\tassert(0 <= a && a < _n);\n\t\t\ta...
aoj_2833_cpp
C: ツイート数 問題 AORイカちゃんが利用するSNSであるイカったーでは、投稿のことをツイートと呼ぶ。 そして、イカったーでは、ツイートへの返信が多くなると視認性が悪くなることが懸念されるため、あるツイートが次の規則のいずれかを満たすときに画面にそのツイートを表示する仕様になっている。 規則1. どのツイートへも返信していない 規則2. どのツイートからも返信されていない 規則3. 規則2が適用されたツイートから返信先を順に辿ったとき、 $K$ 回未満で辿り着ける なお、同じツイートは重複して表示されることはない。 いま、 $N$ 個のツイートがあり、 $A_i$ が $0$ のとき $i$ 番目のツイートは返信でないツイートで...
[ { "submission_id": "aoj_2833_6985470", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint main(){\n int n, k, v;\n cin >> n >> k;\n vector<vector<int>> g(n);\n vector<int> R, H(n);\n for(int i = 0; i < n; i++){\n cin >> v;\n if(v == 0){...
aoj_2834_cpp
D: 次元旅行 問題 次元が $1$ 次元から $N$ 次元まで存在する。 AORイカちゃんは次元間を移動できる。 具体的には、AORイカちゃんが $i$ 次元にいるとき、 $j$ 次元( $i > j$ )には自由に移動する事ができるが、 $k$ 次元( $i < k$ )に移動するには魔法を使う必要がある。 AORイカちゃんは $M$ 種類の魔法が使え、 $1, 2, \dots, M$ と番号が振られている。 $i$ 番目の魔法では $a_i$ 次元から $b_i$ 次元に移動できる。 これは $a_i$ 次元にいるときしか使えない。 $i$ 次元に行くと次元特有の「次元の呪い」を受ける。 $i$ 次元の「次元の呪い」に...
[ { "submission_id": "aoj_2834_9886997", "code_snippet": "// competitive-verifier: PROBLEM\n#include <iostream>\n#include <vector>\n/**\n * @brief 重み付きグラフ\n *\n * @tparam T 辺の重みの型\n */\ntemplate <class T>\nstruct Graph {\n private:\n struct _edge {\n constexpr _edge() : _from(), _to(), _weight() {}...
aoj_2835_cpp
E: 敵襲から守れ 問題 島が $V$ 島あり、それぞれ $0, 1, ..., V-1$ と番号がついている。橋が $E$ 本あり、それぞれ $0, 1, ..., E-1$ と番号がついている。 $i$ 番目の橋は島 $s_i$ と島 $t_i$ にかかってあり、幅は $c_i$ である。 島 $0$ に基地があるAORイカちゃん軍団 (通称イカ団) は規模が弱小であるため、島 $V-1$ にあるSosu-Usa軍団 (通称そすうさ団) にいつもやられっぱなしである。ある日、イカ団は「そすうさ団が明日攻めてくる」との情報を得た。そすうさ団の基地から大人数のそすうさ団の部下が橋を渡って島を移動し、部下が一人でもイカ団の基地にたどり...
[ { "submission_id": "aoj_2835_10886269", "code_snippet": "// BEGIN: main.cpp\n#line 1 \"main.cpp\"\n#define PROBLEM \"https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2835\"\n\n// BEGIN: my_template.hpp\n#line 1 \"my_template.hpp\"\n#if defined(LOCAL)\n#include <my_template_compiled.hpp>\n#else\n#if...
aoj_2843_cpp
F: 掛け算は楽しい - Multiplication Is Interesting - 物語 男子高生の難波列くんは、彼女の誕生日に数列をプレゼントしようと考えている。彼女は掛け算が大好きな女の子なので、難波くんは彼女にできるだけ多くの掛け算を楽しんてもらえるような数列をプレゼントしたいと思っている。しかし、計算結果が 2^{20} を超える値になると彼女の機嫌が途端に悪くなってしまう(通常の人類は 2^{20} という膨大な数を計算できないため、これでも彼女は随分と寛大な人であると言える)。彼女の機嫌を損なわないように、できるだけ多くの掛け算を楽しんでもらえる数列を難波くんが作ったので、あなたの仕事はその数列が彼女を十分に楽しま...
[ { "submission_id": "aoj_2843_10538313", "code_snippet": "// AOJ #2843 Multiplication Is Interesting\n// 2025.5.28\n\n#include <bits/stdc++.h>\nusing namespace std;\nconst double EPS = 1e-9;\nconst int INF = 1e9;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() {\n\tint n = ...
aoj_2841_cpp
D: 優柔不断 - Indecision - 問題 えびちゃんは最近ギャルゲーにハマっていて、今の目標は二人のヒロインを同時に攻略することです。 えびちゃんはいくつかあるイベントを利用してヒロインからの好感度を高めることができますが、各イベントの対象として選べるヒロインはどちらか一人のみです。しかし、えびちゃんは選ばなかったヒロインに対してもフォローを忘れないので、もう片方のヒロインからの好感度もある程度は高めることができます。ただし、イベントには費用がかかるため、必ずしも全てのイベントを行えるわけではありません。 さて、優柔不断なえびちゃんは各イベントをどちらのヒロインと行うか(またはどちらとも行わないか)で迷っています。えびちゃ...
[ { "submission_id": "aoj_2841_10191600", "code_snippet": "// AOJ #2841\n// Indecision 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, C;\n cin >> N >> C;\n vector<int> a(N), b(N), cost(N);\n for (int i = 0; i ...
aoj_2844_cpp
G: ほぼ無限グリコ - Almost Infinite Glico 問題 N 個のマスが円環状に並んでいるフィールドがあります。 i 番目 (1 \leq i \leq N-1) のマスの 1 つ先は、 i+1 番目のマスになります。ただし、 i = N の場合、その 1 つ先は 1 番目のマスになります。 あなたが最初にいるマスは 1 番目のマスです。そこから以下のルールに従って、じゃんけんを K 回続けて行います。このとき、あなたと相手は特殊なじゃんけんを会得しているので、じゃんけんの勝ち方が M 通りあります。 相手とじゃんけんを行い、あなたが相手に勝ったとき、今出した手、すなわち勝ち方 i に応じたマス数 p_i だけ進み...
[ { "submission_id": "aoj_2844_6939724", "code_snippet": "#include <bits/stdc++.h>\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nusing std::cout;\nusing std::cin;\nusing std::endl;\nusing ll=long long;\nusing ld=long double;\nll ILL=2167167167167167167;\nconst int INF=2100000000;\nconst ll mod=1e9+7...
aoj_2840_cpp
C: たったひとつの部分列 - Unique Subsequence - 問題 ある日えびちゃんは、机の上に長さ n のテキスト文字列 T と長さ m のパターン文字列 P ( m \leq n ) が置かれていることに気づきました。えびちゃんは、文字列に現れる「たったひとつの部分列」が大好きであるため、 P が T のたったひとつの部分列であるかどうかをすぐに調査し始めました。 P が T のたったひとつの部分列であるという性質は以下のように表されます。ここで、文字列 X の i 文字目を X_i と書きます。 長さ m の数列 S = (s_1, ..., s_m) (ただし、 s_1 < s_2 < ... < s_m ) で...
[ { "submission_id": "aoj_2840_4642810", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing pll = pair<ll,ll>;\nconst ll LINF = 0x1fffffffffffffff;\n#define name3(_1,_2,_3,name,...) name\n#define rep1(n) for(ll i=0;i<(n);++i)\n#define rep2(i,n) for(ll i=0;i<(n);++i)\...
aoj_2852_cpp
Tiny Room You are an employee of Automatic Cleaning Machine (ACM) and a member of the development team of Intelligent Circular Perfect Cleaner (ICPC). ICPC is a robot that cleans up the dust of the place which it passed through. Your task is an inspection of ICPC. This inspection is performed by checking whether the ce...
[ { "submission_id": "aoj_2852_7211818", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define rep(i,a,b) for(int i=a;i<b;i++)\nusing ll = long long;\ntemplate<class T> bool chmin(T &a,const T b){if(a>b){a=b;return 1;}return 0;}\ntemplate<class T> bool chmax(T &a,const T b){if(a<b){a=b;retur...
aoj_2846_cpp
Slimming Plan Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight. Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His weight is $S$ on the 0-th day of the plan and he aims to reduce...
[ { "submission_id": "aoj_2846_10787168", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < n; ++i)\nconstexpr ll INF = 9009009009009009009LL;\n\nint main(){\n ll s, t, d; cin >> s >> t >> d;\n vector<ll> w(d);\n rep(i, d) cin...
aoj_2842_cpp
E: たい焼きマスターと食べ盛り - Taiyaki-Master and Eater 物語 つたさんはたい焼きを作るのがとても上手い。えびちゃんはそんなつたさんが作るたい焼きが大好きだ。 2 人は毎週たい焼きを作って食べて幸せに過ごしているが、たい焼きを作っているそばで食べ盛りのえびちゃんにつまみ食いをされてしまうのがつたさんの最近の悩みだ。 学校祭でたい焼きを作ることになったつたさんは、いつものようにえびちゃんにつまみ食いされていたら売上が心配なので、自分が注目している範囲のたい焼きの様子を知ることができればいいなと思った。学校祭が成功するように、つたさんを助けてあげよう。 問題 縦 H 、横 W の長方形状のたい焼きプレートが...
[ { "submission_id": "aoj_2842_10692821", "code_snippet": "#include <iostream>\n#include <stdio.h>\n#include <string>\n#include <stack>\n#include <queue>\n#include <vector>\n#include <map>\n#include <set>\n#include <unordered_set>\n#include <cmath>\n#include <algorithm>\n#include <bitset>\n#include <climits>\...
aoj_2847_cpp
Ninja Map Intersections of Crossing Path City are aligned to a grid. There are $N$ east-west streets which are numbered from 1 to $N$, from north to south. There are also $N$ north-south streets which are numbered from 1 to $N$, from west to east. Every pair of east-west and north-south streets has an intersection; the...
[ { "submission_id": "aoj_2847_10787335", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < n; ++i)\n#define loop(i, a, b) for (ll i = a; i <= b; ++i)\nconstexpr ll INF = 9009009009009009009LL;\n\nint main() {\n ll n; cin >> n;\n ...
aoj_2848_cpp
Janken Master You are supposed to play the rock-paper-scissors game. There are $N$ players including you. This game consists of multiple rounds. While the rounds go, the number of remaining players decreases. In each round, each remaining player will select an arbitrary shape independently. People who show rocks win if...
[ { "submission_id": "aoj_2848_10057505", "code_snippet": "//tekitou hash demo tooru to uresii\n#include<bits/stdc++.h>\nusing namespace std;\n\nusing ll=long long;\n#define rep(i,n) for(int i=0;i<n;i++)\n#define rep2(i,s,t) for(int i=s;i<t;i++)\n\nusing vi=vector<int>;\n\nint main() {\n \n cin.tie(null...
aoj_2849_cpp
Route Calculator You have a grid with $H$ rows and $W$ columns. $H + W$ is even. We denote the cell at the $i$-th row from the top and the $j$-th column from the left by ($i, j$). In any cell ($i, j$), an integer between $1$ and $9$ is written if $i+j$ is even, and either ' + ' or ' * ' is written if $i+j$ is odd. You ...
[ { "submission_id": "aoj_2849_10787319", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define vl vector<ll>\n#define vvl vector<vl>\n#define vvvl vector<vvl>\n#define vvvvl vector<vvvl>\n#define rep(i, n) for (ll i = 0; i < n; ++i)\n#define loop(i,m,n) for(ll i=m;i<...
aoj_2855_cpp
Permutation Period You have a permutation $p$ of $N$ integers. Initially $p_i = i$ holds for $1 \leq i \leq N$. For each $j$ ($1 \leq j \leq N$), let's denote $p_{j}^0 = j$ and $p_{j}^k = p_{p_j}^{k-1}$ for any $k\geq 1$. The period of $p$ is defined as the minimum positive integer $k$ which satisfies $p_{j}^k = j$ for...
[ { "submission_id": "aoj_2855_10850960", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing pii = pair<int, int>;\nusing ll = long long;\n\nconstexpr ll M = 1e9 + 7;\nconstexpr int MAXN = 1e5 + 1;\n\nstruct Qry{\n Qry() = default;\n Qry(int x, int y, int l):e(x, y),l(l){};\n pi...
aoj_2850_cpp
Endless BFS Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows: 1: $current \leftarrow \{start\_vertex\}$ 2: $visited \leftarrow current$ 3: while $visited \ne $ the set of...
[ { "submission_id": "aoj_2850_10870043", "code_snippet": "#include <algorithm>\n#include <iostream>\n#include <vector>\n#include <utility>\n#include <queue>\nusing namespace std;\nint main() {\n cin.tie(0);\n cout.tie(0);\n ios::sync_with_stdio(0);\n int N, M;\n cin >> N >> M;\n vector<vect...
aoj_2854_cpp
Sum Source Detection JAG members began a game with integers. The game consists of $N + M + 1$ players: $N$ open number holders, $M$ secret number holders, and one answerer, you. In the preparation, an integer $K$ is told to all $N + M + 1$ players. $N + M$ number holders choose their own integers per person under the f...
[ { "submission_id": "aoj_2854_9088186", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntemplate<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }\ntemplate<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return...
aoj_2851_cpp
Low Range-Sum Matrix You received a card at a banquet. On the card, a matrix of $N$ rows and $M$ columns and two integers $K$ and $S$ are written. All the elements in the matrix are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is denoted by $A_{i,j}$. You can select up to ...
[ { "submission_id": "aoj_2851_10967569", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = int;\n// const ll INF = 1LL << 60;\n#define rep(i, a) for(ll i = 0; i < (a); i++)\n#define all(a) begin(a), end(a)\n#define sz(a) (a).size()\nbool chmin(auto &a, auto b) { return a > b ? a = b...
aoj_2853_cpp
Librarian's Work Japanese Animal Girl Library (JAG Library) is famous for a long bookshelf. It contains $N$ books numbered from $1$ to $N$ from left to right. The weight of the $i$-th book is $w_i$. One day, naughty Fox Jiro shuffled the order of the books on the shelf! The order has become a permutation $b_1, ..., b_N...
[ { "submission_id": "aoj_2853_10331822", "code_snippet": "// AOJ #2853 Librarian's Work\n// 2025.3.28\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 = 10*n + (c &...
aoj_2858_cpp
Prime-Factor Prime A positive integer is called a "prime-factor prime" when the number of its prime factors is prime. For example, $12$ is a prime-factor prime because the number of prime factors of $12 = 2 \times 2 \times 3$ is $3$, which is prime. On the other hand, $210$ is not a prime-factor prime because the numbe...
[ { "submission_id": "aoj_2858_10864995", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\n#include <chrono>\n#include <complex>\n#include <cmath>\n#include <unistd.h>\n#define pc_u putchar\n#pragma GCC target (\"avx\")\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\...
aoj_2860_cpp
Tree Separator You are given a tree $T$ and an integer $K$. You can choose arbitrary distinct two vertices $u$ and $v$ on $T$. Let $P$ be the simple path between $u$ and $v$. Then, remove vertices in $P$, and edges such that one or both of its end vertices is in $P$ from $T$. Your task is to choose $u$ and $v$ to maxim...
[ { "submission_id": "aoj_2860_10851151", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstring>\n#include<cstdlib>\nusing namespace std;\nint n,K,h[1001010],m1,g[1001010],f[1001010];\nint siz[1001010],ans;\nstruct edge{\n\tint next,to;\n\tedge(int next=0,int to=0):\n\tnext(next),to(to){}\n}...
aoj_2862_cpp
Coin Slider You are playing a coin puzzle. The rule of this puzzle is as follows: There are $N$ coins on a table. The $i$-th coin is a circle with $r_i$ radius, and its center is initially placed at ($sx_i, sy_i$). Each coin also has a target position: you should move the $i$-th coin so that its center is at ($tx_i, ty...
[ { "submission_id": "aoj_2862_10757127", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define vl vector<ll>\n#define rep(i, n) for (ll i = 0; i < n; ++i)\n#define eps 0.000000001\n\nstruct point {\n\tdouble x,y;\n};\n\n// p1-p2を通る直線上に、点pから引いた垂線の足を返す\npoint projectio...
aoj_2869_cpp
C: AA グラフ (AA Graph) Problem Given a graph as an ASCII Art (AA), please print the length of shortest paths from the vertex s to the vertex t . The AA of the graph satisfies the following constraints. A vertex is represented by an uppercase alphabet and symbols o in 8 neighbors as follows. ooo oAo ooo Horizontal edges a...
[ { "submission_id": "aoj_2869_2753520", "code_snippet": "#include <algorithm>\n#include <bitset>\n#include <climits>\n#include <cmath>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <ctime>\n#include <iostream>\n#include <list>\n#include <map>\n#include <numeric>\n#include <queue>\n#inc...
aoj_2863_cpp
Separate String You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$. For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \{a, ab, b\}$. $a,b,a,b$ $a,b,ab$ $ab,a,b$ $ab,ab$ Your task is to count the ...
[ { "submission_id": "aoj_2863_10852703", "code_snippet": "# include <cstdio>\n# include <iostream>\n# include <cstring>\n# include <string>\n# define R register int\n# define mod 1000000007\n\nusing namespace std;\n\nconst int maxn=200009;\nint n,cnt=1;\nchar c[100005];\nint ch[maxn][26],l;\nbool vis[maxn];\...
aoj_2859_cpp
Revenge of the Broken Door The JAG Kingdom consists of $N$ cities and $M$ bidirectional roads. The $i$-th road ($u_i, v_i, c_i$) connects the city $u_i$ and the city $v_i$ with the length $c_i$. One day, you, a citizen of the JAG Kingdom, decided to go to the city $T$ from the city $S$. However, you know that one of th...
[ { "submission_id": "aoj_2859_11054912", "code_snippet": "// #pragma GCC target(\"avx2\")\n#pragma GCC optimize(\"O3\")\n// #pragma GCC optimize(\"unroll-loops\")\n#include<bits/stdc++.h>\n// #include<sys/time.h>\n// #include<atcoder/modint>\n\nusing namespace std;\n\nconst int M = 998244353;\nconst long lon...
aoj_2867_cpp
A:沢山の種類の林檎 (Many Kinds of Apples) Problem Statement Apple Farmer Mon has two kinds of tasks: "harvest apples" and "ship apples". There are N different species of apples, and N distinguishable boxes. Apples are labeled by the species, and boxes are also labeled, from 1 to N . The i -th species of apples are stored in th...
[ { "submission_id": "aoj_2867_9822638", "code_snippet": "#include <bits/stdc++.h>\n\n\nusing namespace std;\n//make -f ../makefile SRC=\n/*\n*/\n\n\n//------------------------------------------------------------------------------\nbool DEBUG = false;\nconst int INF = 1000000000;\n\nconst int MAX_N = 1000+5;\...
aoj_2864_cpp
Revenge of the Endless BFS Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on a directed graph. An example of pseudo code of BFS is as follows: 1: $current \leftarrow \{start\_vertex\}$ 2: $visited \leftarrow current$ 3: while $visited \ne$...
[ { "submission_id": "aoj_2864_10852650", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\nll in()\n{\n ll re=0,f=1;char x=getchar();\n while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();}\n while(x>='0'&&x<='9')re=re*10+x-48,x=getchar();\n return re*f;\n}\nvoid o...
aoj_2865_cpp
Farm Village There is a village along a road. This village has $N$ houses numbered $1$ to $N$ in order along the road. Each house has a field that can make up to two units of the crop and needs just one unit of the crop. The total cost to distribute one unit of the crop to each house is the summation of carrying costs ...
[ { "submission_id": "aoj_2865_10946032", "code_snippet": "#include <iostream>\n#include <cstdlib>\n#include <cmath>\n#include <string>\n#include <cstring>\n#include <cstdio>\n#include <algorithm>\n#include <queue>\n#include <set>\n#include <map>\n#define re register\n#define max(a,b) ((a)>(b)?(a):(b))\n#defi...
aoj_2870_cpp
D: 素因数分解の多様性 (The Diversity of Prime Factorization) Problem Ebi-chan has the FACTORIZATION MACHINE, which can factorize natural numbers M (greater than 1) in O( $\log$ M) time! But unfortunately, the machine could display only digits and whitespaces. In general, we consider the factorization of M as p_1^{e_1} \times p...
[ { "submission_id": "aoj_2870_9598080", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n\nint pr[1000100];\n\nconst int mod = 1e9 + 7;\n\nint32_t main() {\n fill(pr, pr + 1000100, 1);\n\n for(int i = 2; i <= 1000000; i++) {\n if(!pr[i]) continue;\n ...
aoj_2871_cpp
E: Broccoli or Cauliflower Problem The input is a rooted tree T = (V, E) with n vertices. Note that n is odd and the vertex with index 1 is the root of T . In addition, we give a label G or W for each vertex. Let T_v = (U, F) be a subtree of T such that U is defined as following. U = $\{$ u \in V \ \ | \ \ u $\text{...
[ { "submission_id": "aoj_2871_10822766", "code_snippet": "#include<bits/stdc++.h>\n//#include <atcoder/all>\nusing namespace std;\n//using namespace atcoder;\n\n#define all(v) v.begin(),v.end()\nusing ll = long long;\nusing ull = unsigned long long;\nusing lll = __int128;\nusing vll=vector<ll>;\nusing vvll =...
aoj_2866_cpp
Conveyor Belt Awesome Conveyor Machine (ACM) is the most important equipment of a factory of Industrial Conveyor Product Corporation (ICPC). ACM has a long conveyor belt to deliver their products from some points to other points. You are a programmer hired to make efficient schedule plan for product delivery. ACM's con...
[ { "submission_id": "aoj_2866_10946031", "code_snippet": "#include <iostream>\n#include <cstdlib>\n#include <cmath>\n#include <string>\n#include <cstring>\n#include <cstdio>\n#include <algorithm>\n#include <queue>\n#include <set>\n#include <map>\n#define re register\n#define max(a,b) ((a)>(b)?(a):(b))\n#defi...
aoj_2872_cpp
F: 最短距離を伸ばすえびちゃん (Ebi-chan Lengthens Shortest Paths) Problem Ebi-chan loves directed graphs. One day, a directed graph with N vertices and M edges dropped from somewhere in front of Ebi-chan! The vertices and the edges of the graph is labeled with a number from 1 to N and from 1 to M , respectively. Moreover, the i th ...
[ { "submission_id": "aoj_2872_5870110", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\ntypedef long long ll;\nconst ll INF = (1LL << 60);\n\nstruct Edge {\n int rev, to, dis, cost;\n Edge(int r, int t, int d, int c) {\n rev = r;\n to = t;\n dis = d;\...
aoj_2873_cpp
G: 検閲により置換 (Censored String) Problem Statement You are given the string S , and the set of strings \mathcal P whose size is N . Now we consider applying the following operation to S : Choose exactly one character in S , and replace it with '*'. Let s_i be a i -th character of S , S_{ij} be a consecutive substring in S ...
[ { "submission_id": "aoj_2873_10649852", "code_snippet": "#line 1 \"a.cpp\"\n#define PROBLEM \"https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2873\"\n#line 2 \"string/Trie_Tree.hpp\"\n#include <vector>\n#include <array>\n#include <string>\n\nnamespace po167{\ntemplate<const int char_size,int base>...
aoj_2875_cpp
B: 写像 問題 AORイカちゃんは集合 $S = \{a_1, ..., a_N\}$ と写像 $f: S→S$を作った。$f(a_i) = b_i$ である。 集合 $S$ の任意の要素 $x$ について、$g(f(x)) = h(f(x))$ を満たす全ての写像 $g, h: S→S$ が、$g(x) = h(x)$ を満たすかどうか判定し、満たさない場合は反例を一つ構成せよ。 制約 $1 \le N \le 10^5$ $1 \le a_i,b_i \le N$ $a_i \neq a_j \ (i \neq j)$ 入力は全て整数 入力: $N$ $a_1 \cdots a_N$ $b_1 \cdots b_N$ 出力: ...
[ { "submission_id": "aoj_2875_9502245", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n\nint main() {\n cin.tie(nullptr);\n ios::sync_with_stdio(false);\n int n;\n cin >> n;\n vec...
aoj_2876_cpp
C: 一致 問題 長さ $N$ の数列 $a_i$ が与えられる。 次の条件を満たす整数 $K (1 \le K \le N)$ を全て出力せよ。 条件: $a_1, \cdots, a_K$ をうまく並び替えると $a_{N-K+1}, \cdots, a_N$ と一致する。 制約 $1 \le N \le 10^5$ $1 \le a_i \le 10^9$ 入力は全て整数 入力: $N$ $a_1 \cdots a_N$ 出力: 条件を満たす $K$ を昇順に空白区切りで出力せよ。また末尾に改行を出力せよ。 サンプル サンプル入力 1 8 5 2 4 9 4 9 2 5 サンプル出力 1 1 2 4 6 7 8 サンプル入力 ...
[ { "submission_id": "aoj_2876_10130585", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n\nmt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());\n\nconst int mod = 1e9 + 7;\n\nint32_t main() {\n\n int n; cin >> n;\n\n vector <int> v(n + 1);\n ...
aoj_2879_cpp
F: ごちうさ数 問題 ごちうさが大好きなAORイカちゃんは「ごちうさ数」を定義した。 ごちうさ数とは、 $10$ 進表記において「 $51?3$ 」を含む自然数のことである。 $?$ は $0$ 〜 $9$ のどの数字であってもよい。 $N$ 以下の自然数のうち、ごちうさ数の個数を求めよ。 制約 $1 \le N < 10^{18}$ 入力 $N$ 出力 ごちうさ数の個数を一行で出力せよ。また末尾に改行を出力せよ。 サンプル サンプル入力 1 5124 サンプル出力 1 3 $5124$ 以下のごちうさ数は、$5103$ , $5113$ , $5123$ の 三つである。 サンプル入力 2 60000 サンプル出力 2 160 ...
[ { "submission_id": "aoj_2879_10094491", "code_snippet": "#include <iostream>\n#include <vector>\n\nusing namespace std;\n\n\nint main() {\n string S; cin >> S;\n int N = S.size();\n\n // DP[i桁][下4桁][is_clear][is_less] := ごちうさ数の数\n // is_less -> 入力Sよりちいさいかどうか\n auto ok = [&](int n) {\n ...
aoj_2877_cpp
D: 水槽 問題 AORイカちゃんは縦 $1$ 横 $N$ の大きさの水槽をもらった。水槽は水を入れるのに十分な高さがある。 水槽には $N-1$ 個の仕切りがあり $N$ 個の区画に等間隔に区切られている。 ここに水を注いだところ、各区画の水の高さは $a_i$ になった。 AORイカちゃんはいくつか仕切りを取り除き、区画の数を $M$ 個以下にすることにした。 仕切りを取り除き終わった時、各区画の水の高さの総和の最大値を求めよ。 なお、仕切りの厚さは無視できるものとする。 制約 $1 \le N \le 500$ $1 \le M \le N$ $1 \le a_i \le 10^9$ 入力は全て整数 入力 $N \ M$ $a...
[ { "submission_id": "aoj_2877_10807024", "code_snippet": "#include <bits/stdc++.h>\n//#include <atcoder/all>\n#include <iomanip>\nusing namespace std;\n//using namespace atcoder;\nusing ll = long long;\nusing pint = pair<int, int>;\n//using mint = modint998244353;\ntemplate<typename T>\nusing min_priority_qu...
aoj_2880_cpp
G: エレベータ 問題 株式会社AORは $N$ 階建てのビルである。地下階は存在しない。 AORイカちゃんはイカであるため、階段を下りることは可能だが、上ることは不可能である。 上の階に登れないと不便なため、$M$ 個のエレベータをビルに設置することにした。 エレベータを設置するには時間がかかり、$i$ 番目のエレベータは $D_i$ 日後の夜に設置が完了し、 $A_i$ 階以上 $B_i$ 階以下の全ての階を移動可能にする。 あなたはAORイカちゃんに $Q$ 個の質問をされた。$i$ 番目の質問は「 $E_i$ 日後の昼に、$S_i$ 階から $T_i$ 階に移動可能か?」という質問である。 移動に使える手段は階段とエレベータ...
[ { "submission_id": "aoj_2880_10422516", "code_snippet": "//\n// 区間 (と値) を Set で管理する構造体\n//\n// verified\n// 第六回 アルゴリズム実技検定 M - 等しい数 (for update)\n// https://atcoder.jp/contests/past202104-open/tasks/past202104_m\n//\n// RUPC 2018 G - Elevator (for insert, same)\n// https://onlinejudge.u-aizu.ac....
aoj_2878_cpp
E: いたずらされたグラフ 問題 あなたはグラフのアルゴリズムとして典型であるフローの問題を解いていた。 その問題で与えられるグラフは、頂点 $N$ 個、辺 $M$ 本であり、頂点 $x_i$ から 頂点 $y_i$ に容量 $z_i$ 、コスト $d_i$ の辺が張られている。 ところが、AORイカちゃんが入力ケースにいたずらした。 その結果、 $x_i, y_i, z_i$ の順序がシャッフルされ、頂点の情報と容量の情報が区別できなくなってしまった。 そこで、あなたは $s-t$ 間のフローを求めることを諦め、 $s-t$ 間の最短距離を求めることにした。 あなたは、 $x_i, y_i, z_i$ の順序がシャッフルされた入力...
[ { "submission_id": "aoj_2878_10042154", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <iomanip>\n#include <queue>\nusing namespace std;\ntypedef long long ll;\n// const ll INF64 = 1LL << 60;\nconst ll INF64 = ((1LL<<62)-(1LL<<31)); // 10^18より大きく、か...
aoj_2882_cpp
一般化うるう年 通常,西暦 x 年がうるう年か否かは以下のように定義されている. x が 400 の倍数であれば,うるう年である. そうでないとき, x が 100 の倍数であれば,うるう年ではない. そうでないとき, x が 4 の倍数であれば,うるう年である. そうでないとき,うるう年ではない. これは次のように一般化できる.ある数列 A 1 , ..., A n について,西暦 x 年が "一般化うるう年" であるか否かを以下のように定義する. x が A i の倍数であるような最小の i ( 1 ≤ i ≤ n ) について, i が奇数であれば一般化うるう年であり,偶数であれば一般化うるう年ではない. そのような i が存...
[ { "submission_id": "aoj_2882_10670963", "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_2888_cpp
NINJA GAME 新作ゲーム "NIN JA G AME" がついに発売となった.このゲームではプレイヤーは二次元マップ上の忍者を操作して移動を行う.二次元マップは x 軸,または y 軸のどちらか一方に平行な辺のみからなる,自己交差のない多角形で表される.いま,多角形の内部に存在するスタート地点からゴール地点へと移動する必要がある. 移動は上下左右と斜め45°の8方向が可能で,いずれかの対応するコマンドを入力すると,指定した方向に自動で進み続ける.この自動移動の最中の任意のタイミングで別のコマンドを入力した場合,即座に移動方向の転換が可能である.あなたの目標は,このゲームでの実績を解除するため,最小のコマンド入力回数でスタート...
[ { "submission_id": "aoj_2888_6014512", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define BIG_NUM 2000000000\n#define HUGE_NUM 4000000000000000000 //オーバーフローに注意\n#define MOD 1000000007\n#define EPS 0.000000001\n\n\n\n\n#defi...
aoj_2884_cpp
短歌数 願はくは 花の下にて 春死なむ そのきさらぎの 望月のころ これは,西行法師が詠んだとされる,有名な短歌の一つである. 短歌は,日本において古くから親しまれている和歌の一種であり,その多くは 5・7・5・7・7 の五句三十一音からなる. ところで,57577 という数は,5 と 7 の二種類の数字からなる. このような,十進表記がちょうど二種類の数字からなる正の整数を,短歌数と呼ぶことにする. 例えば,10, 12, 57577, 25252 などは短歌数であるが,5, 11, 123, 20180701 などは短歌数ではない. 正の整数 N が与えられる. N 番目に小さい短歌数を求めよ. Input 入力は最大で 100...
[ { "submission_id": "aoj_2884_10946030", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst ll INF = (ll)1e9 * (ll)1e9 + 100;\n\nll calc(const vector<int>& v) {\n\tint d = v.size();\n\tll dp[d + 1][10][10][4][2] = {};\n\tfor (int i = 0; i < 10; i++) {\n\t\tfor (in...
aoj_2883_cpp
知識の証明 あなたが住んでいる集合住宅の入口のドアには,パスワード式のロックがかけられている.このパスワードはちょうど 4 桁の 0 から 9 の範囲の数字で構成されており,あなたはいつも,集合住宅の管理人から伝えられたパスワード P を使って,このドアのロックを解除している. ある日,あなたは集合住宅の住民全員が,自分と同じパスワード P を使っているのかどうか気になり,同じ集合住宅に住む友人に尋ねることにした.あなたとあなたの友人は,自分のパスワードを互いに伝えあうことで,同じパスワードを使っているのかどうか確かめ合うことができる.しかしながら,パスワードがそれぞれの住民に個別に割り当てられている可能性を考えると,この方法は好ま...
[ { "submission_id": "aoj_2883_10881168", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing ll = long long;\n\n// clang-format off\n\nint letter(const string& s, int& r, const string& psw) {\n ++r;\n int idx = s[r-1] - 'a';\n return psw[idx] - '0';\n}\n\nint hsh(const string& s...
aoj_2885_cpp
分割統治 太郎さんと花子さんと次郎さんは3人で JAG 王国を統治している.JAG 王国には N 個の街が存在し,いくつかの街は双方向の道路で繋がっている.どの街からも別のすべての街へ 1 本以上の道路を経由して必ず辿り着くことができる. ある日太郎さんと花子さんはとうとう仲違いを起こしてしまい,3 人で街を分担して統治することに決めた.しかし,あまりにも仲が悪くなりすぎてしまったため,太郎さんが統治している街と花子さんが統治している街が 1 本の道路で直接繋がっていることすら嫌がっている.そこで,以下の条件を満たすように統治する街を分担することにした. 太郎さんが統治する街と花子さんが統治する街からなる任意のペアは,直接道路で繋が...
[ { "submission_id": "aoj_2885_10687055", "code_snippet": "//#define _GLIBCXX_DEBUG\n\n#include <iostream>\n#include <vector>\n#include <queue>\n#include <climits>\n#include <algorithm>\n#include <map>\n#include <set>\n#include <iterator>\n#include <unordered_map>\n#include <stack>\n#include <string>\n#includ...
aoj_2890_cpp
B: ピボット (Pivots) 問題 1 から N までの整数を並び変えた、長さ N の順列 a_1, a_2, ..., a_N が与えられる。 また、この順列に対して Q 個のクエリが順に与えられる。 i 番目のクエリでは次の操作をしなければならない。 値 q_i ( 1 \leq q_i \leq N ) が与えられる。順列 \{a_1, a_2, ..., a_N\} において q_i の左側の順列を L 、 q_i の右側の順列を R としたとき、元の順列 L \ \ q_i \ \ R を R \ \ q_i \ \ L に変更する。つまり、 q_{i} = a_j であるとき、順列 \{a_1, ..., ...
[ { "submission_id": "aoj_2890_8396278", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint N, A[1 << 19], NexA[1 << 19], Place[1 << 19], Next[1 << 19];\nint Q, B[1 << 19];\n\nvoid Query(int cl, int cr) {\n // Set Candidate\n vector<int> vec;\n vec.push_back(1);\n for (int i = ...
aoj_2886_cpp
対空シールド 時は3xxx年,太陽系外の惑星に進出した人類は,大量の隕石の飛来による基地の被害で頭を悩ませていた.国際宇宙防護会社(International Cosmic Protection Company)は,この問題を解決するために新たな対空シールドを開発した. 防護対象の基地は同じサイズの N 個のユニットが一直線上に等間隔で並んだ形をしており, 1 から N までの番号が順に付けられている.ICPCは,これらのユニットに,合計で M 個のシールドを設置することにした. i 番目のシールドが能力 a i を持ち,ユニット x i に設置されているとする.このとき,あるユニット u における強度は,以下の式で表される. Σ ...
[ { "submission_id": "aoj_2886_10674447", "code_snippet": "#include <bits/stdc++.h>\n#include <stdlib.h>\nusing namespace std;\n#define rep(i, a, n) for(ll i = a; i < n; i++)\n#define ll long long\ntemplate<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}\ntemplate<class t,class u> void chmin(t&a,u b){if(b<a...
aoj_2887_cpp
カジノ あなたの勤めている会社では新たなカジノゲームの開発をしている.今日は最近提案されたゲームについて考察してみることにした. このゲームでは N 個のサイコロを同時に振って,出た目の合計が得点となる.プレイヤーは得点を大きくすることを目標としてプレーする.もし出た目が気に入らなければサイコロを振り直すことができるが,その時は N 個のサイコロ全てを同時に振り直さなければならない.また,サイコロを振ることのできる回数は最大で M 回である.十分に大きい目が出たと思ったのであれば, M 回より少ない回数でゲームを終えても良く,最後に振ったサイコロの目の合計が得点となる. 適切な賭け金を設定するためには,得点の期待値を求めなければなら...
[ { "submission_id": "aoj_2887_10594234", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i,n) for(int i=0;i<(n);i++)\nusing namespace std;\n#define all(a) a.begin(),a.end()\n#define compress(a) sort(all(a));a.erase(unique(all(a)),a.end())\ntypedef long long ll;\ntypedef pair<ll,ll> P;\nconstexpr ll mo...
aoj_2892_cpp
D: しりとり圧縮 (Shiritori Compression) 問題 えびちゃんとかにちゃんの二人はしりとりをしました。えびちゃんはしりとりで出た単語のメモを見ています。 えびちゃんは、この単語列 w_1 , w_2 , ... , w_N から冗長な連続部分列を、存在しなくなるまで取り除きたいと思っています。えびちゃんの思う冗長な連続部分列とは以下のように定義されます。 以下を満たす i , j が存在したとき、連続部分列 w_i , ... , w_{j-1} は冗長です。 i < j なる添字 i , j について、単語 w_i と w_j の先頭の文字が等しい。 このとき、えびちゃんは添字 i 以上 j-1 以下の単語を...
[ { "submission_id": "aoj_2892_8396405", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint N;\nint dp1[200009][27];\nint dp2[200009][27];\nint Letter[200009];\nstring S[200009];\n\nint main() {\n // Step 1. Input\n cin >> N;\n for (int i = 1; i <= N; i++) cin >> S[i];\n for (i...
aoj_2894_cpp
F: 01 文字列と窓 (Binary String with Slit) 問題 文字の種類が 0 と 1 のみからなる文字列 S が与えられます。以下の操作を繰り返すことで、 S を T に変えたいです。 文字列 S 中の最も右側に登場する 1 を含むように、幅 2 のスリットを置く。スリット内には連続した 2 文字を必ず含まなければならない。つまり、文字列の端 1 文字のみを含むように置くことはできない。 2 通り置ける場合も考えられるが、この場合はどちらの方法で置いても構わない。 スリット中の 2 文字を 2 桁の二進数と捉えるとき、元の数値との差の絶対値が 1 になるようにスリット中の文字を変更する。ただし、スリット中の文字...
[ { "submission_id": "aoj_2894_8396566", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint solve(string S, string T) {\n if (S == T) return 0;\n int idx1 = -1;\n int idx2 = -1;\n for (int i = 0; i < (int)S.size(); i++) {\n if (S[i] == '1' && T[i] == '1') idx1 = i;\n ...
aoj_2891_cpp
C: な◯りカット (Namo.. Cut) 問題 -謎の巨大クラゲ、 コードネーム「な◯り」を討伐せよ- 「な◯り」は非常に生命力が強いため、素早く切断し続けなければ、あっという間に復活してしまう。 我々は、「な◯り」をどのように切断するのが効率良いのか、日々試行錯誤している。 その過程で、あなた方プログラマの手が必要になった。 「な◯り」は N 頂点と N 辺からなる連結な無向グラフで表現できる。 以降、各頂点が 1 から N の異なる数で名前付けられているとしよう。 我々は、「な◯り」に関して Q 回の質問を行う。 それらすべてに答えるプログラムを作成して欲しい。 質問は 1 から Q の番号を持ち、各質問は次のように構成され...
[ { "submission_id": "aoj_2891_10994311", "code_snippet": "#include <iostream>\n#include <vector>\n#include <stack>\n#include <set>\n\nusing namespace std;\n\nvector<vector<int>> G;\nvector<int> seen;\nvector<int> finished;\nstack<int> cycle;\n\n\nint DFS(int now, int parent, int cycleIndex){\n seen[now] =...
aoj_2895_cpp
G: 回文部分列 (Palindromic Subsequences) 問題 英小文字のみからなる文字列 S が与えられるので、この文字列 S の 連続とは限らない 部分列であって、回文であるものは何種類あるかを求めてください。 ここで、 S の連続とは限らない部分列とは、元の文字列 S から 1 文字以上 |S| 文字以下を任意に選択し (選択するそれぞれの文字の位置は非連続でも良い)、それらを元の順番通りに連結させてできた文字列のことを指します。この問題において、空文字列は部分列として認められないことに注意してください。 また、文字列 X が回文であるとは、元の文字列 X と、 X を反転した文字列 X’ が等しいことを指します...
[ { "submission_id": "aoj_2895_10823891", "code_snippet": "#include<bits/stdc++.h>\n// #include<atcoder/all>\nusing namespace std;\n// using namespace atcoder;\n\nusing ll=long long;\nusing ld=long double;\nusing pl=pair<ll,ll>;\nusing vpl=vector<pl>;\nusing vl=vector<ll>;\nusing vvl=vector<vl>;\n\nlong doubl...
aoj_2901_cpp
F: Swap 問題 長さ $N$ の文字列 $S,\ T$ が与えられます.$S,\ T$ はそれぞれ 'o' , '.' の二種類の文字だけで構成されています. あなたは $S$ に対して,以下の操作を行うことができます. 以下の条件を全て満たす整数対 $(l, r)$ を選択する.その後,$S[l]$ と $S[l + 1],S[r - 1]$ と $S[r]$ をそれぞれスワップする. $1 \leq l, r \leq N$ $r - l \geq 3$ $S[l] = S[r] =$ '.' $S[l + 1] = S[l + 2] = \dots = S[r - 1] =$ 'o' 何回か操作を繰り返したあと(0...
[ { "submission_id": "aoj_2901_9498540", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n\nint main() {\n cin.tie(nullptr);\n ios::sync_with_stdio(false);\n int n;\n cin >> n;\n str...
aoj_2899_cpp
D: 遭難 問題 $H * W$ のグリッドで表される地図が与えられる。 各マスは '#' か '.' であり、前者は陸地であることを、後者は海であることを示している。 以下のように上下左右に隣接している陸地の集合を島と呼ぶ。 ..... .###. ..##. ..#.. ..... 陸地 $6$ マスの島。 ...... .##.#. ....#. ...... 陸地 $2$ マスの島が $2$ つ。 与えられる地図は、以下の条件を満たす。 地図の端 $1$ マスは必ず '.' である。 同じ形の島が二つ以上存在することはない。 つまり、島に含まれる陸地のうち、最も上にあり、その中で最も左にある陸地を基準とした陸地の座標集合...
[ { "submission_id": "aoj_2899_10539358", "code_snippet": "// AOJ #2899 Accident\n// 2025.5.29\n\n#include <bits/stdc++.h>\nusing namespace std;\nconst uint64_t BASE = 1000003;\n\nint main(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n int H,W;\n cin>>H>>W;\n vector<string> G(H);\n for(int ...
aoj_2898_cpp
C: 素数 問題 ある日、素数が大好きなそすうさ君は $p + q$ が素数となるペア $(p, q)$ で遊んでいた。 そすうさ君は突然、このペアのうち、 $p$ と $q$ がともに $N$ 以下の素数であるペアがいくつあるか気になりだした。 そすうさ君に代わって個数を求めよ。 制約 入力値は全て整数である。 $1 \leq N \leq 10^7$ 入力形式 入力は以下の形式で与えられる。 $N$ 出力 ペアの個数を出力せよ。また、末尾に改行も出力せよ。 サンプル サンプル入力 1 3 サンプル出力 1 2 ペアは $(2, 3), (3, 2)$ の二つである。 サンプル入力 2 20 サンプル出力 2 8
[ { "submission_id": "aoj_2898_10760317", "code_snippet": "#include<bits/stdc++.h>\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define BIG_NUM 2000000000\n#define HUGE_NUM 99999999999999999\n#define MOD 1000000007\n#define EPS 0.000000001\nusing namespace std;\n\n\n#define NUM 10000005\nb...
aoj_2900_cpp
E: 凸凹数列 問題 長さ $N$ の数列 $A$ が与えられる。$A$ の $i$ 項目 は $A_i$ である。 あなたは、この数列に対して以下の操作を行うことができる。 $1 \leq i \leq N - 1$ なる整数 i を選ぶ。 $A_i$ の値と $A_{i + 1}$ の値を入れ替える。 $A$ を凸凹数列にするために必要な操作の最小回数を求めよ。 以下の条件を満たす長さ $N$ の数列を凸凹数列と定義する。 $1 < i < N$ を満たす任意の $i$ について、 $A_{i + 1}, A_{i - 1} > A_i$ または $A_{i + 1}, A_{i - 1} < A_i$ を満たす。 直感的に...
[ { "submission_id": "aoj_2900_9895400", "code_snippet": "#include <bits/stdc++.h>\n\nbool check(std::vector<int> &a, int i) {\n if (i <= 0 || i >= a.size() - 1) return true;\n return (a[i - 1] > a[i] && a[i] < a[i + 1]) || (a[i - 1] < a[i] && a[i] > a[i + 1]);\n}\n\nsigned main() {\n int n;\n std...
aoj_2893_cpp
E: 均衡な辺削除 (Balanced Edge Deletion) 問題 N 頂点 M 辺の重み付き単純無向グラフ G が与えられる。 頂点には 1 から N 、 辺には 1 から M の番号がつけられている。 i 番目の辺は頂点 u_i と v_i を結んでおり、そのコストは w_i である。 このグラフに対して、以下の操作を 1 度だけ行うことを考える。 G の辺集合から辺を 1 つ選択し、その辺を削除する。 上の操作によってグラフが分割されることがあるので、操作後のグラフを A , B と表記することとする。(分割されない場合、 B は空グラフであるとする。) W(X) をグラフ X 内にある辺のコストの総和 (グラフに辺が...
[ { "submission_id": "aoj_2893_10539247", "code_snippet": "// AOJ #2893 Balanced Edge Deletion\n// 2025.5.29\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 = 10*n ...
aoj_2905_cpp
Problem B. Colorful Drink In the Jambo Amusement Garden (JAG), you sell colorful drinks consisting of multiple color layers. This colorful drink can be made by pouring multiple colored liquids of different density from the bottom in order. You have already prepared several colored liquids with various colors and densit...
[ { "submission_id": "aoj_2905_11016267", "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_2906_cpp
Problem C. Santa's Gift Santa is going to pack gifts into a bag for a family. There are $N$ kinds of gifts. The size and the price of the $i$-th gift ($1 \leq i \leq N$) are $s_i$ and $p_i$, respectively. The size of the bag is $C$, thus Santa can pack gifts so that the total size of the gifts does not exceed $C$. Chil...
[ { "submission_id": "aoj_2906_11016354", "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_2902_cpp
G: 式の切り取り 問題 長さ $N$ の数式 $S$ が与えられる。 数式は、以下の BNF で示される形式になっている。 <expr> ::= <number> | <expr> <op> <expr> <op> ::= ‘^’ | ‘&’ | ‘|’ <number> は、 $0$ 以上 $2^{31}-1$ 以下の整数を表す。 演算子、’^’ ‘&’ ‘|’ は、それぞれ排他的論理和、論理積、論理和を表す。 演算子の優先順位は以下の通りである。 高 ’^’ > ‘&’ > ‘|’ 低 区間 $[i, j]$ が $Q$ 個与えられる。 $S_i, \dots , S_j$ の計算結果を出力せよ。 なお、数式...
[ { "submission_id": "aoj_2902_4956152", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll;\nconst ll INF = 1e18;\n\ntemplate <typename T>\nbool chmin(T &a, T b) {\n if(a > b) {\n a = b;\n return true;\n }\n return false;\n}\n\ntemplate <typename T>...
aoj_2907_cpp
Problem D. Prefix Suffix Search As an English learner, sometimes you cannot remember the entire spelling of English words perfectly, but you can only remember their prefixes and suffixes. For example, you may want to use a word which begins with ' appr ' and ends with ' iate ', but forget the middle part of the word. I...
[ { "submission_id": "aoj_2907_10946024", "code_snippet": "#include <bits/stdc++.h>\n \n#pragma GCC optimize(\"O2\")\nusing namespace std;\n#define ll long long\n#define ull unsigned long long\n#define rep(i,n,N) for(ll i=n;i<=N;++i)\n#define rap(i,n,N) for(ll i=n;i>=N;--i)\n#define mp make_pair\n#define pb p...
aoj_2909_cpp
Problem F. Nim without Zero Alice: "Hi, Bob! Let's play Nim!" Bob: "Are you serious? I don't want to play it. I know how to win the game." Alice: "Right, there is an algorithm to calculate the optimal move using XOR. How about changing the rule so that a player loses a game if he or she makes the XOR to $0$?" Bob: "It ...
[ { "submission_id": "aoj_2909_10853891", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define vl vector<ll>\n#define rep(i, n) for (ll i = 0; i < n; ++i)\n\nint main() {\n ll n;\n\tcin>>n;\n\tvl a(n);\n\tll xr=0;\n\trep(i,n){\n\t\tcin>>a[i];\n\t\txr^=a[i];\n\t}\n...
aoj_2908_cpp
Problem E. Magic Triangles Fallen angel Yohane plans to draw a magic symbol composed of triangles on the earth. By casting some magic spell on the symbol, she will obtain magic power; this is the purpose for which she will draw a magic symbol. The magic power yielded from the magic symbol is determined only by the comm...
[ { "submission_id": "aoj_2908_10937906", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#if __has_include(<atcoder/all>)\n#include <atcoder/all>\nusing namespace atcoder;\n#endif\n#ifndef ONLINE_JUDGE\n#define _GLIBCXX_DEBUG\n#include <iostream>\ntemplate <typename T, typename U>\nostream& ...
aoj_2911_cpp
Problem H. Enlarge Circles You are given $N$ distinct points on the 2-D plane. For each point, you are going to make a single circle whose center is located at the point. Your task is to maximize the sum of perimeters of these $N$ circles so that circles do not overlap each other. Here, "overlap" means that two circles...
[ { "submission_id": "aoj_2911_10866213", "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_2910_cpp
Problem G. Additions You are given an integer $N$ and a string consisting of ' + ' and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to $N$ by modifying some characters. Here, you replace one character with another character any number of times, and...
[ { "submission_id": "aoj_2910_10855445", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < n; ++i)\n#define loop(i ,m, n) for (ll i = m; i <= n; ++i)\n#define pll pair<ll,ll>\n#define vl vector<ll>\n#define vvl vector<vl>\n#define inf...
aoj_2914_cpp
Problem K. Rough Sorting For skilled programmers, it is very easy to implement a sorting function. Moreover, they often avoid full sorting to reduce computation time if it is not necessary. Here, we consider "rough sorting" which sorts an array except for some pairs of elements. More formally, we define an array is "$K...
[ { "submission_id": "aoj_2914_10854524", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < n; ++i)\n#define pll pair<ll,ll>\n#define vl vector<ll>\n#define inf 100000000000000000LL\n\nll inversion_number(vl & v){\n int n = v.size()...
aoj_2912_cpp
Problem I. Sum of QQ You received a card with an integer $S$ and a multiplication table of infinite size. All the elements in the table are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is $A_{i,j} = i \times j$ ($i,j \geq 1$). The table has infinite size, i.e., the number ...
[ { "submission_id": "aoj_2912_11016364", "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_2923_cpp
I: 破壊 (Ravage) サンタクロースは、街のイルミネーションに引っかかり、壊した。 イルミネーションにはN個の電球があり、$i$ 番目の電球は電圧が $A_i$ 以上 $B_i$ 以下のときにしか付かなくなってしまった。 電圧はイルミネーションのどこでも同じにする必要がある。 電圧を調節することで、最大いくつの電球を同時に光らせることができるか求めよ。 入力 1 行目には整数 $N$ が与えられる。 続く $N$ 行のうち $i$ 行目には $A_i, B_i$ が空白区切りで与えられる。 出力 同時に光らせることができる電球の個数の最大値を出力せよ。 制約 $N$ は $1$ 以上 $100 \ 000$ 以下の整数 $A...
[ { "submission_id": "aoj_2923_9604988", "code_snippet": "#include <bits/stdc++.h>\n\n\nusing namespace std;\n//make -f ../makefile SRC=\n/*\n*/\n\n\n//------------------------------------------------------------------------------\nbool DEBUG = false;\nconst int UNKNOWN = -1;\nconst int START = 0; \nconst int...
aoj_2922_cpp
H: 慈悲 (Mercy) サンタクロースは、クリスマスなのにプログラミングをやっている集団を見つけた。 サンタクロースは彼らを可哀想に思ったので、ケーキをプレゼントすることにした。 クリームが $N$ 種類あって、美味しさは $A_1, A_2, A_3, \dots, A_N$ である。 スポンジが $M$ 種類あって、美味しさは $B_1, B_2, B_3, \dots, B_M$ である。 クリーム 1 種類とスポンジ 1 種類を組み合わせてケーキを作り、その美味しさは (クリームの美味しさ) × (スポンジの美味しさ) になる。 サンタクロースは慈悲深いので、$N \times M$ 通りの組み合わせのケーキをすべて一つ...
[ { "submission_id": "aoj_2922_5968462", "code_snippet": "#include <iostream>\nusing namespace std;\nint main(){\n int n,m;cin>>n>>m;\n long long a = 0,b = 0;\n for(int i = 0; n > i; i++){\n long long t;cin>>t;\n a += t;\n }\n for(int i = 0; m > i; i++){\n long long t;cin>>...
aoj_2925_cpp
K: 救済 (Angel Relief) 天使の天真さんは、ある街を救うことにした。 この街は南北 $H$ 区画 × 東西 $W$ 区画に分けられた長方形の形をしており、各区画に家がある。 北から数えて $X$ 番目、西から数えて $Y$ 番目の区画を $(X, Y)$ で表す。 区画 $(i, j)$ にある家には $A_{i, j}$ 人の人が住んでいる。 天真さんは、辺が南北または東西に平行または垂直な長方形のエリアを選び、その中に住んでいる人全員を ひとりずつ 救済する。 天真さんは、考えられるすべての長方形でこの操作を行う。 天真さんが人を救済する回数の合計を求めよ。 入力 1 行目に、整数 $H, W$ が空白区切りで与...
[ { "submission_id": "aoj_2925_9604887", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n//make -f ../makefile SRC=\n\n/*\n3X4 grid consists of 4 horizontal lines and 5 vertical ones\nno. of rects = comb(4,2) * comb(5,2) = 6 * 10 = 60\n\n*/\n\n\n//-----------------------------------------...
aoj_2926_cpp
L: スギ (Demon's Cedar) 月の瀬さんは悪魔らしいことをするため、街じゅうの樹木をスギの木に変えて、人々を花粉症で困らせることにした。 樹木は $N$ 種類存在する。$i$ 種類目の樹木の天界でのランクは $A_i$、魔界でのランクは $B_i$ である。また、$1$ 種類目の樹木はスギである。 月の瀬さんは、次の操作を何度でも行うことができる。 天界で、種類 $i$ の樹木を種類 $j$ に変える。これには $|A_i - A_j|$ の時間がかかる。 魔界で、種類 $i$ の樹木を種類 $j$ に変える。これには $|B_i - B_j|$ の時間がかかる。 天界と魔界の移動や、その他の行動に時間はかからない。 ...
[ { "submission_id": "aoj_2926_7084569", "code_snippet": "#include <bits/stdc++.h>\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nusing std::cout;\nusing std::cin;\nusing std::endl;\nusing ll=long long;\nusing ld=long double;\nll ILL=2167167167167167167;\nconst int INF=2100000000;\nconst ll mod=1e9+7...
aoj_2927_cpp
M: プレゼント (Presents) 白羽さんは、とある悪魔にサプライズプレゼントとして次のような集合を用意した。 $N$ 以下の異なる $K$ 個の自然数からなる どの 2 つの値の組を集合から選んでも、片方の数がもう片方の数で割り切れる 実はこのような集合には悪魔の力を奪う性質があり、このままだと力を失ってしまう。 悪魔を助けるために、このような集合がいくつあるか計算せよ。 入力 2 つの整数 $N, K$ が空白区切りで与えられる。 出力 条件を満たす集合の個数を出力せよ。 制約 $N$ は $1$ 以上 $100 \ 000$ 以下の整数 $K$ は $1$ 以上 $N$ 以下の整数 入力例1 6 3 出力例1 3 集合 ...
[ { "submission_id": "aoj_2927_9604845", "code_snippet": "#include <bits/stdc++.h>\n\n/*\n*/\n\nusing namespace std;\n//make -f ../makefile SRC=\n\n\n/*\nTODO: top down dp\n*/\n\n//------------------------------------------------------------------------------\nbool DEBUG = false;\n\nconst int64_t MOD = 100000...
aoj_2913_cpp
Problem J. Prime Routing Fox Jiro is one of the staffs of the ACM-ICPC 2018 Asia Yokohama Regional Contest and is responsible for designing the network for the venue of the contest. His network consists of $N$ computers, which are connected by $M$ cables. The $i$-th cable connects the $a_i$-th computer and the $b_i$-th...
[ { "submission_id": "aoj_2913_11016933", "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_2928_cpp
N: 通販 (Mail Order) 胡桃沢さんは、魔界通販で積み木のおもちゃを買った。 積み木は一辺の長さが1の立方体の形をしており、縦に $H$ 個、横に $W$ 個に分割されたマス目の上に積まれている。 真横から見ると、左から順に、$A_1, A_2, A_3, \dots, A_H$ 個のブロックが積まれて見えた。 正面から見ると、左から順に、$B_1, B_2, B_3, \dots, B_W$ 個のブロックが積まれて見えた。 胡桃沢さんは偉大なので、これらの情報だけからブロックの総数を当てようと考えた。 小さい数を答えて間違えると格好悪いので、考えられる最大の個数を答えたい。 入力 1 行目には整数 $H, W$ が空白...
[ { "submission_id": "aoj_2928_7084580", "code_snippet": "#include <bits/stdc++.h>\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nusing std::cout;\nusing std::cin;\nusing std::endl;\nusing ll=long long;\nusing ld=long double;\nll ILL=2167167167167167167;\nconst int INF=2100000000;\nconst ll mod=1e9+7...
aoj_2929_cpp
O: 千咲ちゃんと遠足 (Chisaki and Picnic) 幼稚園生の千咲ちゃんは、遠足にお菓子をもっていくことにした。 お菓子は $N$ 個あって、$i$ 番目のお菓子は値段が $A_i$ 円で、美味しさが $B_i$ である。 千咲ちゃんには友達が $M$ 人いて、$j$ 番目の友達は、値段が $C_j$ 円以上のお菓子を $D_j$ 個以上千咲ちゃんがもっていると泣きわめく。 友達が泣きわめいてしまうと千咲ちゃんはかなしいので、そうならないようにお菓子をもっていきたい。 お菓子の美味しさの合計は最大でいくつになるか求めて、千咲ちゃんを助けなさい。 入力 1 行目には、お菓子の個数 $N$ と、友達の人数 $M$ が空白区...
[ { "submission_id": "aoj_2929_7084595", "code_snippet": "#include <bits/stdc++.h>\n#pragma GCC optimize(\"Ofast\")\nusing namespace std;\nusing std::cout;\nusing std::cin;\nusing std::endl;\nusing ll=long long;\nusing ld=long double;\nll ILL=2167167167167167167;\nconst int INF=2100000000;\nconst ll mod=1e9+7...
aoj_2932_cpp
C: 約数ゲーム / Divisor Game 問題 tsutaj くんは約数ゲームで遊ぼうとしています。 約数ゲームでは、まず 2 以上の自然数 N が与えられ、その後は以下の手順でゲームが進んでいきます。 N 以外の N の約数の中から、整数を 1 つ宣言する。ただしこのとき、既に宣言したことがある整数の約数になるものは宣言できない。 宣言できる整数がある限りこれを繰り返し、宣言できるものがなければゲームは終了する。 ゲームを終了させるまでに行われた宣言の回数としてあり得る数の最小値と最大値を求めてください。 入力形式 入力は 1 行で与えられる。 N 制約 2 \leq N \leq 10^{12} 出力形式 宣言回数の最小値...
[ { "submission_id": "aoj_2932_5640051", "code_snippet": "#include<iostream>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nusing ll=long long;\n\nint main(){\n ll n;cin>>n;ll num=n;\n ll ans=0;ll p=0;\n for(ll j=2;j*j<=n;j++){\n if(num%j==0){\n while(num%j==0&&num>0){\n\tnum/=j;\n ...
aoj_2931_cpp
B: 括弧を語る数 / Parentheses Number 問題 以下のように 正しい括弧列 を定めます。 空文字列は正しい括弧列である 正しい括弧列 S に対して ( S ) は正しい括弧列である 正しい括弧列 S , T に対して ST は正しい括弧列である ここで、正しい括弧列に対して以下のような規則で順列を対応付けます。 i 番目の 閉じ括弧 が j 番目の 開き括弧 に対応しているとき、 数列の i 番目の値は j である。 長さ n の順列 P = ( p_1, p_2, $\ldots$ , p_n ) が与えられるので、 それに対応する括弧列を復元してください。 ただし、順列に対応する括弧列が存在しない場合は :(...
[ { "submission_id": "aoj_2931_9644399", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n int n;\n cin >> n;\n vector<int> p(n);\n for (int i = 0; i < n; ++i) {\n cin >> p[i];\n --p[i]; // Convert to 0-based index\n }\n\n stack<int> s;\n strin...
aoj_2930_cpp
A: 情報検索 / Information Search 問題 ポスティングリストとは、検索語と出現文書 ID の対応関係を持たせたリストである。例えば 北海道: 1, 2, 4, 9 観光: 1, 3, 4, 7 などである。 上記のポスティングリストから、and 検索をすると、ID 1, 4 の文書がヒットし、or 検索をすると、ID 1, 2, 3, 4, 7, 9 がヒットする。 ここで and 検索とは「どちらのリストにも含まれる要素を列挙する」ことであり、 or 検索とは「少なくともどちらか一方のリストに含まれる要素を列挙する」ことである。 ポスティングリストが与えられるので、and 検索と or 検索の結果をそれぞれ出...
[ { "submission_id": "aoj_2930_9328773", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i,j,n) for (int i = j; i < (int)(n); i++)\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\n#define all(x) (x.begin(), x.end())\ntemplate<typename T1, typename T2> inline bool chmax(T1 ...
aoj_2934_cpp
E: 往復文字列 / Round-trip String 物語 ここは全人類が競技プログラマーになった世界。この世界ではみなさんの生きる現代では考えられないような習慣が多数存在する。その中の一つに、両親、特に母親に感謝の証を表す時は、文字列を送るという風習がある。送る文字列としてどのような文字列がふさわしいかは地域差があるが、北の大地北海道では、できるだけシンプルな文字列が贈り物としてふさわしい。また、送られた側の母親は子供に返礼として、送られた文字列がどれほど美しいかを答える必要がある。 さて、今あなたは1児の母親から相談を受けている。その母親は子供から素晴らしそうな文字列をもらったのだが、どれくらい素晴らしいのかうまく測れないで...
[ { "submission_id": "aoj_2934_9758288", "code_snippet": "#line 1 \"main.cpp\"\n#include <bits/stdc++.h>\n#line 1 \"/home/anqooqie/.proconlib/lib/ac-library/atcoder/string.hpp\"\n\n\n\n#line 9 \"/home/anqooqie/.proconlib/lib/ac-library/atcoder/string.hpp\"\n\nnamespace atcoder {\n\nnamespace internal {\n\nstd...
aoj_2938_cpp
B: たぬきつね 問題 謎の装置 $M$ があり,この装置に Tanuki と Fox を入れると, 装置から一匹の動物が出てくる(以下, Tanuki を $T$ ,Foxを $F$ とする). $M(x, y)$ は,装置 $M$ に $x, y$ の順で動物を入れて出てきた動物を表す. 色々試した結果,以下のことがわかった. $M(T, T) = T$ $M(T, F) = F$ $M(F, T) = T$ $M(F, F) = T$ あなたは,一列に並んでいる動物たち $P_1, P_2, ... , P_N$ を以下のように装置に入れていった. $M(....M(M(P_1,P_2), P_3)...., P_N)$ 最後...
[ { "submission_id": "aoj_2938_3837431", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n int n;\n cin >> n;\n string ans = \"T\";\n for(int i=0;i<n;i++){\n string p;\n cin >> p;\n if(ans==\"T\"){\n ans = p;\n }\n else{...
aoj_2936_cpp
G: Donuts Orientation 物語 ほむちゃんの最近のマイブームはお菓子作りだ。たくさんお菓子を作っては、それを友達におすそ分けしているらしい。そんなほむちゃんは今回、ドーナツづくりに挑戦するようだ。 ドーナツづくりに大切なことはいくつもある。生地や味付けはもちろん、かわいい見た目にするためのデコレーションも外せない。試行錯誤を繰り返しているうちに、ほむちゃんのデコレーションへのこだわりに熱がこもってきたようだ。こだわりぬいたドーナツを多くの人に食べてもらいたいので、ほむちゃんはドーナツをたくさんつくりたいと考えている。 ・・・ところで、こだわるのは一向に構わないが、ほむちゃんこだわりのドーナツを十分な数用意することは...
[ { "submission_id": "aoj_2936_9331654", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nstruct ArbitraryModInt {\n int x;\n\n ArbitraryModInt() : x(0) {}\n\n ArbitraryModInt(int64_t y)\n : x(y >= 0 ? y % get_mod() : (get_mod() - (-y) % get_mod()) % get_mod()) {\n }\n\n...
aoj_2933_cpp
D: 矢 / Arrow 問題 rodea 君は 1 次元座標系の中におり、 x = 0 の場所に立っている。この位置から、 x = N の位置にある的を目がけて、 常に速さ 1 で移動する正の整数の長さの矢を投げる。しかし、rodea 君は非力なため、 区間 0 \leq x \leq N の中に合計 M 個の送風機を置くことにしている。 ここで、矢の先端から根元までの位置に 1 つの送風機も含まれない場合を「損失」と定義する。損失の判定は、矢の先端が x = 1, 2, 3, $\ldots$ , N に到達した際に行う(つまり、合計 N 回行う)。 このとき、以下のクエリを Q 回処理せよ。 「損失」許容可能な回数 l_i ...
[ { "submission_id": "aoj_2933_9329229", "code_snippet": "#pragma region Macros\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nusing lint = long long;\n\nusing ull = unsigned long long;\nusing ld = long double;\nusing int128 = __int128_t;\n#define all(x) (x).begin(), (x).end()\n#define EPS 1e-8\n#define...
aoj_2935_cpp
F: 赤黒そーるじぇむ / Red-Black Soul Gem 問題 ほむちゃんは、そーるじぇむを赤色や黒色に変化させたり、 異なる 2 つのそーるじぇむ間を魔法の糸で接続したりする不思議な力を持っています。 この力を使うことで、ほむちゃんは、そーるじぇむによる魔方陣を作ることができます。 ほむちゃんは、 1 から N で番号付けられた N 個のそーるじぇむがあるとき、以下の条件が成り立つ異なる魔方陣がいくつあるのか気になりました。 どの 2 つのそーるじぇむ間も、高々 1 回しか接続されない。 すべてのそーるじぇむの色が、赤色か黒色のいずれかになっている。 任意のそーるじぇむに対して、自身の色と異なる色のそーるじぇむのうち、少な...
[ { "submission_id": "aoj_2935_10328186", "code_snippet": "// AOJ #2935 Red-Black Soul Gem\n// 2025.3.26\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nll modPow(ll a, ll b, ll mod) {\n ll res = 1;\n a %= mod;\n while(b){\n if(b & 1) res = (res * a) % mod;\n ...
aoj_2940_cpp
D: 場所当てゲーム 問題 AORイカちゃん と そすうさ がグラフを使った場所当てゲームを行う. 最初に,AORイカちゃん が整数 $N$ を指定し,そすうさ は頂点数 $N$ の無向グラフを生成する. $N$ 個の頂点には, $1$ ~ $N$ までの番号が割り振られている.この無向グラフを使って,$K$ 回ゲームを行う. 各ゲームのはじめに AORイカちゃん は頂点を $1$ つ選び,そすうさ がその頂点を当てる. そすうさ は AORイカちゃん に最大 $10$ 回まで質問することができる. そすうさ が頂点番号を $1$ つ AORイカちゃん に伝えると,番号に従い AORイカちゃん は以下のうちどれかを答える. ...
[ { "submission_id": "aoj_2940_10848506", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing pii = pair<int, int>;\n\nenum {\n No,\n Near,\n Yes\n};\n\nint query(int n) {\n cout << n << endl;\n string r; cin >> r;\n if(r == \"Yes\") return Yes;\n else if(r == \"No\")...
aoj_2939_cpp
C: オセロ 問題 オセロの盤面を用意する. 盤面は左上が $(1,1)$ , 右下が $(8,8)$ と表記する. ここで用意する盤面は, 以下のように, $(5,4)$ の黒の石がない. ........ ........ ........ ...ox... ....o... ........ ........ ........ 黒石:x 白石:o 8x8の盤面 この状態から, 黒が先手でオセロを開始する. AORイカちゃんは, 以下のルールで $q$ 回遊ぶ. 左上を $a$ 行目 $b$ 列目のマス, 右下を $c$ 行目 $d$ 列目のマスとした, マス目に沿った長方形領域が与えられる. AORイカちゃんは, この長方形領...
[ { "submission_id": "aoj_2939_7957369", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\n\n\n\nint main(){\n\tint q;cin>>q;\n\tfor(int z = 0; q > z; z++){\n\t\tint a,b,c,d;cin>>a>>b>>c>>d;\n\t\tint ans = 0;\n\t\tfor(int i = a; c >= i; i++){\n\t\t\tfor(int j = b; d >= j; j++){\n\...
aoj_2941_cpp
E: LISum 問題 長さ $N$ の数列 $A$ が与えられる。 数列 $A$ の最長増加部分列のひとつを $B$ とするとき、$\sum B_i$ の最大値を求めよ。 数列 $A$ の最長増加部分列とは、すべての $i < j$ で $A_i < A_j$ を満たす部分列のうち、最長なものを示す。 制約 入力値は全て整数である。 $1 \leq N \leq 10^5$ $0 \leq A_i \leq 10^5$ 入力形式 入力は以下の形式で与えられる。 $N$ $A_1 \dots A_N$ 出力 数列 $A$ の最長増加部分列のひとつを $B$ とするとき、$\sum B_i$ の最大値を出力せよ。また、末尾に改行も...
[ { "submission_id": "aoj_2941_10853837", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing pll = pair<ll, ll>;\n\ntemplate<typename Monoid>\nclass segment_tree {\n using T = typename Monoid::type;\n\npublic:\n segment_tree(std::vector<T> const& init)\n ...