group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_0732_cpp
いちご 2 (Strawberry 2) 問題文 果物好きのビ太郎は,いちごのつかみ取りに挑戦することにした.ビ太郎の目の前には 1 脚の机がある.机は長方形の形をしており,縦 H 行,横 W 列のマス目状に区切られている.机には N 個のいちごが置かれており, i 番目 ( 1 ≦ i ≦ N ) のいちごは上から A i 行目,左から B i 列目のマスにある.複数のいちごが同じマスに置かれている可能性もある. ビ太郎は机から,縦 3 行,横 3 列の正方形の領域をなす 9 個のマスを選び,それらのマスにあるいちごをすべて取る.この動作は 1 回だけ行う. ビ太郎は,なるべく多くのいちごを取りたい. 机の大きさといちごの位置につ...
[ { "submission_id": "aoj_0732_10881893", "code_snippet": "#include <iostream>\n#include <vector>\n#include <map>\n#include <algorithm>\nusing namespace std;\n\nint main() {\n int H, W, N;\n cin >> H >> W >> N;\n\n vector<pair<int, int>> strawberries(N);\n for (int i = 0; i < N; ++i) {\n in...
aoj_0751_cpp
日本沈没 2 (Japan Sinks 2) 問題文 日本列島は東西に細長い列島である.日本列島は南北方向の境界線により N 個の区画に分けられている.区画には西から順に 1 から N までの番号が付けられている.現在,区画 i ( 1 ≦ i ≦ N ) の標高は A i m である. 日本列島ではたびたび嵐が起きている.嵐が起きると波による浸食で各区画の標高が以下のように減少する. 強さ x の 西風の 嵐では,西から数えて x 個以内の区画のうち,「それより西に自身より標高の高い区画が存在しない」ようなすべての区画の標高が 1 m 減少する.すなわち,嵐の前の区画 i の標高を a i で表すと, i ≦ x かつ, 1 ≦ ...
[ { "submission_id": "aoj_0751_10575051", "code_snippet": "/* import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint n = sc.nextInt();\n\t\tint q = sc.nextInt();\n\n\t\tint[] A = new int[n + 1];\n\n\t\tfor (int i = 1;...
aoj_0750_cpp
貨物列車 (Freight Train) 問題文 IOI 鉄道は 1 本の鉄道路線を運営している.IOI 鉄道線には一直線上に並んだ N 個の駅があり,順に 1 から N までの番号が付けられている.各 i ( 1 ≦ i ≦ N - 1 ) に対して,駅 i と駅 i + 1 の間は線路で結ばれており,その長さは 1 である. IOI 鉄道は貨物を取り扱っている.駅 2, 3, …, N には貨物が 1 つずつ置かれており,駅 i ( 2 ≦ i ≦ N ) に置かれている貨物の価値は A i である. IOI 鉄道は貨物列車を 1 編成所有している.この列車は最初駅 1 におり,IOI 鉄道線上を双方向に走行できる.それぞれの駅...
[ { "submission_id": "aoj_0750_9662876", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n#define FOR(i,l,r) for(ll i=l;i<r;i++)\n#define REP(i,n) FOR(i,0,n)\n#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)\n#define RREP(i,n) RFOR(i,0,n)\nint main(){\n ll n,w,d;cin>>n>>w>>d...
aoj_0762_cpp
タイピング大会 (Typing Contest) 問題文 JOIG 国では JOIG 語が使用されており,JOIG 語では文字 A , B , C , D , E , F , G , H , I , J , K , L , M , N , O の 15 種類の文字が用いられる. 来月 JOIG 国で開催されるタイピング大会では,JOIG 語で用いられる 15 種類の文字からなる長さ N の文字列 S を入力するのにかかる時間を競う.この大会では,参加者は以下の条件でタイピングを行う. 参加者は, 1 本の指を使ってタイピングをする. 参加者は, 15 種類の文字のキー 1 つずつを 1 列に並べた,左右に細長いキーボードを使用する....
[ { "submission_id": "aoj_0762_9666432", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef vector<ll> vi;\ntypedef vector<vi> vvi;\ntypedef vector<vvi> vvvi;\n#define FOR(i,l,r) for(ll i=l;i<r;i++)\n#define REP(i,n) FOR(i,0,n)\n#define RFOR(i,l,r) for(ll i=r-1;i>=l...
aoj_0749_cpp
塗りつぶし (Painting) 問題文 JOI くんはお絵かきソフトで遊んでいる. お絵かきソフトでは,縦 H 行,横 W 列の長方形のマス目に絵を描くことができる.それぞれのマスには色が定められており,色は 1 以上 10 9 以下の整数で表される. 上から i 行目 ( 1 ≦ i ≦ H ),左から j 列目 ( 1 ≦ j ≦ W ) のマスをマス (i,j) と呼ぶ.現在,マス (i,j) の色は A i,j である. マス (i,j) から辺で接しているマスへの移動を繰り返し,マス (i,j) と色が異なるマスに入ることなく移動できるマスの集まりを,ここでは マス (i,j) の領域 と呼ぶ. お絵かきソフトには, ...
[ { "submission_id": "aoj_0749_9662779", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n#define FOR(i,l,r) for(ll i=l;i<r;i++)\n#define REP(i,n) FOR(i,0,n)\nint main(){\n int h,w;cin>>h>>w;\n vector<vector<ll>>a(h,vector<ll>(w));\n REP(i,h)REP(j,w)cin>>a[i][j];...
aoj_0760_cpp
コイン集め 2 (Coin Collecting 2) 問題文 机の上に,縦 H 行,横 W 列の長方形状にコインが並べられている. 最初,上から i 行目 ( 1 ≦ i ≦ H ),左から j 列目 ( 1 ≦ j ≦ W ) のコインは, S i,j = # のとき表面, S i,j = . のとき裏面が見えている状態である. 葵と凛は,これらのコインを用いてゲームを行うことにした.ゲームは以下のような流れで行われる. 葵がどれか 1 つの行を選び,その行のコインをすべてひっくり返す. 凛がどれか 1 つの列を選び,その列のコインをすべてひっくり返す. 葵が,表面が見えるコインをすべて獲得する.また凛が,裏面が見えるコインをす...
[ { "submission_id": "aoj_0760_9727722", "code_snippet": "#include \"bits/stdc++.h\"\n\n#define REP(i,num) for(ll i=0;i<(num);++i)\n#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))\n#define LOOP(i) while(i--)\n#define ALL(c) c.begin(),c.end()\n#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pi...
aoj_0761_cpp
運河 (Canal) 問題文 JOIG 王国は H 行 W 列のマス目に区切られた長方形の形をしている.上から i 行目 ( 1 ≦ i ≦ H ),左から j 列目 ( 1 ≦ j ≦ W ) のマスをマス (i,j) と呼ぶ. 各マスには標高と呼ばれる整数が定まっている.マス (i,j) の標高は A i,j である. JOIG 王国では,王国を縦断する運河を建設することにした.運河の建設は,以下のように行われる. ある整数 k ( 1 ≦ k < W ) を定める.左から k 列目と k+1 列目の間に,王国の上端から下端まで縦断する運河を建設する. 運河を横切らず,辺で接している標高が同じマスへの移動を繰り返すことで相互に移...
[ { "submission_id": "aoj_0761_9666396", "code_snippet": "#include <vector>\n#include <string>\n#include <deque>\n#include <tuple>\n#include <climits>\n#include <numeric>\n#include <iostream>\n#include <iomanip>\n#include <random>\n#include <cfloat>\n#include <set>\n#include <queue>\n#include <cmath>\n#includ...
aoj_0747_cpp
年齢の差 (Age Difference) 問題文 JOI 市には 1 から N までの番号が付けられた N 人の住民がおり,住民 i ( 1 ≦ i ≦ N ) の年齢は A i 歳である. JOI 市の住民の年齢 A 1 , A 2 , …, A N が与えられる. i = 1, 2, …, N に対して,住民 i と他の住民との年齢の差の最大値を求めるプログラムを作成せよ. 制約 2 ≦ N ≦ 250 000 . 0 ≦ A i ≦ 10 9 ( 1 ≦ i ≦ N ). 入力される値はすべて整数である. 入力 入力は以下の形式で与えられる. N A 1 A 2 … A N 出力 N 行出力せよ. i 行目 ( 1 ≦ i ...
[ { "submission_id": "aoj_0747_10879938", "code_snippet": "//NOAC 25..\n#include <bits/stdc++.h>\n\n#define endl \"\\n\"\n#define sline cout << endl\n#define ll long long\n#define ull unsigned long long\n#define fi int i =\n#define fj int j =\n\nusing namespace std;\n\nint main() {\n int N;\n cin >> N;\...
aoj_0778_cpp
庭園 2 (Garden 2) 問題文 JOI 庭園は縦 N 行,横 N 列のマス目状に区切られた正方形の形をしている. 上から i 行目 ( 1 ≦ i ≦ N ),左から j 列目 ( 1 ≦ j ≦ N ) のマスは区画 (i, j) と呼ばれている. JOI 庭園は土壌にあまり恵まれていないため,各区画には特定の 1 種類の色の花を, 最大 1 本しか植えることができない. 具体的には,区画 (i, j) には A i, j = R のとき赤, A i, j = Y のとき黄, A i, j = B のとき青の色の花を最大 1 本しか植えることができない. ここで,この庭園の管理者である K 理事長は,航空写真を撮った時の見...
[ { "submission_id": "aoj_0778_10827791", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconstexpr int MAXN = 3505;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n int N;\n cin >> N;\n\n vector<string> A(N + 2, string(N + 2, '#')); // 1-indexed, 周囲を番兵で...
aoj_0748_cpp
ジョイ四人組 (JOI04) 問題文 JOI 中学校には 4N 人の一年生が在籍しており, 4 つのクラスに分かれている.各クラスの情報は以下の通りである. 1 年 A 組: N 人の生徒がいる.それぞれの生徒の身長は A 1 , A 2 , …, A N である. 1 年 B 組: N 人の生徒がいる.それぞれの生徒の身長は B 1 , B 2 , …, B N である. 1 年 C 組: N 人の生徒がいる.それぞれの生徒の身長は C 1 , C 2 , …, C N である. 1 年 D 組: N 人の生徒がいる.それぞれの生徒の身長は D 1 , D 2 , …, D N である. 来月,JOI 中学校では体育祭が開催される...
[ { "submission_id": "aoj_0748_10882878", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include<utility>\n#include<set>\n#include<deque>\n#include <unordered_map>\n#include<string>\n#include<map>\n#include<cmath>\n\nusing namespace std;\n\n\nconst long long INF = 1LL << 60;\n...
aoj_0779_cpp
高速道路の通行料金 (Highway Tolls) 問題文 JOI 王国は N 個の都市からなる王国であり,これらの都市には 1 から N までの番号が付けられている. JOI 王国には,これらの都市を結ぶ 一方通行 の高速道路が M 本あり, 1 から M までの番号が付けられている. 高速道路 i ( 1 ≦ i ≦ M ) を通ると都市 A i から都市 B i に移動することができ,通行にかかる時間は L i である. それぞれの高速道路を通るたびに,通行料金が発生する. 高速道路 i の通行料金は最も安い時で C i だが,JOI 王国の労働者は皆時間外労働を嫌うため,ある基準となる時刻 0 から離れれば離れるほど通行料金...
[ { "submission_id": "aoj_0779_10827794", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nconstexpr ll INF = LLONG_MAX / 4;\n\ntemplate <class T>\ninline bool chmin(T &a, const T &b) {\n if (a > b) { a = b; return true; }\n return false;\n}\n\nstruct Edge {\n ...
aoj_0759_cpp
鐘 (Bell) 問題文 JOI 市には 1 本の十分に長い道路がある.この道路は数直線とみなすことができ,各地点は 1 個の実数による座標で表される. また,JOI 市にはこの道路に沿って N 個の鐘があり,座標の小さい順に 1 から N までの番号が付けられている.鐘 i ( 1 ≦ i ≦ N ) は座標 A i にある. JOI 市では, 1 年の終わりにこれらの鐘を一斉に鳴らすのが一大イベントとなっている. どの鐘も,鳴らすとその鐘と同じ地点では強さ K の音で聞こえるが,距離が 1 離れるごとに聞こえる音の強さは 1 小さくなり,距離が K 以上離れると 0 になる.すなわち,鐘 i を鳴らしたとき,座標 x で聞こえる...
[ { "submission_id": "aoj_0759_10807001", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n int N, M;\n long long K;\n cin >> N >> M >> K;\n\n vector<long long> A(N);\n for(int i = 0; i < N; i++) cin >> A...
aoj_0787_cpp
座席 2 (Seats 2) 問題文 JOI 国では,今年プログラミングの世界大会が開かれることとなった.大会には N 人の選手が参加予定であり,選手には 1 から N までの番号が付けられている. 各選手の出身国は 1 以上 10 9 以下の整数の番号で表され,選手 i ( 1 ≦ i ≦ N ) の出身国は国 C i である. N 人の選手の出身国がすべて同じであることはない. また,各選手の座席は直線状に並んでおり,選手 i ( 1 ≦ i ≦ N ) の座席は位置 X i にある.選手 i ( 1 ≦ i ≦ N ) と選手 j ( 1 ≦ j ≦ N ) の 座席の距離 は |X i - X j | である.ただし, |x...
[ { "submission_id": "aoj_0787_10827800", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Seat {\n long long country, x;\n int idx;\n bool operator<(const Seat &o) const {\n if (x != o.x) return x < o.x;\n return country < o.country;\n }\n};\n\nint main() {\...
aoj_0776_cpp
買い物 2 (Shopping 2) 問題文 JOI 商店には N 個の商品があり,商品には 1 から N までの番号が付けられている. それぞれの商品には, 定価 と 種類 が定められている.商品 i ( 1 ≦ i ≦ N ) の定価は P i 円である.商品の種類は 1 以上 M 以下の整数で表され,商品 i ( 1 ≦ i ≦ N ) の種類は A i である. JOI 商店は,セールを行うことにした.セールは M 日間続き, j 日目 ( 1 ≦ j ≦ M ) には種類 j の商品をすべて定価の半額で買うことができる. セールの期間中に, Q 人の客が JOI 商店を訪れた.客には 1 から Q までの番号が付けられてい...
[ { "submission_id": "aoj_0776_11042720", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n int n, m, q;\n cin >> n >> m >> q;\n\n vector<long long> P(n + 1, 0);\n vector<int> A(n + 1);\n vector<vector<lo...
aoj_0790_cpp
感染シミュレーション (Infection Simulation) 問題文 EGOI 食堂には昨日 N 人の客が来店した. 客には 1 から N までの番号が付けられており,客 i ( 1 ≦ i ≦ N ) の来店時刻は L i ,退店時刻は R i であった. そして今日,客のうち 1 人が,現在 JOI 国で流行している新型の感染症 X に感染した状態で来店したことが明らかになった. 感染症 X の 感染しづらさ は整数 x で表される. 具体的には, 1 ≦ i ≦ N について,客 i が 1 人以上の感染者と同時に食堂内にいた時間の累計が x 以上となったタイミングで,客 i は新たに感染者となる. さて,JOI 国では...
[ { "submission_id": "aoj_0790_10907773", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n int n; cin >> n; vector<int> B;\n vector<pair<int,int>> A(n); for (auto& [a,b]:A) (cin >> a >> b),B.emplace_back(b);\n sort(B.begin(),B.end()),B.erase(unique(B.begin(),B.end()),B.end()...
aoj_0788_cpp
たくさんの数字 (Many Digits) 問題文 JOI 高校の葵さんは, N 行 N 列のマス目の各マスに整数を十進数表記で書くことにした.具体的には上から i 行目 ( 1 ≦ i ≦ N ),左から j 列目 ( 1 ≦ j ≦ N ) のマスには A i + B j を十進数表記で書く. 葵さんは数字を何文字書くことになるかを知りたい.つまり,葵さんが書く N 2 個の整数の桁数の合計を求めたい. A i ( 1 ≦ i ≦ N ) と B j ( 1 ≦ j ≦ N ) が与えられたとき,葵さんが書く N 2 個の整数の桁数の合計を求めるプログラムを作成せよ. 制約 1 ≦ N ≦ 150 000 . 1 ≦ A i ≦...
[ { "submission_id": "aoj_0788_10827803", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n int N;\n cin >> N;\n vector<ll> A(N), B(N);\n for (int i = 0; i < N; i++) cin >> A[i];\n ...
aoj_0775_cpp
カードゲーム 2 (Card Game 2) 問題文 ビ太郎は N 枚のカードを持っており, i 枚目 ( 1 ≦ i ≦ N ) のカードには整数 A i が書かれている. これらの中から次の条件を満たすような 3 枚のカードを選びたい. 条件: 選んだカードに書かれている整数が 3 ずつ離れている. 厳密には,選んだカードに書かれている整数が,ある整数 x を用いて x, x+3, x+6 と表せる. 例えば,ビ太郎が 5 枚のカードを持っており,それぞれに 2, 4, 5, 7, 10 が書かれているとき, 4, 7, 10 が書かれているカードを選ぶと,条件を満たす. ビ太郎が持っているカードの情報が与えられたとき,条件を満...
[ { "submission_id": "aoj_0775_11040880", "code_snippet": "#include <iostream>\nusing namespace std;\n\nint main() {\n\tint n;\n\tbool a[200006] = {\n\t\t0\n\t};\n\tcin >> n;\n\tfor (int i = 0; i < n; i++) {\n\t int k;\n\t\tcin >> k;\n\t\ta[k] = true;\n\t}\n\tfor (int i = 0; i < 200000; i++) {\n\t\tif (a[i...
aoj_0789_cpp
名前 (Name) 問題文 JOI 君と IOI 君は犬を飼うことにした.最初にすべきことは,犬の名前を決めることである.二人で話し合った結果,犬の名前を以下の 4 つの条件を満たすものにすることにした. 条件 1 名前は英大文字 ( A , B , ..., Z ) と英小文字 ( a , b , ..., z ) からなる文字列である. 条件 2 JOI 君の好きな文字列は長さ N の文字列 S であるから, S が名前の部分列となるようにする. 条件 3 IOI 君の好きな文字列は長さ M の文字列 T であるから, T が名前の部分列となるようにする. 条件 4 名前を呼びやすいものにするため,同じ文字の間には別の文字が K...
[ { "submission_id": "aoj_0789_10573174", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int INF = 1000000000;\ninline void chmin(int &a, int b) { if (a > b) a = b; }\nint baseVals[8] = {0, 1, 4, 5, 16, 17, 20, 21};\nint bitCount[8] = {0, 4, 4, 6, 4, 6, 6, 7};\n\...
aoj_1017_cpp
Problem I: Riffle Shuffle There are a number of ways to shuffle a deck of cards. Riffle shuffle is one such example. The following is how to perform riffle shuffle. There is a deck of n cards. First, we divide it into two decks; deck A which consists of the top half of it and deck B of the bottom half. Deck A will ...
[ { "submission_id": "aoj_1017_1912894", "code_snippet": "#include<iostream>\n#include<queue>\nusing namespace std;\nqueue<int>Q[3]; int p, q;\nvoid solve(int a) {\n\tfor (int i = 0; i < 1000; i++) {\n\t\tif (Q[i % 2].size() < a) {\n\t\t\twhile (!Q[i % 2].empty()) { Q[2].push(Q[i % 2].front()); Q[i % 2].pop()...
aoj_1010_cpp
Problem B: Dominoes Arrangement [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 western dominoes as shown in the above ...
[ { "submission_id": "aoj_1010_9453300", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\ntypedef vector<ll> vi;\ntypedef vector<vi> vvi;\ntypedef vector<vvi> vvvi;\ntypedef vector<bool> vb;\ntypedef vector<vb> vvb;\ntypedef vector<vvb> vvvb;\ntyp...
aoj_1002_cpp
Extraordinary Girl (I) She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since...
[ { "submission_id": "aoj_1002_1827294", "code_snippet": "#include<iostream>\n#include<vector>\n#include<string>\n#include<algorithm>\n#include<map>\n#include<set>\n#include<utility>\n#include<cmath>\n#include<cstring>\n#include<queue>\n#include<cstdio>\n#include<sstream>\n#define loop(i,a,b) for(int i=a;i<b;...
aoj_1015_cpp
Problem G: Dominating Set What you have in your hands is a map of Aizu-Wakamatsu City. The lines on this map represent streets and the dots are street corners. Lion Dor Company is going to build food stores at some street corners where people can go to buy food. It is unnecessary and expensive to build a food store on ...
[ { "submission_id": "aoj_1015_2698281", "code_snippet": "#include <stdio.h>\n#include <cmath>\n#include <algorithm>\n#include <cfloat>\n#include <stack>\n#include <queue>\n#include <vector>\n#include <string>\n#include <iostream>\n#include <set>\n#include <map>\n#include <time.h>\ntypedef long long int ll;\n...
aoj_1008_cpp
What Color Is The Universe? On a clear night, a boy, Campanella looked up at the sky, there were many stars which have different colors such as red, yellow, green, blue, purple, etc. He was watching the stars and just lost track of time. Presently, he wondered, "There are many stars in the space. What color is the univ...
[ { "submission_id": "aoj_1008_10850942", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nint main()\n{\n for (int t, n, r, i; cin>>n, n; printf(~r ? \"%d\\n\" : \"NO COLOR\\n\", r))\n {\n std::map<int, int> c;\n r = -1;\n for (i = 0; i++<n; r = ++c[t]> n / 2 ? t : r)\n ...
aoj_1019_cpp
Problem A: Vampirish Night There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount f...
[ { "submission_id": "aoj_1019_10853907", "code_snippet": "#include <stdio.h>\nint s[200],b[200][200],sum[200];\nint main()\n{\n int i,j,n,k;\n bool flag;\n while(scanf(\"%d%d\",&n,&k)==2)\n {\n if(n==0&&k==0)break;\n for(i=1;i<=k;i++)\n {\n scanf(\"%d\",&s[i]);\n ...
aoj_1016_cpp
Problem H: Fibonacci Sets Fibonacci number f ( i ) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule f ( i ) = f ( i - 1) + f ( i - 2), where we set f (0) = 1 = f (-1). Let V and d be two certain positive integers and be N ≡ 1001 a c...
[ { "submission_id": "aoj_1016_5581180", "code_snippet": "#include <iostream>\nusing namespace std;\n\nconst int MAXN = 1001;\n\nint P[MAXN], F[MAXN], V, D;\nvoid init(int N) { // 初期化 はじめは全ての頂点はバラバラ\n for (int i=0; i<=N; ++i) P[i] = i;\n}\nint root(int a) { // a の root(代表元) を求める\n if (P[a] == a) return ...
aoj_1025_cpp
Problem G: Building Water Ways In ancient times, Romans constructed numerous water ways to supply water to cities and industrial sites. These water ways were amongst the greatest engineering feats of the ancient world. These water ways contributed to social infrastructures which improved people's quality of life. On th...
[ { "submission_id": "aoj_1025_1315022", "code_snippet": "#include<bits/stdc++.h>\n\n#define REP(i,s,n) for(int i=s;i<n;i++)\n#define rep(i,n) REP(i,0,n)\n#define _3_ 1\n\nusing namespace std;\n\ntypedef unsigned long long ull;\ntypedef pair<int,int> ii;\n\nstruct Point { int x,y; };\n\nconst int IINF = INT_M...
aoj_1022_cpp
Problem D: Indian Puzzle In the Indian Puzzle, one is intended to fill out blanks with numbers and operators in a n by n grid in order to make equalities in the grid true (See Figure 1). Figure 1 A blank cell should be filled out with a number (from 0 to 9 inclusive) or an operator ( + , - , × , ÷ , = ), and black cell...
[ { "submission_id": "aoj_1022_10853930", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <map>\n#include <string>\n#include <queue>\nusing namespace std;\n#define SZ(v) ((int)(v).size())\nconst int maxint = -1u>>...
aoj_1004_cpp
Pair of Primes We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this: 1 2 3 4 5 6 7 8 9 . . . N N . . . 9 8 7 6 5 4 3 2 1 Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime. Input Inp...
[ { "submission_id": "aoj_1004_10848139", "code_snippet": "#include <iostream>\n#include <string.h>\n#include <stdio.h>\n#include <vector>\n#include <list>\n#include <math.h>\n#include <algorithm>\nusing namespace std;\n\npair<int, int> pii[10005];\nint N, answer;\nbool isPrime(int n) {\n if (n == 1) retur...
aoj_1023_cpp
Problem E: Amazing Graze In 2215 A.D., a war between two planets, ACM and ICPC, is being more and more intense. ACM introduced new combat planes. These planes have a special system that is called Graze, and fighting power of a plane increases when it is close to energy bullets that ICPC combat planes shoot. Both comba...
[ { "submission_id": "aoj_1023_10958610", "code_snippet": "/*\n * Author: OldY\n * Created Time: 2011/8/31 16:30:04\n * File Name: E.cpp\n */\n#include <algorithm>\n#include <cmath>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <deque>\n#include <iostream>\n#include <map>\n#include <qu...
aoj_1027_cpp
Problem I: A Piece of Cake In the city, there are two pastry shops. One shop was very popular because its cakes are pretty tasty. However, there was a man who is displeased at the shop. He was an owner of another shop. Although cause of his shop's unpopularity is incredibly awful taste of its cakes, he never impro...
[ { "submission_id": "aoj_1027_2004163", "code_snippet": "#include<bits/stdc++.h>\n#define rep(i,n)for(int i=0;i<n;i++)\nusing namespace std;\n\nint main() {\n\tint k;\n\twhile (cin >> k, k) {\n\t\tint sum = 0;\n\t\trep(i, k*(k - 1) / 2) {\n\t\t\tint c; cin >> c; sum += c;\n\t\t}\n\t\tcout << sum / (k - 1) <<...
aoj_1029_cpp
Problem A: Traffic Analysis There are two cameras which observe the up line and the down line respectively on the double lane (please see the following figure). These cameras are located on a line perpendicular to the lane, and we call the line 'monitoring line.' (the red line in the figure) Monitoring systems are conn...
[ { "submission_id": "aoj_1029_6047634", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\nint main()\n{\n int n, m;\n\n while (cin >> n >> m, n || m)\n {\n vector<int> time;\n int tmp, ans = 0;\n for (int i = 0; i < n + m; i...
aoj_1026_cpp
Problem H: Hedro's Hexahedron Dr. Hedro is astonished. According to his theory, we can make sludge that can dissolve almost everything on the earth. Now he's trying to produce the sludge to verify his theory. The sludge is produced in a rectangular solid shaped tank whose size is N × N × 2. Let coordinate of two cor...
[ { "submission_id": "aoj_1026_10853956", "code_snippet": "/*\n * Author: tender\n * Created Time: 2011/9/5 13:02:29\n * File Name: h.cpp\n */\n#include <iostream>\n#include <algorithm>\n#include <cmath>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <deque>\n#include <map>\n#include <q...
aoj_1030_cpp
Problem B: Cubes Without Holes There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure. Then, 次に、上図(右)に示すように、印のついた表面から、反対の面まで水平または垂直に貫通する穴をあける。 あなたの仕事は、 n と 印の位置を読み込み、穴の空いていない小さい立方体の個数を数えるプログラムを作成することである。 Input 入力はいくつかのデ...
[ { "submission_id": "aoj_1030_10852651", "code_snippet": "#include<set>\n#include<cstdio>\n#include<cstring>\n#include<iostream>\n#include<algorithm>\nusing namespace std;\nint n,m;\nset<int> s;\nint Hash(int x,int y,int z)\n{\n return x*n*n+y*n+z;\n}\nint main()\n{\n while(scanf(\"%d%d\",&n,&m)!=EOF&&...
aoj_1033_cpp
Problem E: Kuru-Kuru Robot ロボット工学の研究者であるアシモフ博士は、新しいロボットの開発に成功した。このロボットは、床に張り巡らせた特殊なワイヤーに沿って自由に動くことができる。ロボットは常に現在いるワイヤーに平行な方向を向いて前進する。 すばらしいことに、このロボットはワイヤー上を移動するためにその距離にかかわらずエネルギーを消費しない。しかし、ワイヤーの端点やワイヤーの交点で向きを変えるためにはその点を中心に回転する必要があり、その回転角度だけエネルギーを消費する。 このロボットをスタート地点からゴール地点まで動かしたい。例えば、下図においてロボットを start に東向き(下図 x 軸の正の向き)で...
[ { "submission_id": "aoj_1033_2737394", "code_snippet": "#include<bits/stdc++.h>\n#define f first\n#define s second\n#define mp make_pair\n#define pi M_PI\n#define inf 1e14\n#define eps (1e-8)\n#define MAX 1000\n#define equals(a,b) (fabs((a)-(b))<eps)\nusing namespace std;\n \nclass Point{\npublic:\n double...
aoj_1034_cpp
Problem F: Line Puzzle プログラミングでパズルを解いてみよう。 n × n の数字が格子状に並んでいる。数字のいくつかは丸で囲まれており、これらを起点と呼ぶことにする。パズルのルールは以下のとおりである: 各起点から縦・横に進む1本の線を引く(斜めには引けない)。 通った数字の和が起点の数字と同じになるように線を伸ばす。 線は枝分かれしてはいけない。 線はすでに引かれた数字を通ることはできない(線は交差してはいけない)。 線は2個以上の起点を通ることはできない。 下図に示すように、パズルのゴールはすべての起点を使い、すべての数字に線を引くことである。 あなたの仕事は、パズルを解くプログラムを作成することである。...
[ { "submission_id": "aoj_1034_8051261", "code_snippet": "#include <algorithm>\n#include <functional>\n#include <iostream>\n#include <map>\n#include <stdio.h>\n#include <string>\n#include <vector>\nusing namespace std;\n\ntypedef long long ll;\n#define rep(i, n) for (int i = 0; i < (n); i++)\ntypedef pair<int...
aoj_1032_cpp
Problem D: Course Planning for Lazy Students 会津大学では2009年度より、授業履修に関する新しい制度を開始した。新制度では必修科目を撤廃し、それぞれの進路を考慮して科目を自由に選択できるようになった。 しかし、どの科目も無条件で履修できるわけではなく、特定の科目を履修するためには、先修条件を満たしている必要がある。下図に履修計画表の一部の例を示す: 図の長方形が1つの科目を表し科目名と単位数を含んでいる。図の矢印が先修条件を表す。矢印の意味は、矢印の終点で指されている科目を履修するためには、その矢印の始点を示す科目を修得している必要がある。例えば、Linear Algebra II (線...
[ { "submission_id": "aoj_1032_3993527", "code_snippet": "#include <iostream>\n#include <vector>\n#include <array>\n#include <list>\n#include <string>\n#include <stack>\n#include <queue>\n#include <deque>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <tuple>\n#i...
aoj_1038_cpp
Problem D: Dr. Nakamura's Lab. Dr.中村は偉大な発明者である, 今日も常人には発想出来ない新たな発明に取り掛かっている. 今発明しているのは新たな防犯システムとコンテナである. 防犯システムの方は上に乗った者を識別して招かれざる客だった場合, 電流を流して気絶させるパネルである. このパネルは踏まないように上を通過しても無駄で, 空中のものに対し放電する. しかし, まだ完成には程遠く, 電流は強すぎて調節が不可能で, 一度放電すると充電しない限り使えない. また, 人と物体の区別ができず, そもそも人自体区別できない等欠点をあげればキリがない. コンテナの方は謎の力によって常時地面から浮いており, ...
[ { "submission_id": "aoj_1038_8051272", "code_snippet": "#include <algorithm>\n#include <climits>\n#include <cmath>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <functional>\n#include <iostream>\n#include <list>\n#include <map>\n#include <numeric>\n#include <queue>\n#include <set>\n#i...
aoj_1037_cpp
Problem C: Midnight Teatime ICPCの国内予選に備えて問題を解いていた僕は, その日3つ目のAcceptを貰ったところでキーボードを叩く手を止めた. 時計を見れば, もう日付が変わろうかという時刻だ. 紅茶とお菓子で一服して, 今日はもう寝ることにしよう. そう思って僕はキッチンへと向かった. ダージリンのかぐわしい香りがキッチンを満たした頃, 妹がやってきた. 受験生である彼女は今日もこんな時間まで真面目に勉強していたようだ. 僕は彼女を誘って, 小さな深夜のお茶会を開くことにした. 都合の良いことに, キッチンには4つのお菓子があった. これをただ2人で分けるのもつまらないので, 僕はこのお菓子を賭...
[ { "submission_id": "aoj_1037_8461531", "code_snippet": "#include <bits/stdc++.h>\n\nconstexpr int ROOT = 0;\nconstexpr int NONE = -1;\n\nstruct BinaryTree {\n static constexpr int N = 10;\n struct Node {\n int left;\n int right;\n int id = NONE;\n\n bool is_child() {\n ...
aoj_1028_cpp
Problem J: ICPC: Ideal Coin Payment and Change Taro, a boy who hates any inefficiencies, pays coins so that the number of coins to be returned as change is minimized in order to do smoothly when he buys something. One day, however, he doubt if this way is really efficient. When he pays more number of coins, a clerk co...
[ { "submission_id": "aoj_1028_10866035", "code_snippet": "/*\n * Author: NomadThanatos\n * Created Time: 2011/8/31 13:51:49\n * File Name: J.cpp\n */\n#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cmath>\n#include <cstdlib>\n#include <algorithm>\n#include <vector>\nusing namespace st...
aoj_1040_cpp
Problem F: Chocolate with Heart Marks 太郎君はチョコレートが大好きで, 学校から帰るとハートマークが描かれたお気に入りの板チョコを食べます, 最近の楽しみは, すべてのハートマークのブロックを最後まで残すように食べることです. 太郎君は, すべてのハートマークのブロックがつながったまま, できるだけ多くのハートマークのないブロックを食べようとします. しかし太郎君はまだ幼く, 上記のように食べようとしても無駄なブロックが残ってしまいます. そこで太郎君は, すべてのハートマークのブロックをつながったまま残すときに食べられる最大のブロック数を求めるプログラムの作成をあなたに依頼しました. 太郎君は...
[ { "submission_id": "aoj_1040_10260991", "code_snippet": "#line 2 \"template.hpp\"\n// #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// https://xn--kst.jp/blog/2019/08/29/cpp-comp/\n// debug methods\...
aoj_1045_cpp
Problem 05: Split Up! 勇者ポン太とその親友同じく勇者ゴン太は、これから壮大な冒険へと出発するために、それぞれ仲間を求めてルイーダの酒場へやって来ました。酒場には、冒険に出たくてうずうずしている武闘家や僧侶、魔法使いがたくさん居ます。 心やさしいゴン太はポン太を気遣い、「先に仲間を選んでいいよ。」と言いました。 一方、ポン太もゴン太が心配でなりません。「いや、君が先に選んでいいよ。」と言い返しました。 お互い譲り合いが続き、ついにルイーダがこう提案しました。「じゃあ、ここにいる n 人の登録者をそれぞれのパーティの合計戦闘力がなるべく均等になるように、この"パーティ分けマシン"で分けてあげるわ。」 あなたに与えら...
[ { "submission_id": "aoj_1045_10397112", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n/*\n 与えられた n 個の整数を 2 つのグループに分け,\n グループ A の合計とグループ B の合計の差の最小値を求める\n ブールマスク全探索による典型的な部分和分割問題の解法。\n*/\n\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n while(true){\n ...
aoj_1046_cpp
Problem 06: Ghost Buster! 一般人には知る由も無いことだが、この街は幽霊で溢れている。そのほとんどは無害なのだが、困ったことに、人を呪う悪霊も少なからずいるのだ。 あるところに、そんな悪霊と戦う少女がいた。彼女は昼間は何食わぬ顔で高校に通いながらも、夜になると街中を歩き回り、彷徨える魂を見付けては成仏させるのだ。 幽霊を成仏させるためにはまずその幽霊に接近する必要があるのだが、それは簡単なことではない。幽霊は物をすり抜けられるからだ。幽霊は民家に壁から侵入して勝手口から出て行ったり、信号の無い大通りを悠々と横断したりする。人間である彼女にはそんなことはできないので、幽霊を追跡するのはとても難しいのだ。 彼女は...
[ { "submission_id": "aoj_1046_9523805", "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) { return (ull)rn...
aoj_1047_cpp
Problem 07: Crop Circle アルゼンチンの広大な農地に突如ミステリーサークルが出没した。ミステリーサークルは重なっているもの、ポツンとあるもの、大きいもの、小さいものと合計 n 個確認された。 あるミステリーハンターが空中からミステリーサークルの全体像を撮影しようと試みたところ、各円の輪郭がはっきりしていなかったため、映像にその美しい模様を映し出すことが難しいことが分かった。 そこで、そのミステリーハンターは輪郭に沿って特殊素材の紐を設置し、輪郭を強調する提案をした。 紐を設置する部分は、あるミステリーサークルの円周上で、他のどのミステリーサークルにも含まれない部分である。 撮影隊は必要な紐の長さを計測するために...
[ { "submission_id": "aoj_1047_6012531", "code_snippet": "#include <cstdio>\n#include <iostream>\n#include <cstring>\n#include <string>\n#include <vector>\n#include <utility>\n#include <queue>\n#include <map>\n#include <set>\n#include <cmath>\n#include <deque>\n#include <algorithm>\n#include <stack>\n#include...
aoj_1048_cpp
Problem 08: Provident Housewife 主婦の琴子はこの不況のさなか食費を抑えることに闘志を燃やしていました。毎朝新聞広告を必ずチェック。買う物リストと最も安く売られているお店をしっかりリストアップして、お店をはしごしながら、エプロン・サンダルという戦闘スタイルで自転車をこぎこぎ買い物に行きます。 そこで夫のあなたは少しでも琴子の役に立とうと、得意のプログラミングで家計簿プログラムを作成することにしました。プログラムは、各スーパーに売っている品物の名前と値段(円)、琴子が必要な品物を入力し、全ての品物を集めるための最小金額を出力します。 琴子は家を出て必要な品物を集め、家に戻ってこなければなりません。 そこで...
[ { "submission_id": "aoj_1048_10397141", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n// 大きな値として INF を定義\nstatic const int INF = 1e9;\n\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n while (true) {\n int n;\n cin >> n;\n if (!cin || n =...
aoj_1039_cpp
Problem E: Frisbee Dogs クレインは, 彼女の愛犬である Jack をフリスビードッグ大会に出場させようとしている. しかし, 彼女は Jack がよい成績を取れるか自信が無い. 彼女のために, 大会をシミュレートして Jack の成績を見積もるプログラムを作成してほしい. この大会は, 2次元平面上にいる N 匹の犬によって行われる. 大会の開始時点において, i 番目の犬は ( D i x , D i y ) の位置にいる. i 番目の犬は V i [m/s] で走ることができ, 全ての犬は十分小さいので点とみなせる. ある時刻に, 2 匹以上の犬が同じ位置にいても構わない. 1枚目のフリスビーの発射をもっ...
[ { "submission_id": "aoj_1039_7077749", "code_snippet": "#ifndef HIDDEN_IN_VS // 折りたたみ用\n\n// 警告の抑制\n#define _CRT_SECURE_NO_WARNINGS\n\n// ライブラリの読み込み\n#include <bits/stdc++.h>\nusing namespace std;\n\n// 型名の短縮\nusing ll = long long; // -2^63 ~ 2^63 = 9 * 10^18(int は -2^31 ~ 2^31 = 2 * 10^9)\nusing pii = pair...
aoj_1049_cpp
Problem 09: Building Houses この秋、割火ハウスは最近開拓が進んでいる松短地区の神暗通り沿いの土地を分譲することにした。 先日募集をかけ、今日は購入者に分譲説明会を開催する。 購入者が説明会場に集まりだしたところ、なんだか空気がとても凍り付いていた。不思議に思った担当者は開催前に 「皆さん新天地を求めてきたというのに、ちょっと表情が暗いですが大丈夫ですか?」 と聞いてみた。そこで思わぬ事実が判明した。実は、購入者全員が現在隣町の集合団地の住人で、あまりにも周辺の人たちと折り合いが合わないため今回引越しをしようと検討していたのだった。 購入者たちはすでに費用を支払済みで以前の住まいを引き払っている。従って、...
[ { "submission_id": "aoj_1049_10397151", "code_snippet": "#include <cstdio>\n#include <algorithm>\n#include <vector>\n#include <climits>\n#include <numeric>\nusing namespace std;\n\n// i を [a,b) の範囲で動かすループマクロ\n#define repi(i,a,b) for(int i=int(a); i<int(b); i++)\n// i を [0,n) の範囲で動かすループマクロ\n#define rep(i,n) ...
aoj_1054_cpp
Problem D: Distorted Love Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal information. The word "privacy" is not in her dictionary. ...
[ { "submission_id": "aoj_1054_710257", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <string>\n#include <sstream>\n#include <cstring>\n#include <cstdlib>\n#include <cstdio>\n#include <cmath>\n#include <queue>\n#include <stack>\n#include <map>\n#include <set>\n#includ...
aoj_1055_cpp
Problem E: Huge Family Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious personality and are close each other. They usually ...
[ { "submission_id": "aoj_1055_2254609", "code_snippet": "#include<bits/stdc++.h>\n#define N 100005\nusing namespace std;\n\ntypedef pair<int,int> P;\n\nvector<P> G[N];\nbool used[N],used2[N];\n\nmap<int,int> cnt;\nset<P> usedP;\n\nvoid dfs(int x){\n \n if(used2[x])return;\n used2[x]=1;\n used[x]=1;\n \n...
aoj_1056_cpp
Problem F: Ben Toh As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box...
[ { "submission_id": "aoj_1056_10848503", "code_snippet": "#include<stdio.h>\n#define stepn 70\ndouble f[100001],g[100001];\n\nint max(int o,int p) {return o>p?o:p;}\nint min(int o,int p) {return o<p?o:p;}\n\ndouble pow1(int o)\n{\n if (o==0) return 1.0;\n if (o==1) return 0.5;\n double ans=pow1(o/2)...
aoj_1059_cpp
Problem I: Mysterious Onslaught In 2012, human beings have been exposed to fierce onslaught of unidentified mysterious extra-terrestrial creatures. We have exhaused because of the long war and can't regist against them any longer. Only you, an excellent wizard, can save us. Yes, it's time to stand up! The enemies are d...
[ { "submission_id": "aoj_1059_10852685", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <cstdlib>\n#include <cmath>\n#include <queue>\n#include <map>\n#include <algorithm>\n#include <vector>\n\nusing namespace std;\n\nstruct Node{\n int val, step;\n};\n\nmap<int, bool> flag;\nqueue<Node>...
aoj_1064_cpp
Problem C: Yanagi's Comic Yanagi is a high school student, and she is called "Hime" by her boyfriend who is a ninja fanboy. She likes picture books very much, so she often writes picture books by herself. She always asks you to make her picture book as an assistant. Today, you got asked to help her with making a comic....
[ { "submission_id": "aoj_1064_3722385", "code_snippet": "#include<iostream>\n#include<vector>\n#include<string>\n#include<cstring>\n#include<iomanip>\n#include<algorithm>\n\nusing namespace std;\n\n#define debug(x) cout<< #x <<\" : \"<< x << endl;\n#define repi(i, x, n) for(int i = x; i < n; i++)\n#define re...
aoj_1060_cpp
Problem J: No Story Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer L , how many pairs of positive integers a , b ( a ≤ b ) such that LCM( a , b ) = L are there? Here, LCM( a , b ) stands for the least common multiple of a and b . Input For ...
[ { "submission_id": "aoj_1060_10848273", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <cstdio>\n#include <cstring>\n#include <cmath>\n#include <vector>\nusing namespace std;\nlong long s;\nint main()\n{\n\twhile(cin>>s&&s)\n\t{\n\t\tvector<int> a;\n\t\tfor(int i=2;i<=s/i;i++)\n\t\t{\n...
aoj_1057_cpp
Problem G: Rolling Dice The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a tear of delight. Now they are enthusiastically pla...
[ { "submission_id": "aoj_1057_6000290", "code_snippet": "#include <iostream>\n#include <queue>\n#include <map>\nusing namespace std;\n#define rep(i,n) for(int i=0;i<n;i++)\nint dx[]={-1,1,0,0},dy[]={0,0,-1,1};\nclass DICE{\npublic:\n\tvector<int> dice;\n\tDICE(){\n\t\tdice.resize(6);\n\t\trep(i,6)dice[i]=i+1...
aoj_1058_cpp
Problem H: Winter Bells The best night ever in the world has come! It's 8 p.m. of December 24th, yes, the night of Cristmas Eve. Santa Clause comes to a silent city with ringing bells. Overtaking north wind, from a sleigh a reindeer pulls she shoot presents to soxes hanged near windows for children. The sleigh she is o...
[ { "submission_id": "aoj_1058_9644503", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nvoid fastIO() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n}\n\n\nconst int oo = 1e9;\nvector<vector<pair<long long, long long>>> adj;\nint n, m;\n\nint getShortestPath(int s...
aoj_1063_cpp
Problem B: Watchin' TVA Animation is one of methods for making movies and in Japan, it is popular to broadcast as a television program or perform as a movie. Many people, especially the young, love one. And here is an anime lover called Jack. We say he is an mysterious guy with uncertain age. He likes anime which are b...
[ { "submission_id": "aoj_1063_10851284", "code_snippet": "/*\n * Author: 8mao\n * Created Time: 2014/3/16 21:55:53\n * File Name: 2155.cpp\n */\n# include<map>\n# include<set>\n# include<cmath>\n# include<queue>\n# include<stack>\n# include<vector>\n# include<string>\n# include<cstdio>\n# include...
aoj_1065_cpp
Problem D: The House of Huge Family Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future. Mr. Dango's family, the huge family, is getting their new house...
[ { "submission_id": "aoj_1065_10915073", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <numeric>\n#include <limits>\nusing namespace std;\n\nlong long stoer_wagner(vector<vector<long long>>& W) {\n int n = (int)W.size();\n vector<int> v(n);\n iota(v.begin(),...
aoj_1074_cpp
Problem A: Popularity Estimation あなたはとあるアニメーション制作会社の企画部長である。昨今のアニメーション制作会社が制作するものは、アニメーションそのものにとどまらない。関連商品、例えば登場キャラクターのフィギュアやキャラクターソングCDなども、重要な収益源なのである。この収益をどれだけ伸ばせるかは、ひとえに企画部長のあなたにかかっているのであった。 当たり前のことだが、こういった関連商品は闇雲に発売すればいいというものではない。商品の開発には多くの時間と予算が必要なためだ。アニメの登場キャラクターのフィギュアを発売するにしても、多くの売上が見込まれる、人気があるキャラクターのものに限らなければなら...
[ { "submission_id": "aoj_1074_1713165", "code_snippet": "#include<bits/stdc++.h>\n#define N 20\n#define M 31\nusing namespace std;\ntypedef pair<string,int> P;\n\nint n,cnt[M],point[N],k,m,tim,minp;\nvector<P> t[N];\nstring s;\n\nint main(){\n while(1){\n cin>>n;\n if(!n)break;\n for(int i=0;i<M;i+...
aoj_1066_cpp
Problem E: Legend of Storia In Storia Kingdom, there is an artifact called "Perfect Sphere" made by a great meister Es. This is handed down for generations in the royal palace as a treasure. Es left a memo and filled mysterious values in it. Within achievements of researches, it has been revealed that the values denote...
[ { "submission_id": "aoj_1066_10851205", "code_snippet": "#include<stdio.h>\n#include<string.h>\n#include<algorithm>\n#include<math.h>\n#define eps 1e-9\n#define PI acos(-1.0)\n#define M 100\nusing namespace std;\n\ntypedef struct N{\n\tdouble x,y;\n\tN(){;}\n\tN(double tx,double ty){\n\t\tx=tx; y=ty;\n\t}\n...
aoj_1067_cpp
Problem F: Cutting a Chocolate Turtle Shi-ta and turtle Be-ko decided to divide a chocolate. The shape of the chocolate is rectangle. The corners of the chocolate are put on (0,0), ( w ,0), ( w , h ) and (0, h ). The chocolate has lines for cutting. They cut the chocolate only along some of these lines. The lines are e...
[ { "submission_id": "aoj_1067_10853288", "code_snippet": "#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <math.h>\n#define MAXN 30050\n#define eps 1e-8\ntypedef struct point {\n double x,y;\n\tpoint (){\n \n\t}\n\tpoint (double xx,double yy){\n x = xx;\n\t\t y = yy;\n\t}...
aoj_1069_cpp
Problem H: Squid Multiplication Squid Eiko loves mathematics. Especially she loves to think about integer. One day, Eiko found a math problem from a website. "A sequence b ={ a i + a j | i < j } is generated from a sequence a ={ a 0 , ... , a n | a i is even if i is 0, otherwise a i is odd}. Given the sequence b , fin...
[ { "submission_id": "aoj_1069_10946367", "code_snippet": "#include <stdio.h>\n#include <string.h>\n#include <stdio.h>\n#include <math.h>\n#include <algorithm>\nusing namespace std;\n#define MAXN 450000\ntypedef long long LL;\nLL b[MAXN];\nLL a[MAXN];\nLL gcd(LL aa,LL bb){\n if(!bb){\n\t\treturn aa;\n\t}\n...
aoj_1073_cpp
Problem L: The Tower Your task is to write a program that reads some lines of command for the following game and simulates operations until the player reaches the game over. We call following 2-dimensional grid of m by n characters Tower. The objective of this game is to move blocks in the tower to climb to a goal bloc...
[ { "submission_id": "aoj_1073_3474912", "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;\n#define F first\n#define S second\n\nvoid INPUT();\nint s_to_i(string z);\n\nstring s[55],com[1000],DIR[1000];\nint x,y...
aoj_1070_cpp
Problem I: FIMO sequence Your task is to simulate the sequence defined in the remaining part of the problem description. This sequence is empty at first. i -th element of this sequence is expressed as a i . The first element of this sequence is a 1 if the sequence is not empty. The operation is given by integer from 0 ...
[ { "submission_id": "aoj_1070_10853989", "code_snippet": "/*************************************************************************\nAuthor: ziki\nCreated Time: 2012-10-5 15:32:35\nFile Name: I.cpp\nDescription: \n************************************************************************/\n#include <vector>\n...
aoj_1068_cpp
Problem G: School of Killifish Jon is the leader of killifish. Jon have a problem in these days. Jon has a plan to built new town in a pond. Of course new towns should have a school for children. But there are some natural enemies in a pond. Jon thinks that the place of a school should be the safest place in a pond for...
[ { "submission_id": "aoj_1068_10848919", "code_snippet": "/*\n * Author: 8mao\n * Created Time: 2014/3/16 20:09:19\n * File Name: 2009.cpp\n */\n# include<map>\n# include<set>\n# include<cmath>\n# include<queue>\n# include<stack>\n# include<vector>\n# include<string>\n# include<cstdio>\n# include...
aoj_1076_cpp
Problem C: Time Manipulation 彼女は見習いの魔法使いだ。 彼女はまず最初に時間を操る魔法を覚えた。 そして彼女は生計を立たせるために酒屋を開くことにした。 彼女の住んでいる国の住人達はみんなお酒が大好き、ということが関係している。 住人達は長い年数をかけて熟成させたお酒が特に好きで、熟成させた年数に応じてその価値も比例して上がる。 50年熟成させたお酒より100年熟成させたお酒のほうが価値が高いのは簡単に想像がつくはずだ。 そして手に入れるのが難しいということも。 彼女は自分の魔法を使って、長い年月熟成させたお酒を一瞬で作って、それを売って収入を得ようとしているのであった。 彼女はお酒を熟成させる年数に応...
[ { "submission_id": "aoj_1076_4079650", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nunsigned long long popcount(unsigned long long x) {\n x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) +\n (x & 0x5555555555555555UL);\n x = ((x & 0xccccccccccccccccUL) >> 2) +\n (x & 0x333333333333333...
aoj_1075_cpp
Problem B: High & Low Cube 僕は近所の小学生たちと一緒に夏祭りに来ていた。有り体に言えば保護者役だが、出店の焼きそばやたこ焼きなんかが焼ける匂い、時折聞こえる打ち上げ花火の音などは、この歳になっても心が踊るものがある。が、好奇心旺盛な子供たちがはぐれないように、今日はしっかり見守っていないと。 子供たちはとある出店に興味を持ったようだった。覗き込んでみると、そこでは出店のおじさんとサイコロを使ったゲームをして、勝てば景品が貰えることになっていた。そのゲームは、 High & Low と呼ばれる単純なものだ。参加者とおじさんは1個ずつサイコロを振るが、その前に参加者は、自分の出目がおじさんの出目より大きいか小...
[ { "submission_id": "aoj_1075_1635615", "code_snippet": "#include <algorithm>\n#include <iostream>\n#include <string>\n#define N 21\n#define T 7\nusing namespace std;\nvoid Change(int);\nvoid Rot_Left();\nint stoi();\nstring s[N],t[T];\n\nint main(){\n int a[2][6],coma,comb,d[2][6][2]={\n {{0,7},{7,0},{7...
aoj_1077_cpp
Problem D: The Great Summer Contest 現在、人々の娯楽はプログラミングコンテストに限られている。彼女が所属しているとある中学校の娯楽部の活動内容は、プログラミングコンテストを企画し運営することだ。彼女の仕事は問題を作成することではない。多くの人から問題を募り、審判団を組織し、またコンテストの宣伝を行う、いわば裏方のお仕事だ。カリスマ作題者や著名なアルゴリズマーと違い、そういった仕事をする人に光が当たることはほとんどない。存在感はないけれども欠かすことのできないその仕事に、彼女は誇りを持って取り組んでいた。 娯楽部は常に問題を募集しているが、それらの問題は以下の 6 種類に分類される。 Math Gr...
[ { "submission_id": "aoj_1077_3911814", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <cstdio>\n#include <cmath>\n#include <cstdlib>\n#include <ctime>\n#include <cctype>\n#include <cstring>\n#include <utility>\n#include <map>\n#include <queue>\nusing namespace std;\n...
aoj_1078_cpp
Problem E: SAT-EN-3 彼女は悩んでいた。成績が良くないのだ。両親に無理を言って全寮制の学校に入学したものの、彼女の才能は一向に開花することはなかった。あるいは才能など元々なかったのかもしれないが、それはできるだけ考えたくない可能性だった。 そこで彼女が頼ったのは、インターネット上で見つけた怪しげな脳力トレーニングの教材だった。SAT-EN-3 (SATisifiability problem for Enhancement of Neuron: version 3) と銘打つその学習メソッドによると、充足可能性問題のようなもののインスタンスをひたすら手で解くことによって、計算力が向上し、引いては論理的思考力・直感力...
[ { "submission_id": "aoj_1078_8461558", "code_snippet": "#include <bits/stdc++.h>\n\nstd::map<std::string, std::string> anti_literal;\n\nstruct Parser {\n using CopyIter = std::string::const_iterator;\n using Iter = CopyIter&;\n std::string line;\n Parser(std::string s): line(s) {}\n void skip...
aoj_1079_cpp
Problem F: Cosmic Market Cosmic market(コズミック・マーケット)、通称コズミケ、は全宇宙最大規模の同人即売会だ。 コズミケにはあらゆるジャンルの同人愛好家達が集う。 近年、コズミケへの来場者は増加傾向にある。 最初から全ての人が入場できると大変混雑して危険なので、開場直後は入場規制を行っている。 ある一定人数の人だけが開場と同時に入場することが出来るのだ。 それ以外の人たちはしばらく待ってからの入場となっている。 しかし先着順に会場に入ることにすると、徹夜で前日から並ぶ人が出てしまう。 コズミケの参加者には未成年も多く、治安上の問題もあるので先着順という決め方はとても良くない。 そういう理由があ...
[ { "submission_id": "aoj_1079_3911787", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\ntypedef pair<ll, ll> P;\n\n#define fi first\n#define se second\n#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)\n#define rep(i,n) repl(i,0,n)\...
aoj_1082_cpp
Problem I: 11224111122411 腕が引っかかって抜けない。 机の裏に転がり込んでしまったものを拾おうとして、懐中電灯代わりに携帯の画面で照らしながら腕を挿し込んでみたが、うっかり何かに引っかかって抜けなくなってしまった。無理に動かすと痛い。 どうしよう。どうすれば脱出できるのだろう。大声で助けを呼ぶか。恥ずかしいので却下したいが、独力で脱出するのは難しそうだ。いや、声の届く範囲には誰もいなかったはずだ。焦る気持ちを押さえて辺りを見渡す。あのパソコンに手が届けばメールで助けを呼べるのだが、あいにく遠すぎる。やはり偶然誰かが通りかかるのを待つしかないのか。 いや待て、メールを送る機械ならあるじゃないか。手の届くところ...
[ { "submission_id": "aoj_1082_3911751", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#define _GLIBCXX_DEBUG\n#include<bits/stdc++.h>\nusing namespace::std;\nstruct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;\n// random_device rd;\n// mt19937 mt(rd());\...
aoj_1084_cpp
Problem A: K Cards ある日、先生は次のようなゲームを思いついた。 ゲームは 1 から 10 までの数がひとつ書かれたカードを n 枚使用し、以下のように進む。 先生が n 枚のカードを数が見えるようにして横一列に黒板に貼り付け、ある整数 k (k ≥ 1) を生徒に宣言する。横一列に並べられた n 枚のカードについて、連続した k 枚のカードの積の最大値を C k とする。また、先生が並べた時点での C k を C k ' とおく。 生徒は 1. で貼られたカードの列を見て C k を大きくすることを考える。ある 2 枚を入れ替えることで C k をより大きくすることができた場合、生徒の成績は C k - C k ...
[ { "submission_id": "aoj_1084_10486236", "code_snippet": "#include \"bits/stdc++.h\"\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#include <ext/pb_ds/tag_and_trait.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusin...
aoj_1081_cpp
Problem H: World domination 世界征服を企む悪の組織、なんてものは、古今東西フィクションノンフィクションを問わず、いろんな所にいるものだが、一体彼らは何のために世界征服をしようとしたのだろうか。そんなことをふと考えてしまうのは、私もまた、世界征服を企てているからであった。私が世界征服を目論む理由はただ一つ、私がロボット工学の分野で世界一優秀であることを世界に示すためである。征服したあとの世界になど興味はない、そこらへんの犬にでもくれてやっても構わないのだ。 誠に遺憾だが、それはつまり、私よりも優秀であるとされている研究者がいる、ということだ。その人物には心当たりがある。誰あろう、私の学生時代の同期 R 博士...
[ { "submission_id": "aoj_1081_1983733", "code_snippet": "#include \"bits/stdc++.h\"\n#include<unordered_map>\n#include<unordered_set>\n#pragma warning(disable:4996)\nusing namespace std;\nusing ld = long double;\ntemplate<class t>\nusing table = vector<vector<t>>;\nconst ld eps = 1e-10;\n\n// < \"d:\\d_downl...
aoj_1083_cpp
Problem J: The Incubator サラリーマンの朝は早い。エリートコースを進み一流企業に入社して新人という肩書きからも卒業する頃、僕に下った辞令は未開の惑星における営業活動だった。辺鄙な土地での不便な生活を強いられているが、一応は左遷でなく栄転であり、その証拠に給料もぐんと上がっている - こんな場所では金なんて使いようもないのだけど。近年僕たちが直面している宇宙規模のエネルギー不足に対応するため、特定の生物種の個体から莫大なエネルギーを生成するテクノロジーが開発された。その特定の生物種というのが、この辺鄙な惑星の固有種なのだ。この生物が絶滅しないように保護しつつ、適度にエネルギーを回収していくのが僕の仕事だ。 エネ...
[ { "submission_id": "aoj_1083_3911977", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#include<bits/stdc++.h>\nusing namespace::std;\nstruct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;\n// random_device rd;\n// mt19937 mt(rd());\n// #include <boost/nume...
aoj_1086_cpp
Problem C: Live Schedule YOKARI TAMURAは全国的に有名なアーティストである。今月YOKARIは D 日間にわたってライブツアーを行う。ツアーのスケジュールの決定においてこの国を C 種類の地域でわける。YOKARIがある地域でライブを行うことにより利益を得られ、これは正の整数で表される。YOKARIは原則として 1 日に最大 1 つまでライブを行う。ただし、ある地域でライブを行った後、隣接する地域でライブを行える場合はその地域で同じ日に再びライブを行うことができる。この条件を満たす限り、地域を移動しながら何度もライブを行うことができる。また、同じ日に同じ地域でライブを 2 度以上行うことはできない...
[ { "submission_id": "aoj_1086_2630538", "code_snippet": "#include <stdio.h>\n#include <cmath>\n#include <algorithm>\n#include <cfloat>\n#include <stack>\n#include <queue>\n#include <vector>\n#include <string>\n#include <iostream>\n#include <set>\n#include <map>\n#include <time.h>\ntypedef long long int ll;\n...
aoj_1085_cpp
Problem B: Spellcasters n 人の魔法使いがいる。彼らには 1 から n までの番号があり、i 番目の魔法使いは魔力 r i ( 1 ≤ i ≤ n ) を持っている。いま彼らは強力な魔法使いと対峙しており、その敵の魔力は S である。n 人の魔法使いは協力して戦うのが得意で、特に 2 人で協力して戦うことを好む。2 人の魔法使いが協力した場合、魔力は単純にその和となり、強力な魔法などを駆使してある程度強い敵にも勝てるようになる。あなたの仕事は魔力 S を持つ敵に対して勝つことができる魔法使いのペア (i, j) ( i ≠ j かつ 1 ≤ i ≤ n かつ 1 ≤ j ≤ n ) の総数を出力することである...
[ { "submission_id": "aoj_1085_9796673", "code_snippet": "#include <stdio.h>\n#include <cmath>\n#include <algorithm>\n#include <stack>\n#include <queue>\n#include <vector>\ntypedef long long int ll;\n\n#define BIG_NUM 2000000000\n\nusing namespace std;\n\nvoid func(int N,int S){\n\n\tint table[N],index = N-1,...
aoj_1080_cpp
Problem G : Everything Starts With Your Vote ヒューリスティクスという言葉がある。確実にうまくいくという保証はないけれども大抵の場合はうまくいく、比較的単純なアプローチのことだ。単純にして強力であるがゆえに、この世の中は多くのヒューリスティクスで満ち溢れている。 ヒューリスティクスの一例として、こんなものが挙げられる。アニメ番組において、あるキャラクターの人気度は、そのアニメ本編中における登場時間の総和に比例する。確かにこれは多くの場合に成り立っているようだ。しかし、どうやら僕は少数派に属するらしい。影の薄いキャラ、背景にちらりと映るモブキャラなんかに限って可愛く見えたりするのだ。 自分の...
[ { "submission_id": "aoj_1080_6372130", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef unsigned int ull;\ntypedef pair<int, int> pil;\nconst ll ll_INF = 0x3f3f3f3f3f3f3f3f;\nconst ll ll_MAX = 0x7fffffffffffffff;\nconst int int_INF = 0x3f3f3f3f;\nconst int int_...
aoj_1087_cpp
Problem D: Dimensional Analysis 量の次元とは、相異なる量の間の関係式から具体的数値を無視して量の種類とそのべき乗だけに着目した概念である。具体的には定数係数を無視した等式として、次元の関係式を表す。すなわち、量 q の次元を[ q ]と表せば、以下のようないくつかの次元の関係式が例示できる。 [面積] = [長さ] 2 [体積] = [長さ] 3 [速さ] = [長さ][時間] -1 [加速度] = [長さ][時間] -2 [力] = [質量][長さ][時間] -2 [仕事] = [質量][長さ] 2 [時間] -2 (Wikipedia 「量」より抜粋 URL http://ja.wikipedia...
[ { "submission_id": "aoj_1087_6074337", "code_snippet": "#include<map>\n#include<cctype>\n#include<string>\n#include<vector>\n#include<iostream>\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n\nusing namespace std;\n\nvoid operator*=(vector<int> &a,const vector<int> &b){ rep(i,a.size()) a[i]+=b[i]; }\nvoid oper...
aoj_1088_cpp
Problem E: School Excursion 春、それは修学旅行の時期である。 会津大学附属小学校(会津大小)でも、来年度の修学旅行の計画が建てられていた。 修学旅行は電車で移動することが伝統になっている。 会津若松市内では電車を利用する機会が少ないためだ。 しかし、学校に届いたある苦情により教員たちは頭を悩ませていた。 それは、「ある駅で大人数で乗り換えを行っていたので、その駅を利用する他の乗客に迷惑であった」という内容だった。 とくに、電車を降りたあとホームからの通路で大混雑してしまったという。 それは近年、会津大小の生徒数が急上昇しているからであった。 その原因は日本において競技プログラミングが大流行し、 小学校から...
[ { "submission_id": "aoj_1088_10929739", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing pll = pair<ll, ll>;\n#define vc vector\nusing vl = vc<ll>;\n\n#define ov(a, b, c, name, ...) name\n#define rep2(i, l, r) for(ll i = (l); i < ll(r); i++)\n#define rep1(i, n)...
aoj_1091_cpp
KND is So Sexy Problem KND君は会津大学に在籍する学生プログラマである。彼の胸元はとてもセクシーなことで知られている。 簡単のために胸元から見える肌の部分を図にある二等辺三角形ABCで表す。しかし服にはたるみが生じているため、長さが等しい2辺AC,BC(これらの長さを l とする)には実際にはさらに長さ x 分余裕がある。はだける部分の面積を増やすため、たるんだ分を引っ張ることで新たにふたつの三角形ADC,BECを作ることにしよう。点D,Eは三角形ABCの外側に存在する。この新しいふたつの三角形はたるみによって生じるもので、辺BEと辺ECの長さの和および辺ADと辺DCの長さの和は l + x でなければならな...
[ { "submission_id": "aoj_1091_3385259", "code_snippet": "#include<iostream>\n#include<iomanip>\n#include<cmath>\nusing namespace std;\n\ndouble calcSurfaceArea( double a, double b, double c )\n{\n double cosA = ( b * b + c * c - a * a ) / ( 2 * b * c );\n double sinA = sqrt( 1 - cosA * cosA );\n ret...
aoj_1090_cpp
Problem G: Sports Days 会津大学附属小学校(会津大小)は日本有数の競技プログラマー養成校として有名である。 もちろん、運動会に参加しているときでさえアルゴリズムの修行を欠かせない。 競技プログラミング部部長のあなたはもちろんこの大会でも勝利したい。 今回はある競技に注目する。 ある競技とは会津大小で行われている伝統的な競技だ。 校庭にコーンがn個置いてある。 コーンは4色用意されている。 コーンのいくつかのペアは白線で描かれた矢印で結ばれている。 矢印は片側だけについており、整数が併記されている。 競技者はk人1チームとして行動する。 あるスタート地点のコーンからゴール地点のコーンまで矢印の上をその向きに移動す...
[ { "submission_id": "aoj_1090_10206766", "code_snippet": "// AOJ #1090\n// Sports Days 2025.2.9\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long; \nconst ll INF = 1LL << 60;\n \nvector<int> buildLPS(const string &pat) {\n int m = pat.size();\n vector<int> lps(m, 0);\n int len ...
aoj_1092_cpp
Make KND So Fat Problem KND君は会津大学に在籍する学生プログラマである。彼の隣人はとても迷惑なことで知られている。隣人は彼が甘党であることを知り、必要以上に甘味を差し入れて彼を太らせようと画策している。そのために、当の隣人であるあなたは友人からとある甘味処を紹介してもらった。 しかし、その甘味処での商品の販売の仕方は少し変わっている。その販売方法とは、甘味セットと呼ばれる甘味の組を日替わりで販売するというものだ。予算内であればその日に販売されている甘味セットの中から自由に甘味を買うことができる。しかし、甘味セットに含まれる甘味は一種類につき1個しか販売されていない。 また、予算は期間の始めに用意した額から支...
[ { "submission_id": "aoj_1092_8090096", "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_1089_cpp
Problem F: Strawberry Cake 会津大学附属小学校 (会津大小) に入学したシャ、ネロ、エリ、コーは競技プログラマとして活躍するために IPPC というプログラミングコンテストに出場することにした。しかし IPPC は 3 人 1 組でチームとしてコンテストに出場する決まりで、4 人でチームを組むことはできない。そこで彼らは 2 人ずつに分かれてチームを組み、2 人 1 組で参加できる IPOCH というプログラミングコンテストに出場することにした。 チームは分かれてしまったが、実力は拮抗しており互いに良い練習相手になっている。 ある日彼らのコーチが差し入れにホールケーキを買ってきた。彼らはそれをシャの家で食べ...
[ { "submission_id": "aoj_1089_9083645", "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) { return (ull)rn...
aoj_1108_cpp
A Long Ride on a Railway Travelling by train is fun and exciting. But more than that indeed. Young challenging boys often tried to purchase the longest single tickets and to single ride the longest routes of various railway systems. Route planning was like solving puzzles. However, once assisted by computers, and sup...
[ { "submission_id": "aoj_1108_1045243", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int,int> PI;\nconst double EPS=1e-6;\n#define rep(i,n) for(int i=0;i<(int)(n);++i)\n#define F first\n#define S second\n#define mp(a,b) make_pair(a,b)\n#define pb(a) p...
aoj_1094_cpp
KND Warp Problem KND君は会津大学に在籍する学生プログラマだ。彼はその優秀な頭脳をもってワープ装置を開発したことで有名である。ワープ装置とは便利なもので、ある場所から別の場所まで瞬時に移動することができる。彼はこれから地球上に点在するワープ装置を用いて様々な場所を可能な限り早くめぐる旅を計画している。 彼の隣人であるあなたの仕事は3次元空間 (xyz直交座標系) 上に存在する N 個のワープ装置をうまく使用して、1から M までの番号がふられた M 個の点を順に通って、 M 番目の点まで移動するときの最小の所要時間を求めることだ。はじめは1番目の点にいるものとし、どのワープ装置も任意のワープ装置へ時間0で移動できる...
[ { "submission_id": "aoj_1094_10274933", "code_snippet": "// AOJ #1094 KND Warp\n// 2025.3.7\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_1095_cpp
KND Factory Problem KND君は会津大学に在籍する学生プログラマである。彼の住む町の周辺には N 個の町がある。彼は生クリームが大好きなので毎日生クリームを食べるためにある町に工場を建設した。その工場では毎日 F リットルの生クリームが製造される。生クリームは運ぶたびに、移動元の町の気温と移動先の町の気温の絶対差だけ傷んでしまう。困ったことにこの近辺の町の気温は寒暖計によって計測できない。しかしながら調査によって、それぞれの町の気温を変数とした N 個の一次方程式からなる N 元一次連立方程式を導くことができた。あなたはこれを解くことによって各町の気温を知ることができる。また、ある町から他の町へ生クリームを運搬する...
[ { "submission_id": "aoj_1095_9281098", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <map>\n#include <queue>\n#include <set>\n#include <iomanip>\nusing namespace std;\ntypedef long long ll;\n#define rep(i, n) for(int i = 0; i < (n); i++)\n\ntemplate<class T>\nusing ...
aoj_1103_cpp
Board Arrangements for Concentration Games You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun. We have a 4x4 board and 8 pairs of car...
[ { "submission_id": "aoj_1103_9626659", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef vector<ll> vi;\ntypedef vector<vi> vvi;\n#define FOR(i,l,r) for(int i=l;i<r;i++)\n#define REP(i,n) FOR(i,0,n)\n#define ALL(A) A.begin(),A.end()\nint main(){\n while(1){\n ...
aoj_1107_cpp
Spiral Footrace Let us enjoy extraordinary footraces at an athletic field. Before starting the race, small flags representing checkpoints are set up at random on the field. Every runner has to pass all the checkpoints one by one in the spiral order specified below. The starting point is the southwest corner of the athl...
[ { "submission_id": "aoj_1107_748379", "code_snippet": "/*\n#include<iostream>\n#include<cstdio>\n#include<cmath>\n#include<sstream>\n#include<algorithm>\n#include<cassert>\n#include<iomanip>\n#include<vector>\n#include<map>\n#include<set>\n#define REP(i,s,n) for(int i=s;i<n;i++)\n#define rep(i,n) REP(i,0,n)...
aoj_1105_cpp
Unable Count I would, if I could, If I couldn't how could I? I couldn't, without I could, could I? Could you, without you could, could ye? Could ye? could ye? Could you, without you could, could ye? It is true, as this old rhyme says, that we can only DO what we can DO and we cannot DO what we cannot DO. Changing some ...
[ { "submission_id": "aoj_1105_9629559", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n#define FOR(i,l,r) for(ll i=l;i<r;i++)\n#define REP(i,n) FOR(i,0,n)\n#define ALL(A) A.begin(),A.end()\nint main(){\n while(1){\n int n,a,b;cin>>n>>a>>b;\n if(!n)retu...
aoj_1109_cpp
Fermat's Last Theorem In the 17th century, Fermat wrote that he proved for any integer $n \geq 3$, there exist no positive integers $x$, $y$, $z$ such that $x^n + y^n = z^n$. However he never disclosed the proof. Later, this claim was named Fermat's Last Theorem or Fermat's Conjecture. If Fermat's Last Theorem holds i...
[ { "submission_id": "aoj_1109_10946369", "code_snippet": "#include<iostream>\n#include<cstring>\n#include<algorithm>\n#include<cstdlib>\n#include<vector>\n#include<cmath>\n#include<stdlib.h>\n#include<iomanip>\n#include<list>\n#include<deque>\n#include<map>\n#include <stdio.h>\n#include <queue>\n#include <st...
aoj_1106_cpp
Factorization of Quadratic Formula As the first step in algebra, students learn quadratic formulas and their factorization. Often, the factorization is a severe burden for them. A large number of students cannot master the factorization; such students cannot be aware of the elegance of advanced algebra. It might be t...
[ { "submission_id": "aoj_1106_9046334", "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) { return (ull)rn...
aoj_1093_cpp
KND Runs for Sweets Problem KND君は会津大学に在籍する学生プログラマである。彼は甘党であることで知られている。彼はとある市に1年間滞在することになり、その期間中に市内にある N 箇所の甘味処をすべて回りたいと思っている。なのでこの1年間の住む場所は甘味処を回るのに一番適した場所がいいと考えている。彼の隣人であるあなたは、各甘味処への最悪の移動時間が最小になる場所を探す事になった。この甘味処がある市は簡単のため二次元平面で表すことにする。彼は目的の甘味処へのモチベーションの違いにより、単位時間あたりの移動距離が変化する。また、彼はどんな場所にでも(たとえ甘味処と同じ場所であろうと)住むつもりでいる。KND...
[ { "submission_id": "aoj_1093_8860355", "code_snippet": "#include <algorithm>\n#include <cmath>\n#include <cstdio>\n#include <vector>\nusing namespace std;\ndouble EPS = 1e-6;\ndouble add(double a, double b) {\n if (abs(a + b) < EPS * (abs(a) + abs(b)))\n return 0;\n return a + b;\n}\nstruct point {\n ...
aoj_1110_cpp
Patience As the proverb says, "Patience is bitter, but its fruit is sweet." Writing programs within the limited time may impose some patience on you, but you enjoy it and win the contest, we hope. The word "patience" has the meaning of perseverance, but it has another meaning in card games. Card games for one player ...
[ { "submission_id": "aoj_1110_10851304", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i,a,b) for(int i=a;i<=b;++i)\n#define rrep(i,a,b) for(int i=a;i>=b;--i)\n#define GRPS int T;scanf(\"%d\",&T);rep(C,1,T)\n#define GRP int T;cin>>T;rep(C,1,T)\n#define ETR putchar('\\n')\n#define IN1(a) scanf(\"%d\"...
aoj_1120_cpp
Pile Up! There are cubes of the same size and a simple robot named Masato. Initially, all cubes are on the floor. Masato can be instructed to pick up a cube and put it on another cube, to make piles of cubes. Each instruction is of the form `pick up cube A and put it on cube B (or on the floor).' When he is to pick ...
[ { "submission_id": "aoj_1120_2063803", "code_snippet": "#include \"bits/stdc++.h\"\n#include<unordered_map>\n#include<unordered_set>\n#pragma warning(disable:4996)\nusing namespace std;\nusing ld = long double;\nconst ld eps = 1e-9;\n\n//// < \"d:\\d_download\\visual studio 2015\\projects\\programing_contes...
aoj_1112_cpp
Strange Key Professor Tsukuba invented a mysterious jewelry box that can be opened with a special gold key whose shape is very strange. It is composed of gold bars joined at their ends. Each gold bar has the same length and is placed parallel to one of the three orthogonal axes in a three dimensional space, i.e., x-a...
[ { "submission_id": "aoj_1112_10772248", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define op operator\n#define pb push_back\n\nstruct poi {\n int x, y, z;\n\n poi op-(poi p) {\n return {x - p.x, y - p.y, z - p.z};\n }\n\n poi op+(poi p) {\n return {x + p....
aoj_1116_cpp
Jigsaw Puzzles for Computers Ordinary Jigsaw puzzles are solved with visual hints; players solve a puzzle with the picture which the puzzle shows on finish, and the diverse patterns of pieces. Such Jigsaw puzzles may be suitable for human players, because they require abilities of pattern recognition and imagination. ...
[ { "submission_id": "aoj_1116_9630524", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n#define FOR(i,l,r) for(ll i=l;i<r;i++)\n#define REP(i,n) FOR(i,0,n)\n#define ALL(A) A.begin(),A.end()\nbool match(char a,char b){\n return abs(a-b)==32;\n}\nint f(string s,char a,...
aoj_1124_cpp
When Can We Meet? The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order ...
[ { "submission_id": "aoj_1124_7668810", "code_snippet": "#include <bits/stdc++.h>\n#define LL_INF 9223372036854775807\n#define INT_INF 2147483647\nusing namespace std;\nusing ll = long long;\n\nint main()\n{\n int n, q, ans, hint;\n multiset<int> mst;\n while (true)\n {\n mst.clear();\n cin >> n >>...
aoj_1117_cpp
Missing Numbers Toshizo is the manager of a convenience store chain in Hakodate. Every day, each of the stores in his chain sends him a table of the products that they have sold. Toshizo's job is to compile these figures and calculate how much the stores have sold in total. The type of a table that is sent to Toshizo ...
[ { "submission_id": "aoj_1117_10853845", "code_snippet": "#include <string>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\nstruct dat {\n\tint px, py; string s;\n};\nbool operator<(const dat& d1, const dat& d2) {\n\tif (d1.px != d2.px) return d1.px < d2.px;\n\treturn d1....
aoj_1125_cpp
Get Many Persimmon Trees Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate withi...
[ { "submission_id": "aoj_1125_10958618", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <iostream>\nusing namespace std;\nint x[520],y[520];\n\nint main(){\n\tint i,j,n,w,h,s,t,k,res,q;\n\twhile(scanf(\"%d\",&n)>0&&n){\n\t\tscanf(\"%d%d\",&w,&h);\n\t\t//for(i=1;i<=h;i++) for(j=1;j<=w;j++) a...
aoj_1121_cpp
Kanglish : Analysis on Artificial Language The late Prof. Kanazawa made an artificial language named Kanglish, which is similar to English, for studying mythology. Words and sentences of Kanglish are written with its own special characters called "Kan-characters". The size of the set of the Kan-characters is 38, i.e...
[ { "submission_id": "aoj_1121_4779367", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nvector<string> kan{\n \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\",\n \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t...
aoj_1126_cpp
The Secret Number Your job is to find out the secret number hidden in a matrix, each of whose element is a digit ('0'-'9') or a letter ('A'-'Z'). You can see an example matrix in Figure 1. Figure 1: A Matrix The secret number and other non-secret ones are coded in a matrix as sequences of digits in a decimal format. ...
[ { "submission_id": "aoj_1126_9662752", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nstring trimZeros(string s) {\n int idx = 0;\n while (idx < s.size() && s[idx] == '0') {\n ++idx;\n }\n return (idx == s.size()) ? \"0\" : s.substr(idx);\n}\n\nstring maxNum(const st...
aoj_1122_cpp
What is the Number in my Mind ? Let us enjoy a number guess game. A number containing L digits is in my mind (where 4 <= L <= 10). You should guess what number it is. It is composed of any of the following ten digits: "0","1","2","3","4","5","6","7","8", and "9". No digits appear twice in the number. For example, whe...
[ { "submission_id": "aoj_1122_9632354", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef vector<ll> vi;\ntypedef vector<vi> vvi;\n#define FOR(i,l,r) for(ll i=l;i<r;i++)\n#define REP(i,n) for(ll i=0;i<n;i++)\n#define ALL(A) A.begin(),A.end()\nint main(){\n whil...