group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_2200_cpp
Problem D: Mr. Rito Post Office あなたは離島の郵便局に勤めるプログラマである.あなたの住んでいる地域は,複数の島々からなる.各島には一つ以上の港町がある.それらに加えて他の町や村があるかもしない.ある島から別の島に向かうためには船を使わなければならない.一つの島の中を回るには陸路が使えるが,海路を利用した方が速いこともある. 近年行われた郵便局の民営化をきっかけに,経費削減に向けて郵便配達員の人員整理が全国的に行われた.離島の郵便局もその例外ではなく,結果として郵便配達員は利藤さんただ一人となってしまった.その郵便局が集配を担当する地域は非常に広いため,一人で集配するのは大変な作業である.なので,どの...
[ { "submission_id": "aoj_2200_11057001", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF=0x3f3f3f3f;\nint main(){\n int n,m;\n while(scanf(\"%d%d\",&n,&m)!=EOF&&(n||m)){\n int d[2010][202];\n int l[202][202];\n int s[202][202];\n memset(d,0x3f,...
aoj_2199_cpp
Problem C: Differential Pulse Code Modulation 差分パルス符号変調は主に音声信号を圧縮する際に用いられる圧縮手法の一つである. 音声信号は計算機上では整数列(インパルス列)として扱われる.整数列は入力信号を一定時間間隔で標本化(サンプリング)し,振幅を記録したものである.一般にこの整数列は前後の値が近いという傾向がある.これを利用し,前後の値の差分を符号化し,圧縮率を向上させるのが差分パルス符号変調である. 本問題では差分の値をあらかじめ定められた値の集合から選ぶことを考える.この値の集合をコードブックと呼ぶことにする.復号化後の音声信号 y n は以下の式で定められる. y n = y ...
[ { "submission_id": "aoj_2199_11034201", "code_snippet": "#include <iostream>\n#include <vector>\n#include <cmath>\n#include <climits>\n\nusing namespace std;\n\nint main(){\n\n while(1){\n \n int N, M;\n cin >> N >> M;\n if (N==0 && M==0) break;\n\n vector<int> C(M);\n ...
aoj_2201_cpp
Problem E: Immortal Jewels English text is not available in this practice contest. ある時ある貴族が,ある貧乏な国のおてんばで勇敢なお姫様に惚れ込み結婚を申し込んだ.お姫様は貴族にある条件を出した.その条件とは「不死の宝石」と呼ばれている宝石を大量に持ってくることであった.不死の宝石は,ある山の特定の場所でしか取ることができない非常に希少な宝石である.しかも大変壊れやすいため,採取するには特別な方法が必要だった. 不死の宝石は円形をしており,二次元空間上に複数存在している.この宝石を取るには,ある特別な金属の棒でそれらを吸着する必要がある.金属の棒は無...
[ { "submission_id": "aoj_2201_10848639", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <vector>\n#include <cmath>\n#include <algorithm>\n\nusing namespace std;\nconst int maxn = 100 + 5;\nconst double PI = acos(-1);\n\nstruct Point\n{\n double x, y;\n Point(){}\n Point(double x_,...
aoj_2207_cpp
Problem D: 無矛盾な単位系 京、垓、{禾予}、穣、溝、澗、正、載、極、恒河沙、阿僧祇、那由他、不可思議、無量大数 分、厘、毛、糸、忽、微、繊、沙、塵、埃、渺、漠、模糊、逡巡、須臾、瞬息、弾指、刹那、六徳、虚空、清浄、阿頼耶、阿摩羅、涅槃寂静 これらが何か分かるだろうか。これらは全て10の累乗につけられた数詞である。 京 = 10 16 , 垓 = 10 20 , {禾予} = 10 24 , 穣 = 10 28 , 溝 = 10 32 , ... 分 = 10 -1 、厘 = 10 -2 、毛 = 10 -3 、糸 = 10 -4 、忽 = 10 -5 , ... ではこれらが実用的に使われているのを見たことはあるだろうか...
[ { "submission_id": "aoj_2207_8526509", "code_snippet": "// #define _GLIBCXX_DEBUG 1\n#include <bits/stdc++.h>\n// #include <atcoder/all>\nusing namespace std;\n#define ll long long\n#define ull unsigned long long\n\n#define rep1(i, n) for (int i = 1; i <= n; i++)\n#define rep_0(i, n) for (int i = 0; i < n; ...
aoj_2210_cpp
Problem G: 天体観測 2012年のある日のこと。 北の田舎町に住むあなたは、愛娘を連れて展望台で星見をすることにした。 この町は都会と違って街明かりが少なく、空気も澄んでいるので、晴れた日は満天の星空が広がっている。 天文にそこそこ詳しいあなたは季節ごとの有名な星や星座、それにまつわる神話ぐらいは知っているのだが、 なにせここは星降る町、名前のわからない星座もたくさん見えている。 この前の星見のときにそういった星々に関する娘の質問に答えられなかったあなたは、 星見の時刻にいったいどの星座が見えるのかを調べたいと思った。 特定の日時にどの星が見えるのかを知るには、星座早見盤というアイテムが有用である。 最近では携帯端末のGP...
[ { "submission_id": "aoj_2210_3086590", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <iomanip>\nusing namespace std;\nconst double EPS = 1e-8;\nconst double INF = 1e18;\nconst double PI = acos(-1);\n\nbool epsleq(const double &a, const double &b){\...
aoj_2209_cpp
Problem F: UTF-8 UTF-8はマルチバイト文字を符号化する手法の一つである。 文字は計算機上ではバイト列として扱われる。英語だけであればラテンアルファベットおよび数字、記号を合わせても 1byteで表現できるが、残念ながら世界中で利用されている文字を1byteで表現することはできないため、複数のバイトを用いて文字を表す必要がある。 ここで例えば"あ"という文字に12354(0x3042)という2バイト列を割り当てたとき、そのままバイト列を並べると0x30,0x42と2文字なのか0x3042で1文字なのかが区別がつかない。 このため、マルチバイト文字符号化方式のUTF-8では始めの1バイト目で続くバイト列の長さが分かる...
[ { "submission_id": "aoj_2209_3699896", "code_snippet": "#include <bits/stdc++.h>\n#define r(i,n) for(int i=0;i<n;i++)\n#define int long long\nusing namespace std;\ntypedef pair<int,int>P;\ntypedef pair<int,P>P2;\n#define F first\n#define S second\n\nint calc1(string s){\n\tif(s[0]=='1')return 0;\n\tint x=1;...
aoj_2208_cpp
Problem E: トーマス・ライトの憂鬱 昨日の夕方の話。 普段通り大学での講義が終わり、日課であるキャンパスでの猫への餌付けを済ませた後、家に帰り着くと、作業着を着た人たちが僕の家の扉を取り替える工事をしていた。 それだけなら特に僕の頭痛の種を増やすような出来事ではないのだが、取り外されて去っていく慣れ親しんだ鍵とレバーがついている茶色の扉が非常に平凡であるのに対して、今からまさに取り付けられようとしている黒色の扉が非常に奇妙なもので、ああこれはまたうちの親父が何かを思いついてしまったのだなと容易に想像がついてしまうのであった。 その偏屈親父が言うには、鍵は無くす可能性があるので信用することが出来ない。手元に鍵があったとしても...
[ { "submission_id": "aoj_2208_10852901", "code_snippet": "#include <algorithm>\n#include <vector>\n#include <iostream>\nusing namespace std;\nint main() {\n\tint n,t;\n\tfor(;(cin>>n),n;){\n\t\tvector<int> r,l;\n\t\tbool ok=true;\n\t\tfor(int i=0;i<n;i++)(cin>>t),r.push_back(t);\n\t\tfor(int i=0;i<n;i++)(cin...
aoj_2213_cpp
Problem J: 多項式の解の個数 きたまさ君は大学でさまざまな変換について研究している。最近、きたまさ君が興味を持っている変換は次のようなものである。 N+1個の整数 a 0 , ..., a N を固定し、整数 z を入力とする。また P を素数とする。 t = ( a N z N + a N-1 z N-1 + ... + a 2 z 2 + a 1 z + a 0 ) mod P きたまさ君はこの変換によって t = 0 になってしまう z がいくつもあることに気がついた。 そこで、きたまさ君は友人でありスーパープログラマーでもあるあなたに、変換後に t = 0 になる z が 0〜P-1 にいくつあるかを計算してもらう...
[ { "submission_id": "aoj_2213_10806496", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n// min non-negative i such that n <= 2^i\nint ceil_pow2(int n) {\n int i = 0;\n while ((1U << i) < (unsigned int)(n)) i++;\n return i;\n}\n\n// min non-negative i such that (x & (1 << i)) != 0...
aoj_2211_cpp
Problem H: 迷い猫、走った 洋菓子専門店ストレイキャッツではたくさんの猫が飼われている。猫の数があまりにも多いため、この店のスタッフである希は餌やりに困っていた。 いくつかの場所に餌を置いても、猫は貪欲なので最も近い餌に向かってしまい、一つの餌入れにたくさんの猫が集中してしまう。 あなたは希のために、できるだけ猫が集中しない餌の配置を求める問題を解くことにした。 問題を簡単にするため、猫は平面上の y>0 の部分にいて餌を置くまで動かないとする。 猫は N 個の集団に分かれていて、一箇所に何匹もいるかもしれない。 餌入れは y=0 上の M 点に固定してあり、この中からいくつか選んで餌を入れることになる。 餌を入れると、猫...
[ { "submission_id": "aoj_2211_10215478", "code_snippet": "// AOJ #2211\n// Stray Cats, Run... 2025.2.13\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n \nstruct State { int i, j; };\n \nbool feasible(ll L, const vector<int>& xGroups, const vector<ll>& weights,\n const vector<ll>...
aoj_2212_cpp
Problem I: 盗まれた宝石 パル王国の国宝である宝石が盗賊たちに盗まれた。 冒険者のあなたはその噂を聞きつけて盗賊のアジトに向かい、なんとか宝石を取り戻すことが出来た。 ところが、宝石をパル王国の城へ返しに出向いたところ、城の守衛兵から、 「我が王はまだあなたを完全に信用していない。その宝石が本物かどうか怪しいし、そもそも宝石を取り戻したというのがウソで、王の命を狙う盗賊の仲間なのではないか?と疑っておられる。」 といわれた。 あなたは、守衛兵から本当に信頼できる人物かどうか試すための試練を与えられた。試練の内容は、 「城の地下倉庫へ行き指定された場所に宝石を置け。そこに宝石が本物だったときに反応する魔法陣が書かれてある。た...
[ { "submission_id": "aoj_2212_10853818", "code_snippet": "#include<cstdio>\n#include<cstdlib>\n#include<cstring>\n#include<cctype>\n#include<iostream>\n#include<algorithm>\n#include<queue>\n#include<set>\n#include<map>\n#define ULL unsigned long long\n#define LL long long\nusing namespace std;\nconst int MAX...
aoj_2203_cpp
Problem G: Magical Island 2 まだ魔法があたりまえのように存在した時代である.ある魔導士の一族は,魔力によって作られた正方形の形の島に住んでいた. ある時,この島に危機が訪れた.帝国が大陸間弾道魔導ミサイルを開発し,この島を照準に合わせてきたのである.この世界の魔法は地属性,水属性,火属性,風属性などに分類でき,魔導ミサイルもその四つの属性のいずれかに属していた.島の四隅にはそれぞれ地の水晶,水の水晶,火の水晶,風の水晶が配置されていて,水晶に魔力を送り込むことで対応する属性の魔法攻撃を防ぐことがきでる. 魔導士達は帝国が開発した大陸間弾道魔導ミサイルによる攻撃をかろうじて退けることができた.しかし,帝国は...
[ { "submission_id": "aoj_2203_8216177", "code_snippet": "#include <algorithm>\n#include <assert.h>\n#include <bitset>\n#include <climits>\n#include <cmath>\n#include <complex>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <ctime>\n#include <deque>\n#include <iomanip>\n#include <iostrea...
aoj_2216_cpp
Problem A: Summer of KMC Description KMCはコミックマーケットと呼ばれる同人即売会で毎年CDを販売している。 コミックマーケットでCDを売ることになったFであったが、Fの人気により、KMCの売り場には人が殺到し、お釣りの計算が追いつかない状態となった。そこでFは金額を入力すると即座にお釣りを出力するプログラムを書くことにした。 KMCが釣り銭として用意しているのは、100円玉と500円玉と1000円札のみである。これらの硬貨・札は無限にあるものと考えて良い。お釣りは、硬貨・札の個数が最小になるように選ぶ。また、KMCが販売するCDの値段は100の倍数であり、購入者が支払う金額も100の倍数である...
[ { "submission_id": "aoj_2216_3702261", "code_snippet": "#include <iostream>\n#include <string>\n#include <algorithm>\n#include <functional>\n#include <vector>\n#include <utility>\n#include <cstring>\n#include <iomanip>\n#include <numeric>\n#include <limits>\n#include <cmath>\n#include <cassert>\n\nusing nam...
aoj_2214_cpp
Problem K: ワープホール 20XX年、遠く離れた場所に対する効率的な物質転送方式が確立され、人類の宇宙への進出はますます加速されることになった。この転送方式は、より遠くに物質を転送しようとすると、原則的により大きな物質の転送が可能になる点で革新的であった。転送方式の詳細を次に記す。 まず転送対象となる物質は、スタート座標(1, 1)にて単位質量毎のパーティクルに分割される。各パーティクルには、各々異なる波動エネルギーが与えられなければならない。波動エネルギーは、 V と H からなる任意の長さの文字列で表現され、パーティクルの宇宙空間における漂い方を規定する。 V は座標上(+1, 0)の移動を意味し、 H は(0, +1...
[ { "submission_id": "aoj_2214_10866029", "code_snippet": "#include <bits/stdc++.h>\n\n#define rep(i, j, k) for (int i = j; i < k; ++i)\n#define irep(i, j, k) for (int i = j - 1; i >= k; --i)\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef long double ld;\ntypedef pa...
aoj_2217_cpp
Problem B: Let's JUMPSTYLE Description 踊りの好きなFは,とあるダンスホールでJUMPSTYLEと呼ばれるハードコアな踊りの練習をすることにした. フロアはN×Nの格子状にタイルが敷き詰められている. 踊りの練習をサポートするため,各タイルには次のステップに飛び移るべきタイルの座標が書かれている.Fは日々の練習によって強靭な運動神経を持っており,フロア内の任意のタイルへ飛び移ることができる. Fは,十分に長い時間この踊りを続けていけば,いつか定常状態に入り,同じルートをただループする状態になることに気付いた.Fはこのようなループがこのフロアにいくつ存在するのか疑問に思い,プログラマであるあなたに...
[ { "submission_id": "aoj_2217_3778511", "code_snippet": "#include <iostream>\n\nusing namespace std;\n\nint w[101][101],h[101][101];\nbool b[101][101];\n\nint dfs(int x,int y)\n{\n \n if(x == -1 || y == -1) return 0;\n if(b[x][y]){\n w[x][y] = -1;\n h[x][y] = -1;\n return 1;\n ...
aoj_2219_cpp
Problem D: THE BYDOLM@STER Description THE BYDOLM@STER(バイドルマスター)とは1rem社より2010/4/1にEXIDNAで発売が予定されている育成シミュレーションゲームである。一応断っておくが、今月初めにネットワーク接続サービスが停止した某アーケードゲームとはたぶん関係が無い。 このゲームはバイドルたちからプロデュースするユニット(編隊)のメンバーを選択し、メンバーたちとのレッスンやコミュニケーションを通じて、彼女(彼)らをバイドルの頂点、トップバイドルに育て上げるゲームである。 各バイドルには能力値としてボーカル、ダンス、ルックスの3つのパラメータを持ち、ユニットの能力値はユ...
[ { "submission_id": "aoj_2219_8860773", "code_snippet": "#include <algorithm>\n#include <cfloat>\n#include <climits>\n#include <cmath>\n#include <complex>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <ctime>\n#include <functional>\n#include <iostream>\n#include <list>\n#include <map>\...
aoj_2218_cpp
Problem C: K Poker Description 時は200X年、K大学で活動する謎のサークルKはその大学の文化祭の最中にK東4Fで彼らが作成した新たなゲーム、Kポーカーを発表した。 このゲームは一見すると普通のポーカーであるが、カードに基本点という要素をつけてポーカーをより奥の深いゲームにしたものである。 カードの基本点はそれぞれのカードに書かれている絵柄によって決まり、手札の点数は手札にある5枚の基本点の合計に手札の役の倍率を掛けたものになる。 この基本点を導入した事により、例えばフルハウスなどの強い役を作ったとしても基本点が0であればブタと同様に扱われてしまい、ワンペアに負けることさえある。 それ以外のルールは通常...
[ { "submission_id": "aoj_2218_8139138", "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_2221_cpp
Problem F: KULASIS Description KULASISとは,全学共通科目に関する情報をWeb化し,学生・教員への支援やサービスの向上を目的に,高等教育研究開発推進機構で開発・運用しているシステムの名称です。 KULASISは2003年度のオンラインシラバス開発から始まり,Web掲示板・履修登録・成績関係(採点登録・学生からの採点確認)と順次システムを拡充してきました。 学生はパソコン・携帯電話から学内外を問わず,教務情報(休講・授業変更・レポート)の確認・履修登録・採点確認等の機能を利用することができます。ログイン件数は多い日には10,000件を超え,京都大学の教務情報システムとして浸透し,全学共通科目を履修す...
[ { "submission_id": "aoj_2221_10850489", "code_snippet": "#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\nvector<int> reverse_hash(int x, int b, int l) {\n\tvector<int> ret(l);\n\tint mul = 1;\n\tfor (int i = 0; i < l; i++) {\n\t\tret[i] = x / mul % b;\n\t\tmul *= b;\n\t}\...
aoj_2223_cpp
Problem B: Kaeru Jump There is a frog living in a big pond. He loves jumping between lotus leaves floating on the pond. Interestingly, these leaves have strange habits. First, a leaf will sink into the water after the frog jumps from it. Second, they are aligned regularly as if they are placed on the grid points as in ...
[ { "submission_id": "aoj_2223_10684773", "code_snippet": "#include <vector>\n#include <list>\n#include <map>\n#include <set>\n#include <deque>\n#include <queue>\n#include <stack>\n#include <bitset>\n#include <algorithm>\n#include <functional>\n#include <numeric>\n#include <utility>\n#include <sstream>\n#incl...
aoj_2224_cpp
Problem C: Save your cats Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them. One day, an evil witch visited the village. She envied the cats for being loved by everyone. She drove magical piles in his garde...
[ { "submission_id": "aoj_2224_10848478", "code_snippet": "#include <iostream>\n#include <cstring>\n#include <cstdio>\n#include <cmath>\n#include <vector>\nusing namespace std;\nconst int maxn=1e4+5;\ntypedef long long LL;\nstruct Point\n{\n int x;\n int y;\n};\n\nstruct edge\n{\n int to;\n doubl...
aoj_2231_cpp
Problem J: Cruel Bingo Bingo is a party game played by many players and one game master. Each player is given a bingo card containing N 2 different numbers in a N × N grid (typically N = 5). The master draws numbers from a lottery one by one during the game. Each time a number is drawn, a player marks a square with tha...
[ { "submission_id": "aoj_2231_4303458", "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\n#define MOD 10007\n\...
aoj_2227_cpp
Problem F: Bouldering Bouldering is a style of rock climbing. Boulderers are to climb up the rock with bare hands without supporting ropes. Your friend supposed that it should be interesting and exciting, so he decided to come to bouldering gymnasium to practice bouldering. Since your friend has not tried bouldering ye...
[ { "submission_id": "aoj_2227_10852749", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cstdlib>\n#include <algorithm>\n#include <cmath>\nusing namespace std;\n\nconst double eps = 1e-3;\n\nconst double pi =acos(-1.0);\n\nstruct Point\n{\n double x,y;\n Point() {...
aoj_2225_cpp
Problem D: Dungeon Wall In 2337, people are bored at daily life and have crazy desire of having extraordinary experience. These days,“Dungeon Adventure” is one of the hottest attractions, where brave adventurers risk their lives to kill the evil monsters and save the world. You are a manager of one of such dungeons. Re...
[ { "submission_id": "aoj_2225_10853847", "code_snippet": "#include<stdio.h>\n#include<string.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\n#define maxw 55\n#define maxn 1010\n\nint n;\nint w;\nint h;\nbool wall[maxw][maxw][4];\nint mp[maxw][maxw];\nint ix,iy;\nint ox,oy;\nint que[maxw*maxw...
aoj_2226_cpp
Problem E: Psychic Accelerator In the west of Tokyo, there is a city named “Academy City.” There are many schools and laboratories to develop psychics in Academy City. You are a psychic student of a school in Academy City. Your psychic ability is to give acceleration to a certain object. You can use your psychic abilit...
[ { "submission_id": "aoj_2226_10851598", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <cmath>\n#include <cctype>\n#include <vector>\n#include <stack>\n#include <queue>\n#include <map>\n#include <algorithm>\n#include <iostream>\n#include <string>\n#include <set>\n#defin...
aoj_2230_cpp
Problem I: How to Create a Good Game A video game company called ICPC (International Company for Playing and Competing) is now developing a new arcade game. The new game features a lot of branches. This makes the game enjoyable for everyone, since players can choose their routes in the game depending on their skills. R...
[ { "submission_id": "aoj_2230_10850465", "code_snippet": "#include<cstdio>\n#include<cstring>\n#include<cmath>\n#include<algorithm>\n#define add(a,b,c) (e[i]=b,pre[i]=last[a],last[a]=i,w[i]=c)\n#define prec 1e-6\n#define inf 1e9\nusing namespace std;\nstruct edge\n{ int u,v,w;\n edge(int u=0,int v=0,int...
aoj_2229_cpp
Problem H: Ropeway On a small island, there are two towns Darkside and Sunnyside, with steep mountains between them. There’s a company Intertown Company of Package Conveyance; they own a ropeway car between Darkside and Sunnyside and are running a transportation business. They want maximize the revenue by loading as mu...
[ { "submission_id": "aoj_2229_1574246", "code_snippet": "#include <cstdlib>\n#include <cctype>\n#include <cstring>\n#include <cstdio>\n#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <string>\n#include <iostream>\n#include <sstream>\n#include <map>\n#include <set>\n#include <queue>\n#incl...
aoj_2232_cpp
Problem A: Ennichi 縁日に来たうさぎが, ある出店のゲームの景品がキャロットケーキであるのを見つけた. このゲームのルールは以下の通りである. 縦h マス× 横w マスの格子状のフィールドがあり, 各マスにつき高々1 個のブロックが置かれる. 各ブロックにはアルファベット大文字(‘A’ - ‘Z’) のいずれかで表される色がついている. 同色のブロックが縦または横に一直線上にn 個以上連続して並ぶと, それらのブロックは消滅する. 参加者は横に隣り合う2 つのマスを選んで, それらの状態を互いに入れ替える操作ができる. ブロックの入れ替え, 消滅, 落下によってブロックの有るマスの1 つ下のマスにブロックが無くなる...
[ { "submission_id": "aoj_2232_11059717", "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_2234_cpp
Problem C: Usagitobi m × n マスの盤がある. i 行 j 列のマスを( i , j ) (0 ≤ i < m , 0 ≤ j < n ) で表す. うさぎは( x , y ) にいるとき, (( x + a ) mod m , ( y + b ) mod n ) または(( x + c ) mod m , ( y + d ) mod n ) へ跳ぶことができる. いま, うさぎが(0, 0) にいる. 一度跳び立ったマスへ再び行くことはできないとするとき, うさぎは最大何回跳ぶことができるか. Input 入力は一行に m , n , a , b , c , d がスペース区切りで与えられる. 1 ≤ m ...
[ { "submission_id": "aoj_2234_7242501", "code_snippet": "#include <iostream>\n#include <map>\n#include <vector>\nusing namespace std;\n\nlong long GCD(long long a, long long b) {\n\tif (b == 0) return a;\n\treturn GCD(b, a % b);\n}\n\nlong long GetAnswer(long long H, long long W, long long A, long long B, lo...
aoj_2233_cpp
Problem B: Carrot Tour うさぎがある国を旅行している. この国には1 から n の番号がついた n 個の都市があり, うさぎは今都市1にいる. 都市 i は座標平面上の1 点( x i , y i ) とみなす. うさぎは以下の条件をみたすように旅をする. 移動経路は折れ線であり, その各部分は異なる2 都市を結ぶ線分でなければならない. 移動経路の全長は r 以下でなければならない. 経路のうち重なった部分も, 通った回数分数える. 移動する方向が変わるとき, 曲がる角度は θ 以下でなければならない. 最初の移動方向に制限はない. うさぎがある都市から別の都市へ移動をすると, 移動先の都市でニンジンを1 本...
[ { "submission_id": "aoj_2233_10880835", "code_snippet": "#define _USE_MATH_DEFINES\n#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint x[22], y[22];\ndouble r, theta;\n\nbool check_angle(int p, int i, int n) {\n\tdouble a1 = x[i] - x[p], a2 = y[i] - y[p];\n\tdouble b1 = x[n] - x[i],...
aoj_2238_cpp
Problem G: Nurie 紙の上に円が n 個書かれている. うさぎは k 色の絵の具を持っていて, 次のルールに従って紙に色を塗っていく. 各領域をある1 色の絵の具で塗るか, 何も塗らない. ここで「領域」とは, 円弧の集合で囲まれた面積有限の部分を指す. 隣り合っている2 つの領域を同じ色の絵の具で塗ることはできない. ここで「隣り合っている」とは,境界の一部を共有する円弧があることを指す. 共有点が有限個である2 つの領域は, 隣り合っているとはみなされない. 隣り合っている2 つの領域の両方を塗らないままにすることは許される. うさぎはできるだけ多くの領域を絵の具で塗りたい. 塗れる領域の個数の最大値を求めよ. I...
[ { "submission_id": "aoj_2238_2266327", "code_snippet": "#include<bits/stdc++.h>\n#define MAX 1024\n#define inf 1<<29\n#define linf (1e16)\n#define eps (1e-8)\n#define Eps (1e-15)\n#define mod 1000000007\n#define pi acos(-1.0)\n#define phi (1.0+sqrt(5.0))/2.0\n#define f first\n#define s second\n#define mp ma...
aoj_2239_cpp
Problem H: Nearest Station うさぎがある電車のチケットを n 枚持っている. チケットにはそれぞれ0 から n − 1 までの番号がついていて, k 番のチケットを使うと, p ⋅ a k + q ⋅ b k 駅進むことができる. うさぎは今いる駅から m 駅進んだ駅にあるニンジン食べ放題の店に行きたいが, なるべく歩く距離を短くしたい. 駅は等間隔に並んでいる. チケットを電車の上り線で進むことのみに用いるとき, うさぎは最小何駅分の徒歩で店に着けるか. Input 1 ≤ n , m , a , b , p , q ≤ 1 000 000 000 000 (整数) Output うさぎは最小何駅分の徒歩...
[ { "submission_id": "aoj_2239_10866027", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing VS = vector<string>; using LL = long long;\nusing VI = vector<int>; using VVI = vector<VI>;\nusing PII = pair<int, int>; using PLL = pair<LL, LL>;\nusing VL = vector<LL>; using ...
aoj_2236_cpp
Problem E: Rabbit Plays Games! うさぎがとあるロールプレイングゲームで遊んでいる. 城に入る直前で, 敵に待ち伏せされていた! うさぎが操作する主人公1 人と, n 体の敵との戦闘となった. 各キャラクターには4 つの能力値, 体力 h i , 攻撃力 a i , 防御力 d i , 敏捷 s i が定められている. i = 0 は主人公の情報, 1 ≤ i ≤ n は各敵の情報を表す. 戦闘はターン制である. 各ターン, 生き残っているキャラクターが, 敏捷の値が高い順に攻撃を行う. 敵は必ず主人公を攻撃する. 主人公は敵1 体を攻撃するが, どの敵を攻撃するかは毎ターンごとに主人公が選べる.攻撃力 ...
[ { "submission_id": "aoj_2236_10511586", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define all(v) (v).begin(),(v).end()\n#define pb(a) push_back(a)\n#define rep(i, n) for(int i=0;i<n;i++)\n#define foa(e, v) for(auto&& e : v)\nusing ll = long long;\nconst ll MOD7 = 1000000007, MOD998 = ...
aoj_2237_cpp
Problem F: The Castle 待ち伏せていた敵を見事撃破したうさぎは, 主人公を敵の城内に進めることに成功した. 主人公が城の地下牢に捕らわれていたねこたちを解放したところ, 彼らのうちの何匹かが主人公の力になってくれることになった. ねこたちの話では, 城の奥にいる魔王に辿りつくには1 番から n 番の n 個の部屋をこの順に通り抜けることになるが, 各部屋には1 体ずつ敵が待ち受けていて逐一倒していかなければならないという. 仲間になった m 匹のねこそれぞれについて, 各部屋の敵それぞれに対する勝率が分かっており, 主人公はこのねこたちを1 匹ずつ城の奥へ向けて派遣する. 各部屋はそこにいる敵を倒してからでなけれ...
[ { "submission_id": "aoj_2237_10373053", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <cassert>\n#include <vector>\n#include <algorithm>\n#include <utility>\n#include <numeric>\n// #include \"Src/Utility/BinarySearch.hpp\"\n// #include \"Src/Sequence/CompressedSequence.hpp\"\n// #includ...
aoj_2235_cpp
Problem D: Graph Construction n 匹のうさぎがいて, 0 番から n − 1 番の番号がついた小屋に1 匹ずつ住んでいる. あるとき, 秘密の組織によって地下通路の建設工事が行われる, という情報がうさぎたちのもとへ入った. 地下通路を使えば, うさぎたちは他のうさぎたちの小屋へ遊びに行けるようになって嬉しい. 通路は両方向に進むことができ, また通路同士は交わらない. 諸事情により, 一度建設された通路が破壊されてしまうこともある. 通路の建設や破壊の工事は1 本ずつ行われ, 各工事中はうさぎは自分の小屋に留まっているものとする. うさぎたちは, 工事のいくつかの段階において, あるうさぎとあるうさぎ...
[ { "submission_id": "aoj_2235_10456769", "code_snippet": "// competitive-verifier: PROBLEM\n#include <iostream>\n#include <utility>\n#include <vector>\n#include <algorithm>\n#include <bit>\n#include <cassert>\n#include <map>\n#include <stack>\n/**\n * @brief Undo可能Union-Find\n * @details Implement (union by ...
aoj_2240_cpp
Problem I: Lapin Noir ここは, 地面が正六角形を敷き詰めたマス目になっている街である. 各マスは, 下の図のように2 つの整数で表される. ねこは(0, 0) のマスへ行こうとしている. いたずら好きの黒うさぎはこのことを知って, ねこの邪魔をしようと考えた. 黒うさぎはねこがいるマスへ跳び, その周りの6 マスのうち1 つまたは隣り合う2 つをブロックすることができる. ねこは周りの6 マスのうち, ブロックされていないマスを1 つ選んで進む. ねこが動くたび黒うさぎはねこを追いかけ, またブロックを行うことができる. 黒うさぎが動くと元のブロックは解除される. 下の図はブロックの様子を示している. この街に...
[ { "submission_id": "aoj_2240_4872355", "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 1000000000000000000\n#define MOD 1000000007\n#define EPS 0.000000001\nusing namespace std;\n\n\n#define SIZE 40005\n\n...
aoj_2241_cpp
Problem J: Usaneko Matrix うさぎとねこが勝負をしている. ルールは以下の通りである. まず2 匹はそれぞれ n 行 n 列の正方形状に n 2 個の整数を紙に書き, トランプを1 枚ずつ引く. 次に, 1 から 1 000 000 までの数が1 つずつ書かれた1 000 000 枚のカードを2 匹でシャッフルし, これを1 枚ずつ交互に引いていく. 2 匹はカードが引かれるたび, カードと同じ数が自分の紙に書かれていたらそれに印をつける. 「印がついた n 個の数の組であって, 一直線上に並んでいるもの」の個数が, はじめに引いたトランプの数以上になることを勝利条件とする. 与えられた m 枚目のカードまで...
[ { "submission_id": "aoj_2241_10850418", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define REP(i, n) for (int i = 0; i < (n); i++)\n#define int long long\n#define FOR(i, m, n) for (int i = (m); i < (n); i++)\n#define all(x) x.begin(), x.end()\nusing pii = pair<int, int>;\n\nint A[5...
aoj_2242_cpp
Problem A: Era Name As many of you know, we have two major calendar systems used in Japan today. One of them is Gregorian calendar which is widely used across the world. It is also known as “Western calendar” in Japan. The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system comes ...
[ { "submission_id": "aoj_2242_11059750", "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_2245_cpp
Problem D: Dice Room You are playing a popular video game which is famous for its depthful story and interesting puzzles. In the game you were locked in a mysterious house alone and there is no way to call for help, so you have to escape on yours own. However, almost every room in the house has some kind of puzzles and...
[ { "submission_id": "aoj_2245_4879027", "code_snippet": "#include \"iostream\"\n#include \"climits\"\n#include \"list\"\n#include \"queue\"\n#include \"stack\"\n#include \"set\"\n#include \"functional\"\n#include \"algorithm\"\n#include \"string\"\n#include \"map\"\n#include \"unordered_map\"\n#include \"uno...
aoj_2243_cpp
Problem B: Step Step Evolution Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown in the front screen. There are eight types o...
[ { "submission_id": "aoj_2243_11059884", "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_2244_cpp
Problem C: Dungeon Quest II The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king and all of his soldiers were destroyed by the hero and the peace is there now. One day, however, the hero was worrying about the rebirth of the devil king, so he decided to ask security agency to ...
[ { "submission_id": "aoj_2244_10849113", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <algorithm>\n#include <queue>\nusing namespace std;\n#define MAXN 310\n#define MAXM 5010\n#define FI first\n#define SE second\n#define MP(x,y) make_pair(x,y)\nconst int INF =100000000...
aoj_2250_cpp
Problem I: Operator The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the support center all the time. So, the company wants to figure out how many operators needed to handle this situation. Fo...
[ { "submission_id": "aoj_2250_10867556", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <algorithm>\n#include <cmath>\n#include <iostream>\n#include <queue>\n#define FI first\n#define SE second\nusing namespace std;\nconst double EPS = 1e-8;\nconst int MAXN = 1005;\nconst int INF = 11111111...
aoj_2251_cpp
Problem J: Merry Christmas International Christmas Present Company (ICPC) is a company to employ Santa and deliver presents on Christmas. Many parents request ICPC to deliver presents to their children at specified time of December 24. Although same Santa can deliver two or more presents, because it takes time to move ...
[ { "submission_id": "aoj_2251_10848566", "code_snippet": "#include<stdio.h>\n#include<string.h>\n#include<iostream>\n#include<algorithm>\n#include<queue>\nusing namespace std;\n\ntypedef int ll;\nconst int inf = 200000000;\n#define N 2100\nint lef[1005], pn;\nint tim, T[1005];\nvector<int> G[1005];\nbool mat...
aoj_2253_cpp
ブレイブ・フォース・ストーリー English text is not available in this practice contest. 「最果ての地,ナイン・アイランドには特別な力を持つものが生きていた. ある者は火,ある者は氷,ある者は風,ある者は土を意のままに操ることができた. 人はこれらの術者をこう呼んだ.『Brave Force』と・・・.時は戦国時代.権力者たちはBrave Forceを私欲のために使わんとBrave Force狩りを始めた. Brave Forceを巡る戦いが今始まろうとしている.」 以上は,あなたが今つくろうとしている戦略シミュレーションゲームのプロローグである.このプロローグは本問題には全く...
[ { "submission_id": "aoj_2253_10681617", "code_snippet": "#include <bits/stdc++.h>\n#include <cstdint>\n#include <regex>\nusing namespace std;\n\nusing ll = long long;\nusing vi = vector<int>;\nusing vl = vector<long long>;\nusing vs = vector<string>;\nusing vc = vector<char>;\nusing vb = vector<bool>;\nusin...
aoj_2246_cpp
Problem E: Alice and Bomb Alice and Bob were in love with each other, but they hate each other now. One day, Alice found a bag. It looks like a bag that Bob had used when they go on a date. Suddenly Alice heard tick-tack sound. Alice intuitively thought that Bob is to kill her with a bomb. Fortunately, the bomb has not...
[ { "submission_id": "aoj_2246_10829154", "code_snippet": "#include<bits/stdc++.h>\n//#define Alex std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0);\n//#define int long long\n//#define double long double\n//#define L(i,a,b) for(int i = a;i <= b;i++)\n//#define R(i,a,b) for(int i = a;i >= b;i-...
aoj_2254_cpp
最短ルート English text is not available in this practice contest. あなたの所属する知的プログラミングサークル (通称 Intelligent Clever Programming Circle, ICPC)では,今大掃除の最中である. 部室には,歴代の先輩たちの残していったさまざまなアイテムが所狭しと放置されている. あなたが棚を整理していると,奥に大量のレトロゲームが封印されているのを発見した. その中のいくつかに見覚えがあったあなたは,久々にそのゲームを遊んでみることにした. 見つけたゲームの詳細は次の通りである. このゲームには1番から N 番までの N 個のステージが...
[ { "submission_id": "aoj_2254_10853366", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n int N;\n while(cin >> N, N) {\n vector<vector<int>> t(N, vector<int>(N + 1));\n for(int i = 0; i < N; ++i) {\n for(int j = 0; j < N + 1; ++j) {\n ...
aoj_2255_cpp
6÷2(1+2) English text is not available in this practice contest. 数学科の学生であるきたまさ君は,数学はとても得意なのだが算数はあまり得意ではない. 特に演算子の優先順位が苦手で, カッコの中を先に計算するというのはわかるのだが, "+" と "*" のどちらを優先したら良いかとか複数の演算子が並んでいるときに左から計算したら良いのか右から計算したら良いのか覚えておらず, その時の気分で好きな順番で計算をしている.例えば,"1*1-1+1"という数式を前から"((1*1)-1)+1"という順番で計算する場合もあれば,真ん中から"(1*(1-1))+1"という順番で計算す...
[ { "submission_id": "aoj_2255_10685115", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nbool solve();\n\nusing ll = long long;\n#define rep(i, a, b) for (int i = a; i < (b); ++i)\n#define sz(x) (int)(x).size()\n#define all(x) x.begin(), x.end()\ntypedef pair<int, int> pii;\ntypedef vector<i...
aoj_2249_cpp
Problem H: Road Construction King Mercer is the king of ACM kingdom. There are one capital and some cities in his kingdom. Amazingly, there are no roads in the kingdom now. Recently, he planned to construct roads between the capital and the cities, but it turned out that the construction cost of his plan is much higher...
[ { "submission_id": "aoj_2249_11056492", "code_snippet": "#include <cstdio>\n#include <algorithm>\n#include <vector>\n#include <cstring>\n#include <queue>\nusing namespace std;\nconst int INF=0x3f3f3f3f;\nconst int maxv=10002;\nstruct edge{int en,dis,cost;};\ntypedef pair<int,int> P;\nint main(){\n int sc...
aoj_2256_cpp
ケーキ分割問題 English text is not available in this practice contest. イコとピコはACM博士によって開発された人工知能を搭載した双子のロボットである.今日は二人の誕生日なので,博士は二人のためにたくさんのイチゴがのったケーキを用意した. ケーキは横幅 W ×奥行き H の長方形の形をしている. 便宜上,ケーキは上から見たとき(0,0),( W ,0),( W , H ),(0, H )を頂点とする長方形になるように置かれているとする. また,二人に均等になるようにちょうど2 N 個のイチゴが乗っている. せっかくなので,博士は二人にケーキを切らせることにした. イコとピコは協...
[ { "submission_id": "aoj_2256_10848200", "code_snippet": "#include <bits/stdc++.h>\n#define ll long long\n#define endl '\\n'\n#define ls rt << 1\n#define rs rt << 1 | 1\n#define maxn 200010\nusing namespace std;\n\nconst double eps = 1e-12;\nconst double pi = acos(-1.0);\nint sgn(double x)\n{\n if (fabs(x...
aoj_2260_cpp
問題 B : (iwi) 20XX 年の今,G○○gle 社の世界的な支配により,人々のコミュニケーションは限られており, 例えば,自由に人と情報をやりとりすることは基本的に許されていない. 特に,過去にプログラミングコンテストで名を馳せた強豪たちは,危険と判断され, お互いバラバラにされ,密かに注意深く監視されているという. 自分も,そんな一人であった,ような気がする. しかし実は,自分は記憶を失ってしまっているのだ. 自分が何と名乗っていたか,それすらも思い出せない. 'i' とか 'w' とか括弧とかを使っていた気がするが, それっぽいものを書きだしてみても,しっくりこない. そういえば,今思い出したことには,左右に線対称だっ...
[ { "submission_id": "aoj_2260_9264521", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\n#define rep(i, n) for(ll i = 0; i < (n); i++)\n#define reps(i, l, r) for(ll i = (l); i < (r); i++)\n#define endl \"\\n\";\n#define all(a) (a).begin(), (a).e...
aoj_2258_cpp
全自動円形掃除機 English text is not available in this practice contest. Automatic Cleaning Machine (ACM) 社は画期的な全自動円形掃除機 Intelligent Circular Perfect Cleaner(ICPC) を開発した. なんとこの ICPC は人がいない日中に自動で動き出し,自分が通り過ぎた場所のゴミを掃除する機能を備えている. 全自動という特性を活かすためにも ICPC の集塵機の容積を大きくし,人手でゴミを捨てる回数を減らしたい. しかしながら ICPC が大型化すればするほど ICPC が円形故に部屋の隅の掃除できない部分...
[ { "submission_id": "aoj_2258_2589625", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <complex>\n#include <vector>\n#include <algorithm>\n#include <cmath>\nusing namespace std;\n\nconst int nrep = 50;\n\n/********************* Geometry Library *****************/\nconst double EPS = 1e-9;...
aoj_2257_cpp
桜詩 願はくは花の下にて春死なむ English text is not available in this practice contest. Nathan O. Davis は集積回路コースの学生である. Nathan は足りない単位を補充するために,日本文化に関する授業を履修している.今日の課題は詩の作成である. Nathan は勉強不足で日本語が不得手なため,プログラムに詩を自動生成させようと考えた.手始めに彼は,日本語の単語の接続辞書を入手した. あとは単語の接続にしたがってランダムな文章を生成するだけである. しかしながら,ランダムに生成された全ての文字列が詩として認められるわけではない. 詩には,いくつかの季語のうち...
[ { "submission_id": "aoj_2257_10867672", "code_snippet": "#include <bits/stdc++.h>\n\n#define REP(i,n) for(int i=0;i<(int)(n);i++)\n#define ALL(x) (x).begin(),(x).end()\n\nusing namespace std;\n\nusing ll = long long;\nusing ld = long double;\n\ntemplate <typename T> T &chmin(T &a, const T &b) { return a = m...
aoj_2267_cpp
問題 I : ビット演算 いよいよ G○○gle Code Jam の世界大会が始まろうとしている. 前では P○tr, t○mek, SnapDrag○n をはじめとする, G○○gle の誇る最強のコーダー達が睨みを利かせている. 妙な動きを見せれば,命はないだろう. 目をつむり,コンテスト開始をじっと待つ. …妙だ,コンテストが始まらない. 目を開けてみると…なんということだ.部屋の全ての人間が,倒れている. いや違う,全てではない.一人の男,wata を除いてだ. wata 「やっと話せるぞ. 久しぶりだな,(iwi)」 (iwi) 「…お前は何者だ? 俺の知る wata は幼なじみ系美少女のはずが…」 wata 「まだそん...
[ { "submission_id": "aoj_2267_8975919", "code_snippet": "#include <bits/stdc++.h>\n#define REP(i,n) for(int i=0; i<(int)(n); ++i)\n\nusing namespace std;\n\ntypedef unsigned uint;\nstring num(uint n){\n stringstream ss;\n ss << n;\n return ss.str();\n}\nstring negative(string expr){\n return \"(~...
aoj_2264_cpp
問題 F : 全域木 今,G○○gle Code Jam の地区大会が始まろうとしている. 左の席に座っている男の ID は wata と言うらしい. 東京大学時代の記憶に,似たような ID の仲間が居た覚えがある. しかし,僕の仲間は一人残さず美少女だったはずだ. 僕の記憶の中の wata は,マトロイドが好きだった. 特に,マトロイド交差が大好きで, 様々なマトロイド達を交差させることに一種の興奮すら覚えると言う少し変わった奴だった. マトロイドの理論の力を使えば, 与えられたグラフ上で辺を共有しない複数の全域木を求めることはとても簡単な問題だと言っていた気がする. しかし,特別なグラフに関しては, マトロイドのアルゴリズムを直...
[ { "submission_id": "aoj_2264_8962765", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n int n,k;\n cin >> n >> k;\n if(k>n/2){\n cout << -1 << endl;\n return 0;\n }\n vector<vector<string>> ans(k);\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++){\n int i...
aoj_2261_cpp
問題 C : [[iwi]] そうだ,僕のハンドルネームは (iwi) だ. 僕は確かに昔にプログラミングコンテストに参加していた. そして,多くの仲間と楽しい時間を過ごした. 確か,仲間たちは全員,美少女だったような気がする. プログラミングコンテストの世界は,僕のハーレムだったような気がする. G○○gle は,僕のハーレムを奪ったのだ,そうに違いない. 昔の仲間の手がかりをつかむためにも,やはりプログラミングコンテストに出なければならない. G○○gle Code Jam に参加登録することにしよう. 今度の ID には,丸括弧以外の括弧も検討に入れてみよう. 問題 'i', 'w', '(', ')', '{', '}', ...
[ { "submission_id": "aoj_2261_4088642", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n \nbool check(string s){\n int n = s.size();\n bool ok = true;\n for(int i=0;i<n/2;i++){\n if(s[i] == '('){\n ok &= s[n-1-i] == ')';\n }\n else if(s[i] == ')'){\n ...
aoj_2263_cpp
問題 E : ファーストアクセプタンス プログラミングコンテストでは,各問題に関して, その問題を最初に正解した人の名前や正解時間が, ファーストアクセプタンス(最初の正解)として解説等でしばしば言及される. 久しぶりにプログラミングコンテストに参加するとはいえ,予選で落ちるとは到底思えない. ならば,最初のうちは,多少高いスコアを取ることを目指すよりも, ファーストアクセプタンスを多く獲得し,存在をアピールしたほうが良いのではないか. 自分の実力を持ってすれば,各問題を見た瞬間に, その問題を自分が何分で解くことができるかと, その問題が開始後何分で自分以外の参加者によって最初に解かれるかがわかる. これらの情報を用いて, どの程...
[ { "submission_id": "aoj_2263_10222670", "code_snippet": "#include <bits/stdc++.h> \nusing namespace std;\nusing ll=long long;\nusing dll=long double;\nusing pq=priority_queue<int,vector<int>,greater<int>>;\nusing graph=vector<vector<int>>;\n\n#define int ll\n#define db dll\n#define sbt(x) (x).begin(),(x)...
aoj_2262_cpp
問題 D : 停止問題 G○○gle Code Jam は G○○gle 社が年に 1 度開催するコンテストである. 優勝者は G○○gle への入社を許される,世界最高峰のコンテストだ. しかし勿論,それ以外の参加者は帰らぬ者となる. G○○gle Code Jam では自分の好きなプログラミング言語や処理系を使うことができる. 僕は Defunge という自らが開発したプログラミング言語で参加することにした. この言語を使えば,計算困難な問題はおろか,判定不能な問題ですら解決できる気がしている. 問題 与えられるプログラムが停止するかを判定するプログラムを作成せよ. 与えられるプログラムは,以下で説明するプログラミング言語 De...
[ { "submission_id": "aoj_2262_9264727", "code_snippet": "/* _ ____ */\n/* AC U /\"\\ u U /\"___| AC */\n/* \\/ _ \\/ \\| | u */\n/* AC / ___ \\ | |/__ AC */\n/* /_/ \\_\\ \\____| ...
aoj_2266_cpp
問題 H : キャッシュ戦略 今,G○○gle Code Jam の地区大会が始まろうとしている. 斜め右前の席に座っている男の ID は lyrically と言うらしい. 東京大学時代の記憶に,似たような ID の仲間が居た覚えがあるが,僕の仲間は一人残さず美少女だったはずだ. 僕の記憶の中の lyrically は,アルゴリズムの力や実装の力もさながら, 気合で問題に正解することにも定評があった. 例えば,計算量が多少悪いプログラムでも,上手な実装をすることで高速にし, 正解とするようなことも得意としていた. プログラムを高速にする上で,非常に大切になってくるのが, キャッシュメモリとの親和性である. 問題 ブロック毎に読み込...
[ { "submission_id": "aoj_2266_10849099", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\nconst int N = 10005;\nconst int M = N * 4;\n\nint n, m, k;\nint w[N];\nint a[N];\nint lst[N];\n\ntypedef int ftype;\nconst ftype INF = 0x3f3f3f3f;\nint head[N], to[M], nxt[M], to...
aoj_2265_cpp
問題 G : プログラミングコンテストチャレンジブック 今,G○○gle Code Jam の地区大会が始まろうとしている. 前の席に座っている男の ID は omeometo と言うらしい. 後ろの席に座っている男の ID は jellies と言うらしい. 東京大学時代の記憶に,似たような ID の仲間が居た覚えがあるが,僕の仲間は一人残さず美少女だったはずだ. 彼らは,机の上に蟻のイラストが掛かれた本を持っている. あれはもしや…プログラミングコンテストのアルゴリズムを最初に網羅し,今では発売禁止となった伝説の本, 「プログラミングコンテストチャレンジブック」ではないか? 僕は,omeometo がトイレに行ったのを見計らい,...
[ { "submission_id": "aoj_2265_10042900", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n\nbool check3(vector<int> a) {\n //for (int i: a) cout << i << ' '; cout << endl;\n\tsort(a.begin(), a.end());\n\treturn a[2] < a[1] + a[0];\n}\n\nbool check6(vector<int> a) {...
aoj_2269_cpp
問題 K : 巡回セールスマン問題 2011 年のあの頃,まだプログラミングコンテストはとても平和であり, 我々はルールを精読せずに気軽にコンテストに参加していた. しかし,そこに G○○gle の陰謀は迫っていた. ある日,G○○gle によって秘密裏に買収されていた T○pC○der のコンテストは, 人知れずうちにルールが改変されており,命がけのプログラミングコンテストとなっていた. そして僕は,そこで,何も知らず, まっ先に kita_masa のプログラムのオーバーフローを突いたのだ…. (iwi) 「うう…ああ…」 wata 「今やるべきことは自分を攻めることではない.チャンスを無駄にする気か?」 …そういえば,今こいつ...
[ { "submission_id": "aoj_2269_10342595", "code_snippet": "// AOJ #2269 Traveling Salesman Problem\n// 2025.4.2\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int INF = 1e9;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() {\n\tint n = 0; int ...
aoj_2270_cpp
問題 L : L 番目の数字 反乱を嗅ぎつけた多くの G○○gle のコーダーが我々を取り押さえにやってきた. かなりの数だ. その中には,東京大学時代に僕らを優しく指導してくれた先輩たちも多く見受けられる. 残念ながら,今では敵同士だ. wata 「予想以上の数だ…」 (iwi) 「ああ,我々が超高速指数時間アルゴリズムを持っているからと言って,それは彼らにようやく並んだに過ぎない.この数では…」 ?? 「心配要らない!君たち,アルゴリズムをこっちに渡すんだ!」 声がした窓の外を見ると,G○○gle の建物に向きあう集団がいた. 黒の生地に赤で I,緑で ○,黄色で M と書かれた T シャツ … 彼らは I○M か!? そして奇...
[ { "submission_id": "aoj_2270_10978199", "code_snippet": "// #pragma GCC target(\"avx2\")\n// #pragma GCC optimize(\"O3\")\n// #pragma GCC optimize(\"unroll-loops\")\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n// #include <atcoder/all>\n// using namespace atcoder;\n\nusing ll = long long;\n#define r...
aoj_2274_cpp
問題 D 列の構成 問題文 1 から N までの相異なる整数が N / 2 個書かれたカードがいくつか与えられるので,次の条件を満たすような長さ N の数列 seq を 1 つ作って出力して欲しい. seq の各要素は 0 か 1 である. すべてのカードについて以下が成り立つ: カードに書かれた数字を card[1], ..., card[N/2] とする.このときカードに書かれた部分の和: seq[card[1]] + ... + seq[card[N/2]] が N / 8 以上かつ 3N / 8 以下になっている. 例えば, N = 8 でカードが 2 枚渡され,カードに書かれている数字がそれぞれ [1, 2, 7, 8] ...
[ { "submission_id": "aoj_2274_10809100", "code_snippet": "#include<cstdio>\n#include<cstdlib>\n#include<cstring>\n#include<cmath>\n#include<iostream>\n#include<string>\n#include<vector>\n#include<map>\n#include<set>\n#include<list>\n#include<queue>\n#include<deque>\n#include<algorithm>\n#include<numeric>\n#i...
aoj_2276_cpp
問題 F ボ〜ル 問題文 2 次元平面上の原点にボールがあり, x 軸の正方向との角度が反時計回りに見て 0 度 180 度までの間の方向に一様な確率で発射されようとしている (発射される方向は整数角であるとは限らない).ボールの大きさは十分小さく,平面上では点であると見なすことにする.この問題における目的は,このボールをできるだけ高い確率で捕獲することである. 平面上に N 個の場所 (x i , y i ) が与えられる.ボールを捕獲するために,あなたは N 個の場所から K 個の場所を選んで,それぞれの場所に人を配置することができる.人は i 番目の与えられた場所に対して半径 r i 以内の距離まで動いてボールを取ることが出来...
[ { "submission_id": "aoj_2276_4339412", "code_snippet": "#define _USE_MATH_DEFINES\n#include <bits/stdc++.h>\nusing namespace std;\n#define FOR(i,m,n) for(int i=(m);i<(n);++i)\n#define REP(i,n) FOR(i,0,n)\n#define ALL(v) (v).begin(),(v).end()\nusing ll = long long;\nconst int INF = 0x3f3f3f3f;\nconst ll LINF...
aoj_2268_cpp
問題 J : 乱択平衡分二分探索木 ところで,G○○gle Code Jam の地区大会で右の席に座っていた男の ID は rng_58 と言うらしい. 東京大学時代の記憶に,似たような ID の仲間が居た覚えがあるが,僕の仲間は一人残さず美少女だったはずだ. 彼女はいわゆる無表情不思議系キャラだったような気がする. ということは,彼は知らない男だ.rng とは何の略だろう. おそらく Random Number Generator に違いない. 乱択アルゴリズムを得意とするのだろう. ところで,乱数を用いた平衡二分探索木である Treap は, 2011 年頃のプログラミングコンテストではしばしば用いられていたようだが, 20XX...
[ { "submission_id": "aoj_2268_10307688", "code_snippet": "// AOJ #2268 Randomized Self-Balancing Binary Search Tree\n// 2025.3.17\n\n#include <bits/stdc++.h>\nusing namespace std;\n\ntemplate <typename R>\nvoid fft(vector<complex<R>> &f, int dir) {\n int n = f.size();\n assert(n == (1 << static_cast<in...
aoj_2278_cpp
問題 H あばれうなぎ 問題文 きつねのしえるはうなぎを食べるのが好きである. 2T+1 枚の鉄板が連続して並んでおり,順番に -T, -T+1, ..., T の番号が付いている.しえるはこれらの鉄板に熱を加え,生きたうなぎを焼こうとしている.うなぎを焼く手順は以下のようなものである. まず,時刻 t=-1 のときに各鉄板にどれだけのエネルギーを加えるかを決め,実際にエネルギーを加える.各鉄板に加えるエネルギーの総和は E 以下でなければならない.すなわち, i 番の鉄板に加えるエネルギーを E(i) として, E(i) ≥ 0, E(-T)+...+E(T) ≤ E でなければならない.なお,エネルギーは整数でなくてもよい. エ...
[ { "submission_id": "aoj_2278_4376010", "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 100005\n\nin...
aoj_2282_cpp
Problem B: B問題 R大学の2D好きの人たち (2DRespecters)は、A津大学で開催されるプログラミングの練習合宿に参加する。 この練習合宿では、参加者たちが自作のプログラミング問題を持ち寄り、練習に用いる。 2DRespectersも、いくつかの問題を作成することになった。 しかし、合宿の3日前になっても、まだ、B問題が完成していなかった。 最初のB問題の担当者が作成した問題は、担当者が問題の制約を難しくし過ぎてしまったため、C問題以降にまわされてしまったのだ。 そして、簡単すぎても、難しすぎてもいけない、微妙な難易度の調整が必要とされるB問題は、誰もが手を付けたがらなかった。 それ以来、B問題担当者の椅子は空席...
[ { "submission_id": "aoj_2282_1960392", "code_snippet": "#include <bits/stdc++.h>\n#define f first\n#define s second\nusing namespace std;\nint n,m,a[1001];\ntypedef pair <int,int> P;\ntypedef pair<P,int> PP;\n\nint solve(){\n PP t[1001];\n t[0]=PP(P((m/a[0])*a[0],a[0]),0);\n for(int i=1;i<n;i++){\n so...
aoj_2280_cpp
問題 J Mod 3 Knights Out 問題文 ある日の夕方,コンテストの問題を解き終えた二人は今日の問題について話し合っていた. A「くそー,あのライツアウトの問題,mod 2 じゃなくて mod 3 とか mod 7 とかだったら解法分かったのにー!」 B「じゃあ,mod 3 で別の方法で解く問題を作ればいいんですね.分かりました!」 こうして次のような問題が誕生した. H × W のチェス盤がある.チェス盤の各マスには 0 から 2 の整数が書かれている.このチェス盤にナイトを置いていく.ただし,各マスには多くても 1 体のナイトしか置けない.各マスについて, (マスの数値+そこを攻撃するマスにいるナイトの数)=0 mo...
[ { "submission_id": "aoj_2280_10433362", "code_snippet": "// AOJ #2280 Mod 3 Knights Out\n// 2025.4.30\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int MOD = 1000000007;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tdo n = 10*n + (c & 0xf)...
aoj_2275_cpp
問題 E Fox Number 問題文 きつねのしえるは数字について考えるのが好きである.ある日,しえるはこの世にねこの数字というものがあることを知り,自分もそのような数字が欲しくなってしまった.そこで,次の性質を満たす数字をとりあえず Fox Number と呼ぶことにした. [性質]: 整数 N は k (≥ 1) 個の素数 p 1 , ..., p k と正整数 e 1 , ..., e k で, p 1 < ... < p k , e 1 ≥ ... ≥ e k を満たすものによって N = p 1 e 1 × ... × p k e k と書けるとき,Fox Number であると呼ぶことにする. ところでしえるはこの性...
[ { "submission_id": "aoj_2275_4301948", "code_snippet": "#include <iostream>\n#include <cmath>\n#include <numeric>\n#include <algorithm>\n#include <deque>\n#include <vector>\n#include <unordered_map>\n#include <unordered_set>\n#include <iomanip>\n#include <map>\n#include <stack>\n#include <queue>\n#include <...
aoj_2277_cpp
問題 G XOR 回路 問題文 計算機科学実験及演習 3 は CAD を用いて CPU を設計する授業である.CPU は多くの回路を組み合わせなければ動かず,その中の 1 つに n ビット入力の XOR 回路がある.ここで XOR 回路とは,入力ビット列 x 1 x 2 ...x n に対して, x 1 + x 2 + ... + x n \ (mod 2) を出力する回路のことを言う.しかし完璧に動作する XOR 回路を設計するのは時間がかかるので,とりあえず n ビットのうち k ビットだけ使う XOR 回路 A を作ることにした.つまり,ある i 1 , ... , i k が存在し,回路 A は x i 1 + x i 2 ...
[ { "submission_id": "aoj_2277_10851253", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint n, k, qq[10005], ans[10005];\n\nint ask(int lf = 0, int rg = n - 1){\n cout << \"?\";\n for(int i = 0; i < n; i ++)\n cout << ((lf <= i && i <= rg) ? qq[i] : 0);\n cout << endl;\n\n...
aoj_2283_cpp
Problem C: Seishun 18 Kippu R大学のとある学生sirokurostoneはA津大学で行われる合宿に参加しようとしていた。 他のメンバーは新幹線を使用する予定なのだが、sirokurostoneは青春18切符を使って向かおうとしていた。 同じく青春18切符使いのとある2D好きな人物も合宿に参加しようとしていた。 どうせならと一緒に行こうと考えたsirokurostoneは途中の駅で2D好きな彼を拾って向かおうと考えた。 sirokurostoneはR大学を出る前に遅延状況を確認してすこしでも時間のかからないルートを通ってA津大学のある駅に着きたいと考えている。 sirokurostoneはルートが確定した後...
[ { "submission_id": "aoj_2283_9847642", "code_snippet": "#include <iostream>\n#include <vector>\n#include <map>\n#include <set>\n\nusing namespace std;\nusing ll = long long;\n\nconst ll INF = static_cast<ll>(1) << 62;\n\nvoid solve() {\n ll n, m; cin >> m;\n string s, t, f; cin >> s >> t >> f;\n ma...
aoj_2284_cpp
Problem D: 伝説の剣 ※ この問題には厨二成分が多く含まれます。胸焼けにご注意ください。 ついに復活を遂げた魔王は、再び世界を闇に包むために人間界に攻め入ろうとしていた。 魔王は、本格的な侵攻を始める前に、まず伝説の剣を破壊することにした。 前回の戦争において、魔王は伝説の剣を持つ勇者によって倒された。 魔王の体は闇の衣によって守られているため、生半可な攻撃では魔王を傷つけることはできない。 しかし、伝説の剣は、神々の加護により、魔王の闇の衣すら容易に貫いてしまう。 そのため、今回の戦争に勝利するためには、なんとしてもその伝説の剣を手に入れて破壊する必要がある。 調査の末、伝説の剣はとある遺跡の最奥に安置され、次代の勇者が...
[ { "submission_id": "aoj_2284_7936801", "code_snippet": "#include <algorithm>\n#include <cstdlib>\n#include <cstring>\n#include <iostream>\n#include <map>\n#include <queue>\n#include <vector>\nusing namespace std;\n#define fr first\n#define sc second\ntypedef pair<int, int> P;\nP s, g;\ntypedef pair<P, P> Q;...
aoj_2279_cpp
問題 I 山 問題文 L 氏はある都市の市長である.L 氏の市長としての手腕はすさまじく時を止め一瞬にして都市中に鉄道網を引いたり,財政の赤字を一夜にして莫大な黒字にしたり,はては巨大な怪獣をどこからともなく呼んでパフォーマンスに使うこともした. そんな L 氏は土地の隣り合った行または列同士を何度も入れ替えることででこぼこな土地を山形にするという遊びを最近発明した.土地は H×W 個のブロックに区切られており,ブロック (y,x) では海面からの高さが h y,x であると測定されている.入れ替え後のブロック (y,x) の高さを h' y,x と書くことにする.この土地が山形であるとは,以下の図のように,あるブロック (y^*,...
[ { "submission_id": "aoj_2279_10215449", "code_snippet": "// AOJ #2279\n// Mountain 2025.2.13\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*n...
aoj_2285_cpp
Problem E: アニペロ 猛暑が続いた、長かったようで短かったような夏がもうすぐ終わろうとしていた。 そんな8月下旬のある日、とある2D好きな人物とその先輩のslipは、アニペロサマーライブ、通称アニペロと呼ばれるイベントに参加していた。 アニペロとは、さまざまなアニメソングアーティストたちが集結する、日本国内最大のアニメソングライブイベントである。 今年のアニペロは、公式で公表されていたアーティストの他に、シークレットで超豪華歌手も出演し、大盛況の内に幕を閉じた。 アニペロには初参戦だった2D好きな彼は、ライブ後の余韻にひたりつつも、ひとつの疑問を抱えていた。 「アニペロに出演するアーティストはどのように決めているのだろうか...
[ { "submission_id": "aoj_2285_9658651", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define N 110\n\nint limit, n, m, x;\nint e1[N], s1[N];\nint e2[N], s2[N];\nint dp[1010][N][N];\nint ep[1010];\n\nint main(){\n\twhile (1){\n\t\tcin >> limit >> n >> m >> x;\n\t\tif (limit == 0 && n == 0 ...
aoj_2288_cpp
Problem H: Oh, My Goat! 太郎君は、次郎君に古文のノートを借りた。 明日の古文の宿題を写させてもらうためだ。 太郎君は、用心深い性格をしているため、万が一のことを考えて、近所のコンビニで次郎君のノートのコピーを取って自宅へ帰った。 太郎君は、自宅で宿題を始めようとしたときに、慌てた。 次郎君から借りたノートが鞄に入っていなかったからだ。 どうやら、コンビニに忘れてきてしまったようだ。 太郎君は、急いでコンビニに引き返した。 コピー機とその周辺を懸命に捜索したが、ノートを見つけることはできなかった。 困り果てた太郎君は、コンビニの店長に助けを求めた。 余談だが、店長は地球環境に優しい人で、白ヤギさんを飼っている。...
[ { "submission_id": "aoj_2288_10339676", "code_snippet": "// AOJ #2288 Oh, My Goat!\n// 2025.3.31\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int MOD = 1000000007;\n\ntypedef vector<vector<pair<char,int>>> Automaton;\n\npair<Automaton, int> buildAutomaton(int n, int m, vec...
aoj_2286_cpp
Problem F: Farey Sequence slipは数字を眺めるのが好きである。 ファイルをダウンロードしているときの、残り時間を眺めているだけで、時間を潰せるほどである。 そんなslipが友人から面白い数列を教えられた。 その数列の定義は以下のとおりである。 一般項を F n と表わす。 F n とは、 n 以下の分母を持つ0以上1以下のすべての約分された分数(既約分数)を小さな順から並べたものである。 ただし、整数0、1はそれぞれ分数0/1、1/1として扱われる。 つまり F 3 は、 F 3 = (0/1, 1/3, 1/2, 2/3, 1/1) のように表される。 F 5 であれば F 5 = (0/1, 1/5,...
[ { "submission_id": "aoj_2286_11042230", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing ld = long double;\nusing vi = vector<int>;\nusing vvi = vector<vector<int>>;\nusing vvvi = vector<vector<vector<int>>>;\nusing vll = vector<ll>;\nusing vvll = vector<vector...
aoj_2290_cpp
A: Attack the Moles ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,もぐらたたきを何回も行って,反射神経と記憶力を高めようというものである.出てくるもぐらを次々に叩き,出来るだけ多くのポイントを獲得したい. もぐらが出てくる可能性のある場所は直線状に並んでいて,基準点からの距離によって座標が定まっている.うさぎはしばらく修行を続けるうちに,もぐらの出現する場所と時間が常に一緒であることに気が付いた.うさぎは,その情報をすべて記録し,コンピュータで解析を行うことにした. もぐらを叩くには,もぐらの出現位置に手を動かした後,もぐらの出て...
[ { "submission_id": "aoj_2290_9372895", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <map>\n#include <queue>\n#include <set>\nusing namespace std;\ntypedef long long ll;\n#define rep(i, n) for(int i = 0; i < (n); i++)\n\ntemplate<class T>\nusing vi = vector<T>;\n\nt...
aoj_2295_cpp
F: Power of Power ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,非常に大きな数の計算を行って,計算力をつけて意識を高めようというものである.大きい数が簡単に出てくる演算として,累乗が挙げられる. N 個の非負整数 A 1 , A 2 , ..., A N がある.これらの並べ替え B 1 , B 2 , ..., B N であって, B 1 B 2 ... B N - 1 B N が最大になるものを求めたい.うさぎたちにとってはもちろん常識であるが,この計算は右上から順に行う.また,0 0 = 1 であると約束することにする. 最大...
[ { "submission_id": "aoj_2295_2389243", "code_snippet": "#include <bits/stdc++.h>\n#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)\n#define REP(i,n) FOR(i,0,n)\n#define ALL(x) begin(x),end(x)\n\nusing namespace std;\nusing ld = long double;\n\nvector<int> solve2(const vector<int>& v) {\n int n = v.size();\...
aoj_2292_cpp
C: Common Palindromes ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,文字列中にある回文を探すことによって,文章から隠れたメッセージを読解する能力を高めようというものである.回文はたくさんあるかもしれないので,探すついでに個数も数えてしまいたい. 2 つの文字列 S , T が与えられるので,以下を満たす整数の組 ( i , j , k , l ) の個数を求めたい. 1 ≤ i ≤ j ≤ ( S の長さ). 1 ≤ k ≤ l ≤ ( T の長さ). S の i 文字目から j 文字目までを取り出した部分文字列は, T の k...
[ { "submission_id": "aoj_2292_9777583", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconst long long MOD = 10000000000000099;\nconst long long BASE = 1333;\nconst int MAXN = 5 * 100000;\n\nlong long POWER[MAXN + 1];\n\nlong long mul(long long a, long long b) {\n return ((__int128_t)a...
aoj_2294_cpp
E: Entangled with Lottery ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,あみだくじを利用して,未来を読む力をつけて運気を高めようというものである.もちろん直感に頼るだけでなく,綿密な確率計算も欠かせない. 今回考えるあみだくじは,長さ H + 1 センチメートルの縦棒 N 本からなる.うさぎは棒の上部を見て, N 本のうち 1 本を選ぶことになる.棒の下部には,左から P 本目の棒の場所にのみ「当たり」と書かれている.あみだくじにはいくつかの横棒が含まれる.横棒の配置に関して,以下の条件を考えよう. 各横棒は, a を 1 ...
[ { "submission_id": "aoj_2294_10189840", "code_snippet": "// AOJ #2294\n// Entangled with Lottery 2025.2.4\n\n#include <bits/stdc++.h>\nusing namespace std;\nconst double EPS = 1e-14;\n\nint main(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n int H, N, P, M, K;\n cin >> H >> N >> P >> M >> K;\n\...
aoj_2298_cpp
I: Starting Line ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,一直線上の道を走って,体力と判断力を養おうというものである.うさぎは今,スタートラインに立って長い長い道を見渡している. 道の途中にはいくつかニンジンが置かれており,うさぎはニンジンを食べると加速することができる.加速していないときのうさぎの走る速さは毎秒 U メートルであるが,ニンジンを食べることで,最後のニンジンを食べてから T 秒後までは速さが毎秒 V メートルとなる.また,うさぎはニンジンを K 個まで食べずに持っておくことができる.ニンジンを持っていても走る速さ...
[ { "submission_id": "aoj_2298_7149956", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n int N, K, T, U, V, L;\n cin >> N >> K >> T >> U >> V >> L;\n vector<int> D(N), G(L + 1, -1), S(L + 1);\n for(int i = 0; i < N; i++){\n cin >> D[i];\n G[D[i]] = i;\n S[D[i]]++;...
aoj_2293_cpp
D: Dangerous Tower ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,積み木を丁寧に積み上げることによって,決してミスタイピングをしないほどの手先の器用さを手に入れようというものである.せっかく積み木がたくさんあるので,高い塔を作ろう. 積み木は N 個あり, i 番目 (1 ≤ i ≤ N ) の積み木は 1 × A i × B i の直方体の形をしている.長さ 1 の辺は奥行き方向に用いて,長さ A i , B i の辺を横方向と高さ方向に 1 つずつ割り当てることにした.積み木を積み上げるとき,上の段の積み木は下の段の積み木より横...
[ { "submission_id": "aoj_2293_10946082", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconstexpr int INF = 1e9;\n\nusing pii = pair<int, int>;\n\nstruct edge {\n int to, cap, cost, rev;\n};\n\nusing edges = vector<edge>;\nusing graph = vector<edges>;\n\nvoid add_edge(graph& g, int fro...
aoj_2291_cpp
B: Brilliant Stars ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,夜空に輝くたくさんの星たちを観測して,視力と集中力を鍛えようというものである.うさぎは独自のセンスで星の特徴を記録していくことができる. うさぎは「星の観測日記」として記録した星の特徴をノートにつけていくことにした.ここで,「似ている」 2 つの星をともに記録することは避けたい.2 つの星が「似ている」かどうかは,すべてうさぎの判断で決まっている.「似ている」かどうかの関係はあまり複雑ではなく,以下の条件を満たす. 条件: 異なる 4 つの星 A, B, C, D が...
[ { "submission_id": "aoj_2291_10866253", "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_2296_cpp
G: Quest of Merchant ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,街を駆け回り交易を行うことで,商売の力を手にしようというものである. 今後の修行のためにも,できるだけ多くの資金を稼ぎたい. この世界は,東西南北方向の道路が等間隔に並んでいて,碁盤状になっている.唯一存在する市場の位置を (0, 0),街には x 座標, y 座標が定まっている (座標が整数値の点が交差点に対応する).うさぎは道路に沿ってのみ移動することができ,隣接する交差点間を移動するのに 1 分を要する.いくつかの交差点には街がある.交易では,街で商品を買い...
[ { "submission_id": "aoj_2296_10366916", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <cassert>\n#include <vector>\n#include <algorithm>\n#include <utility>\n#include <numeric>\n// #include \"Src/Utility/BinarySearch.hpp\"\n// #include \"Src/Sequence/CompressedSequence.hpp\"\n// #includ...
aoj_2297_cpp
H: Rectangular Stamps ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,絵を描くことによって,創造力を高めようというものである.四角いスタンプを用いて,上手く模様を描こう. 大小さまざまなスタンプを使い,4 × 4 のマス目の紙に指定された赤・緑・青の通りの絵を完成させたい.スタンプは長方形であり,マス目にぴったり合わせて使う.スタンプの縦と横を入れ替えることはできない. 紙は最初色が塗られていない状態にある.紙にスタンプを押すと,押された部分がスタンプの色に変わり,下に隠れた色は全く見えなくなる.スタンプの色は付けるインクにより決...
[ { "submission_id": "aoj_2297_9995285", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define all(v) (v).begin(),(v).end()\n#define pb(a) push_back(a)\n#define rep(i, n) for(int i=0;i<n;i++)\n#define foa(e, v) for(auto&& e : v)\nusing ll = long long;\nconst ll MOD7 = 1000000007, MOD998 = 9...
aoj_2299_cpp
J: Tiles are Colorful ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. 今日の修行は,流行りのパズルをすばやく解いて,瞬発力を鍛えようというものである.今日挑戦するのは,色とりどりのタイルが並んでいてそれらを上手く消していくパズルだ 初期状態では,グリッド上のいくつかのマスにタイルが置かれている.各タイルには色がついている.プレイヤーはゲーム開始後,以下の手順で示される操作を何回も行うことができる. タイルが置かれていないマスを 1 つ選択し,そのマスを叩く. 叩いたマスから上に順に辿っていき,タイルが置かれているマスに至ったところでそのタイルに...
[ { "submission_id": "aoj_2299_9394837", "code_snippet": "#include <iostream>\n#include <vector>\n#include <stack>\n#include <set>\n#include <map>\n#include <algorithm>\n#include <string>\n#include <cctype>\n#include <cmath>\nusing namespace std;\nusing ll = long long;\nconst long long INF = (1LL<<60);\nconst...
aoj_2300_cpp
Calender Colors Taro is a member of a programming contest circle. In this circle, the members manage their schedules in the system called Great Web Calender . Taro has just added some of his friends to his calendar so that he can browse their schedule on his calendar. Then he noticed that the system currently displays...
[ { "submission_id": "aoj_2300_11047158", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<int, 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 = ...
aoj_2301_cpp
Sleeping Time Miki is a high school student. She has a part time job, so she cannot take enough sleep on weekdays. She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her. She is now trying to figure that out with the following algorithm: Begin with the numbers K , ...
[ { "submission_id": "aoj_2301_10958607", "code_snippet": "#include<bits/stdc++.h>\ntemplate <class T>\ninline bool rd(T &ret) {\n char c; int sgn;\n if(c=getchar(),c==EOF) return 0;\n while(c!='-'&&(c<'0'||c>'9')) c=getchar();\n sgn=(c=='-')?-1:1;\n ret=(c=='-')?0:(c-'0');\n while(c=getchar...
aoj_2302_cpp
On or Off Saving electricity is very important! You are in the office represented as R \times C grid that consists of walls and rooms. It is guaranteed that, for any pair of rooms in the office, there exists exactly one route between the two rooms. It takes 1 unit of time for you to move to the next room (that is, the...
[ { "submission_id": "aoj_2302_10858089", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <iostream>\n#include <algorithm>\n#include <queue>\n#include <vector>\nusing namespace std;\ntypedef long long ll;\n\nconst int dx[]={1,0,0,-1};\nconst int dy[]={0,1,-1,0};\n\nconst int N = 55;\nqueue<in...
aoj_2306_cpp
Rabbit Party A rabbit Taro decided to hold a party and invite some friends as guests. He has n rabbit friends, and m pairs of rabbits are also friends with each other. Friendliness of each pair is expressed with a positive integer. If two rabbits are not friends, their friendliness is assumed to be 0. When a rabbit i...
[ { "submission_id": "aoj_2306_10690753", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nint N, M, ST, gans, ans, hg1, ohg1;\nint jiyou[120][120], val[200], oval[300];\nbool used[1000];\n\nint getans()\n{\n\tint i, res = 0, nc = 0;\n\tf...
aoj_2303_cpp
Marathon Match N people run a marathon. There are M resting places on the way. For each resting place, the i -th runner takes a break with probability P_i percent. When the i -th runner takes a break, he gets rest for T_i time. The i -th runner runs at constant speed V_i , and the distance of the marathon is L . You ...
[ { "submission_id": "aoj_2303_10853140", "code_snippet": "#include<bits/stdc++.h>\ntemplate <class T>\ninline bool rd(T &ret) {\n char c; int sgn;\n if(c=getchar(),c==EOF) return 0;\n while(c!='-'&&(c<'0'||c>'9')) c=getchar();\n sgn=(c=='-')?-1:1;\n ret=(c=='-')?0:(c-'0');\n while(c=getchar...
aoj_2307_cpp
Palindrome Generator A palidrome craftsperson starts to work in the early morning, with the clear air allowing him to polish up his palindromes. On this morning, he is making his pieces to submit to the International Contest for Palindrome Craftspeople. By the way, in order to make palindromes, he uses a special dicti...
[ { "submission_id": "aoj_2307_10836481", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <iostream>\n#include <algorithm>\n#include <vector>\n#include <set>\n#include <map>\n#include <cmath>\n#include <sstream>\n#include <iomanip>\n#include <queue>\n#include <ctime>\nusing namespace std;\nte...
aoj_2311_cpp
問題文 お菓子の魔女 CHARLOTTE は 巴マミ とクッキーゲームを楽しんでいる.クッキーゲームは 8\times 8 の格子状に区切られたテーブルクロスの上にチーズクッキーとチョコレートクッキーを置いて行われる.各格子には高々 1 個のチョコレートクッキーまたはチーズクッキーしか置くことはできない. お菓子の魔女はチーズクッキーを, 巴マミ はチョコレートクッキーを交互に置いてゲームを行う.自分のクッキーを置いたあと,そのクッキーから上下左右斜めの各 8 方向について,置くクッキーとすでに置いていた自分のクッキーの間に相手のクッキーのみが直線に並んでいた場合に,その挟まれた相手のクッキーのすべてが自分のクッキーで置き換えられる...
[ { "submission_id": "aoj_2311_3524913", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <string>\n#include <vector>\n#include <stack>\n#include <queue>\n#include <set>\n#include <bitset>\n#include <map>\n#include <tuple>\n#include <unordered_set>\n#include <unordered_map>\n#include <list...
aoj_2305_cpp
Beautiful Currency KM country has N kinds of coins and each coin has its value a_i . The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins. A currency system is called beautiful if each coin has an ...
[ { "submission_id": "aoj_2305_10867796", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <algorithm>\n#include <cmath>\nusing namespace std;\ntypedef long long ll;\nconst double inf = 1e15;\nconst double eps = 1e-8;\nconst int N = 25;\nconst int M = 200005;\nint a[N], n;\ndouble ans, dp[N][...
aoj_2309_cpp
Vector Compression You are recording a result of a secret experiment, which consists of a large set of N -dimensional vectors. Since the result may become very large, you are thinking of compressing it. Fortunately you already have a good compression method for vectors with small absolute values, all you have to do is ...
[ { "submission_id": "aoj_2309_9813617", "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_2310_cpp
〜魔女からこの世界を守るため キュゥべえ と共に戦う 5 人の魔法少女達の物語〜 問題 A 問題文 薔薇園の魔女 GERTRUD は幅 W メートル,高さ H メートルの長方形の庭でバラを育てている.庭は一辺 1 メートルの正方形で区切られており, W\times H のブロックに分けられている.各ブロックはバラが育てられているか育てられていないかのどちらかである. ただ驚くべきことに,この庭で育てられているバラはブロックを越えて絡み合い 1 つの生命体となっている.この生命体は辺を共有しているブロック間を越えて絡み合うことができ,どこかある 1 点を共有していれば同じ生命体となる. 巴マミ は庭の左下の角から直線に必殺技「ティロ・...
[ { "submission_id": "aoj_2310_10851592", "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_2308_cpp
White Bird Angry Birds is a mobile game of a big craze all over the world. You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver. You are describing a routine that optimizes the white bird's strategy to defeat a pig (enemy) by hitting an egg bomb. The white bir...
[ { "submission_id": "aoj_2308_5846707", "code_snippet": "/*\tauthor: Kite_kuma\n\tcreated: 2021.09.01 15:05:47 */\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_2315_cpp
問題文 影の魔女 ELSAMARIA はすべてのものに対して祈りを続ける魔女である.影に捕まったあらゆる命はこの魔女の中に引きずり込まれてしまう. 影は触手のように動き 美樹さやか を引きずり込もうと狙っている. 美樹さやか はこの魔女に捕まることなく攻撃するために,魔女にとって予測の難しいでたらめな動きをすることを考えた.具体的には,まず頭の中で 1 から N までの整数を一様な確率で K 個作り,その合計値の距離だけ今の位置から魔女の方向へジャンプする,ということを繰り返すのである.そして魔女の位置に到達した時に攻撃するのである. さやか と魔女はある一直線上にいるとし,最初魔女は座標 0 , さやか は座標 S の位置にいるも...
[ { "submission_id": "aoj_2315_8371789", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nvector<vector<long double> > matmul(int N, const vector<vector<long double> >& mat1, const vector<vector<long double> >& mat2) {\n\tvector<vector<long double> > res(N, vector<long double>(N));\n\tfor (i...
aoj_2313_cpp
問題文 ハコの魔女 H.N.ELLY はとある動画サイトの熱狂的なファンである.ハコの魔女の強さはその時々のその動画サイトからの転送速度に応じて変化するのではないかと 美樹さやか は考えた.そこで動画サイトからハコの魔女の持つコンピュータまでの過去の転送速度 (=単位時間あたりのデータの転送量) を調べたい. 初期のインターネットのネットワークの構造とそれ以降のネットワークの構造の変化を表すクエリが与えられるので,各変化について変化した直後の動画サイトからハコの魔女の持つコンピュータまでの転送速度を求めよ. インターネットは複数の転送装置からなるものと見なし,各々をつなぐ回線は双方向に情報を送ることができ,その転送速度の最大は 1 ...
[ { "submission_id": "aoj_2313_9805512", "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_2314_cpp
問題文 落書きの魔女 ALBERTINE は W 列 H 行の正方形のセルからなる長方形の結界の入り口に落書きをしている.この世界では落書きは必ずセルを白色か黒色で塗ることによって成り立つ. すでに使い魔 ANJA の手によって落書きの一部が描かれているのだが,落書きの魔女は残りすべてのセルを塗り落書きを完成させたい.落書きの魔女にはあるこだわりがある.そのこだわりとは次のようなものである. 2 つの異なるセルが辺を共有するとき, 2 つのセルは隣接していると呼ぶことにする.完成された落書きにおいては,任意の 2 つの黒いセルについて,片方からもう片方への隣接した黒いセルをたどるパスがちょうど 1 つだけ存在していなければならない....
[ { "submission_id": "aoj_2314_10712143", "code_snippet": "// AOJ #2314 Scribbling witch\n// 2025.5.30\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int MAX = 11;\n\nint h, w;\nchar B[MAX][MAX+1];\nmap<ll,int> memo[MAX][MAX];\nchar mapto[16];\nint nxt(ll, int, int, char);\n\n...
aoj_2318_cpp
問題文 キュゥべえ はワルプルギスの夜に向けて魔女の合成に明け暮れている.ワルプルギスの夜のために,特別な グリーフシード (魔女の卵) を使って手に入れやすい魔女をうまく合成し目的である舞台装置の魔女を創り上げなければならないからである. キュゥべえ は手に入れやすい種類の魔女の グリーフシード から魔女の素となるものを取り出し,空の特別な グリーフシード に入れることで,その グリーフシード に魔女を宿らせることができる.また,この世界には,ある組み合わせで複数の魔女を合成すると新たな 1 つの魔女を生み出すことができるという合成法則がいくつかある.そこで,いくつかの特別な グリーフシード を使い,それらの中にある魔女の素となる...
[ { "submission_id": "aoj_2318_9799752", "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_2317_cpp
問題文 委員長の魔女 PATRICIA は,蜘蛛のような糸を吐き結界の中で暮らしている.使い魔の MATHIEU は,委員長の魔女が吐いた糸を引っぱり自在に空を飛んでいる.糸は空間上の線分とみなすことにする. 暁美ほむら は委員長の魔女に対して攻撃を仕掛けようとし,爆弾と間違えて花火玉を投げ込んでしまった.その結果,それぞれの糸について,魔女から距離 p_1, ..., p_M の位置にある部分が切れるだけとなってしまった.花火玉を投げる前,それぞれの糸について,糸の 2 つの端点と魔女はこの順番で同一直線上に並んでおり,端点のどちらか一方を使い魔が引っ張っていた.爆発で糸は切れ,使い魔が持っていた部分とそこから一つ置きの部分を残し...
[ { "submission_id": "aoj_2317_5550696", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst int INF = 1100000000;\nint main(){\n int N, M;\n cin >> N >> M;\n vector<int> s(N), t(N);\n for (int i = 0; i < N; i++){\n cin >> s[i] >> t[i];\n }\n vector<int> p(M);\n for (int i = 0; i ...
aoj_2319_cpp
問題文 キュゥべえ はなかなか契約を結んでくれない 鹿目まどか にしびれを切らせて,ソウルジェムゲームと称して 佐倉杏子 と 美樹さやか のソウルジェムの中身 (魂) を W 列 H 段のロッカーの中に隠してしまった.そこで, まどか は 杏子 と さやか を助け出したい.しかし,契約を結ばずに助けるにはロッカーボックスの壁を操作して 2 人のソウルジェムの中身を,指定されたロッカーボックスに正しく移さなければならない.ロッカーはロッカーボックスが W 列 H 段に並ぶことで構成され,隣り合うロッカーボックスは壁で仕切られている. まどか は, 1 回の操作でいずれかの隣りあった 2 つのロッカーボックスの壁を取り除くか取り付けるこ...
[ { "submission_id": "aoj_2319_5955599", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing uint = unsigned int;\nusing ull = unsigned long long;\n#define rep(i,n) for(int i=0;i<int(n);i++)\n#define rep1(i,n) for(int i=1;i<=int(n);i++)\n#define per(i,n) for(int i=int...