group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_2069_cpp
Greedy, Greedy. Once upon a time, there lived a dumb king. He always messes things up based on his whimsical ideas. This time, he decided to renew the kingdom’s coin system. Currently the kingdom has three types of coins of values 1, 5, and 25. He is thinking of replacing these with another set of coins. Yesterday, he ...
[ { "submission_id": "aoj_2069_10946129", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<cstring>\n#include<cstdio>\n\nusing namespace std;\n\ntypedef long long LL;\n\nconst int N = 55, M = 100010, INF = 0x3f3f3f3f;\n\nint w[N];\nint f[M];\n\nint main()\n{\n int n, t = 1;\n while(sca...
aoj_2076_cpp
Flame of Nucleus Year 20XX — a nuclear explosion has burned the world. Half the people on the planet have died. Fearful. One city, fortunately, was not directly damaged by the explosion. This city consists of N domes (numbered 1 through N inclusive) and M bidirectional transportation pipelines connecting the domes. In ...
[ { "submission_id": "aoj_2076_9663227", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define Bankai ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);\n\nconst int MX_SIZE= 1e2 + 10;\nconst int oo=1e9 + 1;\nconst int MOD=1e9+7;\n\nint tc = 0;\n\nvoid File() {\n#ifndef ONLINE_JUDGE\n ...
aoj_2083_cpp
Problem E: Black Force A dam construction project was designed around an area called Black Force. The area is surrounded by mountains and its rugged terrain is said to be very suitable for constructing a dam. However, the project is now almost pushed into cancellation by a strong protest campaign started by the local r...
[ { "submission_id": "aoj_2083_10357089", "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...
aoj_2079_cpp
Problem A: Dance Dance Revolution Dance Dance Revolution is one of the most popular arcade games in Japan. The rule of this game is very simple. A series of four arrow symbols, up , down , left and right , flows downwards on the screen in time to music. The machine has four panels under your foot, each of which corresp...
[ { "submission_id": "aoj_2079_2456027", "code_snippet": "#include<iostream>\n#include<string>\nusing namespace std;\nint main() {\n\tint n; cin >> n;\n\tfor (int i = 0; i < n; i++) {\n\t\tstring s; cin >> s;\n\t\tfor (int j = 0; j < s.size() - 1; j++) {\n\t\t\tif (s[j] == s[j + 1]) {\n\t\t\t\tcout << \"No\\n...
aoj_2081_cpp
Problem C: Save the Energy You were caught in a magical trap and transferred to a strange field due to its cause. This field is three- dimensional and has many straight paths of infinite length. With your special ability, you found where you can exit the field, but moving there is not so easy. You can move along the pa...
[ { "submission_id": "aoj_2081_9061681", "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_2080_cpp
Problem B: Compress Files Your computer is a little old-fashioned. Its CPU is slow, its memory is not enough, and its hard drive is near to running out of space. It is natural for you to hunger for a new computer, but sadly you are not so rich. You have to live with the aged computer for a while. At present, you have a...
[ { "submission_id": "aoj_2080_9612551", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n while (1) {\n int n, m;\n cin >> n >> m;\n if (n == 0 && m == 0) {\n return 0;\n }\n vector <int > a(n), b(n);\n for (int i = 0; i < ...
aoj_2082_cpp
Problem D: Goofy Converter Nathan O. Davis is a student at the department of integrated systems. He is now taking a class in in- tegrated curcuits. He is an idiot. One day, he got an assignment as follows: design a logic circuit that takes a sequence of positive integers as input, and that outputs a sequence of 1-bit i...
[ { "submission_id": "aoj_2082_10626371", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nll s(ll n){\n ll sum = 0;\n for(int i = 0; (1 << i) <= n; i++){\n sum += ((1 << i) | n) == n;\n }\n return sum;\n}\nint main() {\n ll n,m;\n while(cin >> n...
aoj_2088_cpp
Problem E: Spirograph Some of you might have seen instruments like the figure below. Figure 1: Spirograph There are a fixed circle (indicated by A in the figure) and a smaller interior circle with some pinholes (indicated by B ). By putting a pen point through one of the pinholes and then rolling the circle B without s...
[ { "submission_id": "aoj_2088_3149619", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <vector>\n#include <algorithm>\n#include <cmath>\nusing namespace std;\nconst double PI = acos(-1);\n\nint gcd(int a, int b){\n if(a%b==0) return b;\n return gcd(b,a%b);\n}\n\nint main(){\n whi...
aoj_2094_cpp
Problem B: Jaggie Spheres Let J ( n ) be a three-dimensional body that is a union of unit cubes whose all vertices lie on integer coordinates, contains all points that are closer than the distance of √ n to the origin, and is the smallest of all such bodies. The figure below shows how J (1), J (2), and J (3) look. Figu...
[ { "submission_id": "aoj_2094_1049392", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <vector>\n#include <cmath>\n#include <queue>\n#include <iostream>\n#include <algorithm>\n\nusing namespace std;\n\nconst int N = 2000 + 10;\nconst int dx[] = {-1, 0, 1, 0};\nconst int dy[] = {0, 1, 0, -1}...
aoj_2085_cpp
Problem B: Turn Left Taro got a driver’s license with a great effort in his campus days, but unfortunately there had been no opportunities for him to drive. He ended up obtaining a gold license. One day, he and his friends made a plan to go on a trip to Kyoto with you. At the end of their meeting, they agreed to go aro...
[ { "submission_id": "aoj_2085_4649077", "code_snippet": "#include <iostream>\n#include <utility>\n#include <tuple>\n#include <vector>\n#include <string>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <algorithm>\n#include <functional>\n#include <climits>\n#inclu...
aoj_2086_cpp
Problem C: ! You are one of ICPC participants and in charge of developing a library for multiprecision numbers and radix conversion. You have just finished writing the code, so next you have to test if it works correctly. You decided to write a simple, well-known factorial function for this purpose: Your task is to wri...
[ { "submission_id": "aoj_2086_3764345", "code_snippet": "#include<iostream>\n#include<vector>\n#include<climits>\nusing namespace std;\ntypedef long long ll;\n#define inRange(x,a,b) (a <= x && x <= b)\n\nint main(){\n int n;\n string m;\n vector<int> p({2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31});\n ...
aoj_2089_cpp
Problem F: Mysterious Dungeons The Kingdom of Aqua Canora Mystica is a very affluent and peaceful country, but around the kingdom, there are many evil monsters that kill people. So the king gave an order to you to kill the master monster. You came to the dungeon where the monster lived. The dungeon consists of a grid o...
[ { "submission_id": "aoj_2089_5264769", "code_snippet": "#include <cmath>\n#include <vector>\n#include <iostream>\n#include <iomanip>\n#include <fstream>\n#include <algorithm>\n#include <set>\n#include <queue>\n#include <string>\n#include <map>\n#include <stack>\n#include <climits>\n#include <array>\n#includ...
aoj_2098_cpp
Problem F: Two-finger Programming Franklin Jenkins is a programmer, but he isn’t good at typing keyboards. So he always uses only ‘f’ and ‘j’ (keys on the home positions of index fingers) for variable names. He insists two characters are enough to write programs, but naturally his friends don’t agree with him: they say...
[ { "submission_id": "aoj_2098_10433830", "code_snippet": "// AOJ #2098 Two-finger Programming\n// 2025.4.30\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nstruct Var { int scope, start, end; ll w; };\nenum TokType { ID, KW, NUM, OP, PUNC };\n\nint main(){\n ios::sync_with_stdi...
aoj_2084_cpp
Problem A: Hit and Blow Hit and blow is a popular code-breaking game played by two people, one codemaker and one codebreaker. The objective of this game is that the codebreaker guesses correctly a secret number the codemaker makes in his or her mind. The game is played as follows. The codemaker first chooses a secret n...
[ { "submission_id": "aoj_2084_10486221", "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_2091_cpp
Problem H: Petoris You are playing a puzzle game named petoris . It is played with a board divided into square grids and square tiles each of which fits to a single grid. In each step of the game, you have a board partially filled with tiles. You also have a block consisting of several tiles. You are to place this bloc...
[ { "submission_id": "aoj_2091_5515486", "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 4000000000000000000 //オーバーフローに注意\n#define MOD 1000000007\n#define EPS 0.000000001\nusing namespace std;\n\n\n\n#define...
aoj_2090_cpp
Problem G: Repeated Subsequences You are a treasure hunter traveling around the world. Finally, you’ve got an ancient text indicating the place where the treasure was hidden. The ancient text looks like a meaningless string of characters at first glance. Actually, the secret place is embedded as the longest repeated su...
[ { "submission_id": "aoj_2090_10695784", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint dp[1010][1010];\n\nstring get(string a, string b)\n{\n memset(dp, 0, sizeof dp);\n\n int n = a.size(), m = b.size();\n a = '#' + a;\n b = '#' + b;\n for (int i = 1; i <= n; i++)\n ...
aoj_2097_cpp
Problem E: Triangles There is a group that paints an emblem on the ground to invite aliens every year. You are a member of this group and you have to paint the emblem this year. The shape of the emblem is described as follows. It is made of n regular triangles whose sides are equally one unit length long. These triangl...
[ { "submission_id": "aoj_2097_3057313", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <complex>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <array>\nusing namespace std;\nconst double EPS = 1e-8;\nconst double INF = 1e12;\nconst double PI = acos(-1);\n#define EQ(...
aoj_2099_cpp
Problem G: Walk under a Scorching Sun Edward R. Nelson is visiting a strange town for some task today. This city is built on a two-dimensional flat ground with several vertical buildings each of which forms a convex polygon when seen from above on it (that is to say, the buidlings are convex polygon columns). Edward ne...
[ { "submission_id": "aoj_2099_3166070", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <complex>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <array>\n#include <utility>\n#include <map>\nusing namespace std;\nconst double EPS = 1e-6;\nconst double INF = 1e12;\ncons...
aoj_2095_cpp
Problem C: Nagashi Soumen Mr. Natsume, the captain of a baseball club, decided to hold a nagashi-soumen party. He first planned to put a flume at the arena, and let members stand by the side of the flume to eat soumen. But they are so weird that they adhere to each special position, and refused to move to the side of t...
[ { "submission_id": "aoj_2095_9342791", "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_2096_cpp
Problem D: Private Teacher You are working as a private teacher. Since you are giving lessons to many pupils, you are very busy, especially during examination seasons. This season is no exception in that regard. You know days of the week convenient for each pupil, and also know how many lessons you have to give to him ...
[ { "submission_id": "aoj_2096_9347701", "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_2103_cpp
Problem D: バトルタウン あなたは友人たちとゲームを開発することにした. ゲームのタイトルは「バトルタウン」. 戦車による市街戦をテーマにしたゲームだ. ゲーム開発の第一歩として,次のようなプロトタイプを開発することにした. このプロトタイプでは,登場する戦車はプレイヤーの戦車のみであり, 敵の戦車は登場しない. プレイヤーの戦車はプレイヤーの入力に従ってマップ上で様々な動作をする. 以下に,戦車の動作に関する仕様を述べる. マップの構成要素は表1の通りである. 戦車が移動できるのはマップ内の平地の上だけである. 表1: マップの構成要素 文字 要素 . 平地 * レ...
[ { "submission_id": "aoj_2103_1910162", "code_snippet": "#include<iostream>\n#include<string>\nusing namespace std;\nchar map[20][20];\nint dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};\nchar dm[4]={'^','v','<','>'};\nint main(){\n\tint t;\n\tcin>>t;\n\tfor(int r=0;r<t;r++){\n\tif(r!=0)cout<<endl;\n\tint h,w;\n\tcin>>h...
aoj_2102_cpp
Problem C: ラミー あなたの友達は最近 UT-Rummy というカードゲームを思いついた. このゲームで使うカードには赤・緑・青のいずれかの色と1から9までのいずれかの番号が つけられている. このゲームのプレイヤーはそれぞれ9枚の手札を持ち, 自分のターンに手札から1枚選んで捨てて, 代わりに山札から1枚引いてくるということを繰り返す. このように順番にターンを進めていき, 最初に手持ちのカードに3枚ずつ3つの「セット」を作ったプレイヤーが勝ちとなる. セットとは,同じ色の3枚のカードからなる組で,すべて同じ数を持っているか 連番をなしているもののことを言う...
[ { "submission_id": "aoj_2102_10946120", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing P = pair<int, char>;\n\nint main() {\n int n;\n cin >> n;\n while(n--) {\n vector<P> v(9);\n for(int i=0; i<9; ++i) {\n cin >> v[i].first;\n }\n fo...
aoj_2101_cpp
Problem B: 完全数 ある整数 N に対し,その数自身を除く約数の和を S とする. N = S のとき N は完全数 (perfect number), N > S のとき N は不足数 (deficient number), N < S のとき N は過剰数 (abundant number) と呼ばれる. 与えられた整数が,完全数・不足数・過剰数のどれであるかを 判定するプログラムを作成せよ. プログラムの実行時間が制限時間を越えないように注意すること. Input 入力はデータセットの並びからなる. データセットの数は 100 以下である. 各データセットは整数 N (0 < N ≤ 1000...
[ { "submission_id": "aoj_2101_4196635", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef vector<pair<int,int> > pr;\nconst int H_MX = 100000001;\n\nint N;\npr v;\nvector<int> prime;\nunsigned int bset[H_MX/32+1] = {0};\n\nbool get_b(int i){\n\tint bank = i / 32;\n\tint ofs = i % 32;...
aoj_2105_cpp
Problem F: Problem F: リズムマシーン Advanced Computer Music社(ACM社)は, あらかじめプログラムされたリズム通りに音楽を演奏する リズムマシーンを販売していた. ある時,ACM社は新しいリズムマシーンを開発して売り出そうとしていた. ACM社の旧製品は同時に1つの音しか鳴らすことができなかったのに対し, 新製品では最大で8つの音を同時に鳴らせるようになるというのが 一番の目玉機能であった. 今まで複数の旧製品を利用して演奏する必要のあった曲が 新製品1台で済むようになるので, ACM社は新製品への移行を推進させる...
[ { "submission_id": "aoj_2105_2863552", "code_snippet": "// g++ -std=c++11 a.cpp\n#include<iostream>\n#include<vector>\n#include<string>\n#include<algorithm>\t\n#include<map>\n#include<set>\n#include<unordered_map>\n#include<utility>\n#include<cmath>\n#include<random>\n#include<cstring>\n#include<queue>\n#in...
aoj_2108_cpp
Problem I: Aaron と Bruce Aaron は凶悪な犯罪者である. 彼は幾度も犯罪を繰り返しながら (万引き2回,のぞき16回,下着泥棒256回,食い逃げ65,536回) も,その人並み外れた身体能力を用いて 警察の手から逃れ続けてきた. Bruce は警察官である. 彼は突出した運動能力は持っていないが, 写真撮影が趣味であり, 彼の撮った写真が雑誌に載るほどの腕前を持っている. ある日,Bruce は山奥に写真撮影をしに来た. すると偶然 Aaron のアジトを突き止めてしまった. Bruce が逃げる Aaron を追っていくと,...
[ { "submission_id": "aoj_2108_5890083", "code_snippet": "//#include <atcoder/all>\n#include <bits/stdc++.h>\nusing namespace std;\nusing lint = long long;\nconstexpr lint mod = 1e9 + 7;\n#define all(x) begin(x), end(x)\n#define bitcount(n) __builtin_popcountll((lint)(n))\n#define fcout cout << fixed << setpr...
aoj_2109_cpp
Problem J: いにしえの数式 あなたの友人の考古学者が遺跡を発掘していた. ある日,彼は怪しげな記号の羅列が刻まれている石盤を大量に発見した. 彼はこの大発見に大喜びし,すぐさま石盤に刻まれている記号の解読を始めた. 何週間にもわたる彼の解読の努力の結果, どうやらこれらの石盤には変数・演算子・カッコの組み合わせで成り立っている 数式のようなものが刻まれていることがわかった. 発掘した石盤と遺跡に関わる文献を調べていくうちに彼はさらに, それぞれの石盤で演算子の結合規則が異なっており, それぞれの石盤の先頭に演算子の結合規則が記されているらしいことを突きとめた....
[ { "submission_id": "aoj_2109_4399733", "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\nint G;\nint CLOSE[105]...
aoj_2104_cpp
Problem E: カントリーロード ある過疎地域での話である. この地域ではカントリーロードと呼ばれるまっすぐな道に沿って, 家がまばらに建っている. 今までこの地域には電気が通っていなかったのだが, 今回政府からいくつかの発電機が与えられることになった. 発電機は好きなところに設置できるが, 家に電気が供給されるにはどれかの発電機に電線を介してつながっていなければならず, 電線には長さに比例するコストが発生する. 地域で唯一の技術系公務員であるあなたの仕事は, すべての家に電気が供給されるという条件の下で, できるだけ電線の長さの総計が短くなるよう...
[ { "submission_id": "aoj_2104_10853081", "code_snippet": "#include<stdio.h>\n#include<math.h>\n#include<string.h>\n#include<iostream>\n#include<algorithm>\n#include<vector>\n#define MAXSIZE 1000005\n#define LL long long\n#define INF 0x3f3f3f3f\n\nusing namespace std;\n\nLL pos[MAXSIZE];\nLL dist[MAXSIZE];\n\...
aoj_2107_cpp
Problem H: いけるかな? あるところに,日本各地をまわりながら商売をする社長がいた. 彼はある日,不思議な切符を手に入れた. その切符を使うと,なんと目的地までの距離によらず電車の運賃が無料になるという. ただし, 現在の駅から隣接する駅へ移動するのを1ステップと数えたときに, 移動するステップ数がちょうど切符に書かれた数と等しくならないと 追加料金を取られてしまう. ある区間をただちに折り返すような移動は禁止されているが, 既に訪れた駅や区間を複数回通ること自体は許される. たとえば,駅1・駅2・駅1と移動することはできないが, 駅1・駅2・...
[ { "submission_id": "aoj_2107_11030243", "code_snippet": "#include <iostream>\n#include <vector>\n#include <valarray>\n#include <utility>\nusing namespace std;\n\nstruct Matrix{\n int n;\n valarray<int> a;\n Matrix(int N) : n(N), a(N*N) {a=0;}\n void set(int x, int i, int j){\n a[i*n+j] = ...
aoj_2114_cpp
Problem C: Median Filter The median filter is a nonlinear digital filter used to reduce noise in images, sounds, and other kinds of signals. It examines each sample of the input through a window and then emits the median of the samples in the win- dow. Roughly speaking, a window is an interval that contains a target sa...
[ { "submission_id": "aoj_2114_10437995", "code_snippet": "// AOJ #2114 Median Filter\n// 2025.5.1\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint dp_min[256][256], dp_max[256][256], ndp_min[256][256], ndp_max[256][256];\n\nint main(){\n ios::sync_with_stdio(0);\n cin.tie...
aoj_2113_cpp
Problem B: Electrophoretic Scientist Frank, majoring in electrochemistry, has developed line-shaped strange electrodes called F-electrodes . During being activated, each F-electrode causes a special potential on and between the two lines touching the F-electrode’s endpoints at a right angle. Then electrically-charged p...
[ { "submission_id": "aoj_2113_8029844", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long LL;\ntypedef long double LD;\n\nconst int N = 205;\nconst int MAXN = 100005;\nconst LD eps = 1e-9;\n\ninline int sgn(LD x) {\n return x > eps? 1 : x < -eps? -1 : 0;\n}\n\nstruct Point...
aoj_2116_cpp
Problem E: Subdividing a Land Indigo Real-estate Company is now planning to develop a new housing complex. The entire complex is a square, all of whose edges are equally a meters. The complex contains n subdivided blocks, each of which is a b -meter square. Here both a and b are positive integers. However the project i...
[ { "submission_id": "aoj_2116_7138451", "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_2121_cpp
Problem J: Castle Wall A new lord assumed the position by the death of the previous lord in a Far Eastern province. The new greedy lord hates concave polygons, because he believes they need much wasted area to be drawn on paper. He always wants to modify them to convex ones. His castle is currently surrounded by a wall...
[ { "submission_id": "aoj_2121_1128016", "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 EPS (1e-8)\n#define equals(a,b) (fabs((a)-(b)) < EPS)\n#define COUNTER_CLOCKWISE 1\n#define CLOCKWISE -1 \n#define ONLINE_BACK 2\n#define ONLINE_FR...
aoj_2106_cpp
Problem G: エナジー・トランスポーター とある研究所で, エネルギー伝達用の媒体の開発をしていた. この媒体は図3に示すような特殊な物質からなる ポリマー構造をなしている. (-α-Ea-β-) n 図3: エネルギー伝達用媒体の構造. 図の Ea で示した部分がこの媒体のもっとも特徴的な部位の エナジーアキュムレータ (Energy Accumulator) である. このEa基は 1 kJ 幅で離散化された多様なエネルギー状態を取ることができる. あるEa基を励起させると, そのEa基のα側に結合している隣接したEa基に蓄積されている全エネルギーを β側に...
[ { "submission_id": "aoj_2106_8859757", "code_snippet": "#include <algorithm>\n#include <iostream>\n#include <vector>\n#define REP(i, s, n) for (int i = s; i < n; i++)\n#define rep(i, n) REP(i, 0, n)\n#define MAX 150\nusing namespace std;\nbool dp[MAX][MAX][2];\nint main() {\n ios_base::sync_with_stdio(fals...
aoj_2117_cpp
Problem F: Connect Line Segments Your dear son Arnie is addicted to a puzzle named Connect Line Segments . In this puzzle, you are given several line segments placed on a two-dimensional area. You are allowed to add some new line segments each connecting the end points of two existing line segments. The objective is to...
[ { "submission_id": "aoj_2117_10853928", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstdlib>\n#include<complex>\n#include<vector>\n#include<algorithm>\nusing namespace std;\nconst int MAXN=1<<14;\nconst double inf=1.0e20;\ntypedef complex<double> point;\nvector<int> s[MAXN],t[MAXN];\npoi...
aoj_2118_cpp
Problem G: Oil Company Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey has been done and they created a detailed grid map of the area which indicates the reserve of oil. They are now planning to construct mining plants on several grid blocks according this ma...
[ { "submission_id": "aoj_2118_2651329", "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_2115_cpp
Problem D: Life Game You are working at a production plant of biological weapons. You are a maintainer of a terrible virus weapon with very high reproductive power. The virus has a tendency to build up regular hexagonal colonies. So as a whole, the virus weapon forms a hexagonal grid, each hexagon being a colony of the...
[ { "submission_id": "aoj_2115_10848975", "code_snippet": "#include<stdio.h>\n#include<string.h>\n \nint dir[18][2] =\n{\n { -1, -1,}, { -1, 0}, {0, -1}, {0, 1}, {1, 0}, {1, 1},\n { -1, -1,}, { -1, 0}, {0, -1}, {0, 1}, {1, -1}, {1, 0},\n { -1, 0,}, { -1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}\n};\n \nl...
aoj_2119_cpp
Problem H: Finding the Top RPS Player A company “ACM Foods” is preparing for opening its chain shop in a certain area, but another company “ICPC Pizza” is also planning to set up its branch shop in the same area. In general, two competitive shops gain less incomes if they are located so close to each other. Thus, if bo...
[ { "submission_id": "aoj_2119_10852992", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstring>\n#include<cmath>\nusing namespace std;\nconst int MAXN=30;\nint a[MAXN], b[MAXN];\nint main(){\n int n, m, cs=1;\n while(cin>>n>>m&&n+m){\n int cnt=0;\n memset(a,0,sizeof a);\...
aoj_2123_cpp
Problem B: Divisor Function Teiji is a number theory lover. All numbers are his friends - so long as they are integers. One day, while preparing for the next class as a teaching assistant, he is interested in a number-theoretical function called the divisor function . The divisor function σ ( n ) is defined as the sum ...
[ { "submission_id": "aoj_2123_10972771", "code_snippet": "#include<bits/stdc++.h>\n#define ll long long\n\nusing namespace std;\nconst int N = 33;\n\nll k;\nbool prime[N];\nvector<int> p;\n\nvoid sieve() {\n memset(prime, true, sizeof(prime));\n prime[0] = prime[1] = false;\n for (int i = 2; i * i <...
aoj_2126_cpp
Problem F: Alien Pianist One day an alien came from some star far away in the universe. He was interested in cultures on the earth, especially music. He enjoyed listening various kinds of music, and then he decided to play music by himself. Fortunately, he met a composer in a concert and became a friend with him. He re...
[ { "submission_id": "aoj_2126_10505742", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n/* вершина аккорда */\nstruct Node {\n int key; // номер клавиши\n int note; // номер ноты\n vector<int> out; // исходящие рёбра\n};\n\nint main() {\n ios::sync_with_stdio...
aoj_2125_cpp
Problem D: Land Mark “Hey, what’s up? It’s already 30 minutes past eleven!” “I’m so sorry, but actually I got lost. I have no idea where I am now at all and I got tired wandering around. Please help!” - Today you came to the metropolis to play with your friend. But she didn’t show up at the appointed time. What happene...
[ { "submission_id": "aoj_2125_3646382", "code_snippet": "#include<iomanip>\n#include<limits>\n#include<thread>\n#include<utility>\n#include<iostream>\n#include<string>\n#include<algorithm>\n#include<set>\n#include<map>\n#include<vector>\n#include<stack>\n#include<queue>\n#include<cmath>\n#include<numeric>\n#...
aoj_2124_cpp
Problem C: Magical Dungeon Arthur C. Malory is a wandering valiant fighter (in a game world). One day, he visited a small village and stayed overnight. Next morning, the village mayor called on him. The mayor said a monster threatened the village and requested him to defeat it. He was so kind that he decided to help sa...
[ { "submission_id": "aoj_2124_4748207", "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 105\n\nst...
aoj_2133_cpp
Problem C: Alice and Bob Alice and Bob are in love with each other, but they have difficulty going out on a date - Alice is a very busy graduate student at the ACM university. For this reason, Bob came to the ACM university to meet her on a day. He tried to reach the meeting spot but got lost because the campus of the ...
[ { "submission_id": "aoj_2133_1044772", "code_snippet": "/* \n方針\n0. 初期状態で既にAliceが見えているか判定 =(YES)=> 0.000 と出力して終わる\n1. Bombと長方形の角を結ぶ線分を列挙\n 線分は建物の角とぶつかるor平行であるならそのまま伸ばしていく ( 建物につっこんだら終了 )\n2. Aliceから各点 ( 建物の角、線分の端点 ) への最短距離を求める\n3. 各点から直接到達可能なBombの線分をみつけ、その点までの距離 + その点からBombの線分までの最短距離を計算し、最も短いものを記録\n */\n\...
aoj_2131_cpp
Problem A: Pi is Three π (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name π is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίμετρος (perimeter). Recently, the government of some coun...
[ { "submission_id": "aoj_2131_2375984", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main(void){\n double d;\n while(cin >> d){\n if(abs(d) < 0.000000001) break;\n int den = -1, num = -1;\n for(int i = 1;;i++){\n double tmp = 20.0;\n for(int j = i*3;;j++){\n ...
aoj_2129_cpp
Problem I: Text Justification You are hired by the ∀I¶אΞ℘, an extraterrestrial intelligence, as a programmer of their typesetting system. Your task today is to design an algorithm for text justification . Text justification is to equalize the line widths as much as possible by inserting line breaks at appropriate posi-...
[ { "submission_id": "aoj_2129_9679451", "code_snippet": "#include <iostream>\n#include <bits/stdc++.h>\n\nusing namespace std;\n#define endl \"\\n\"\n\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n\n#define ordered_set tree<int, nuint_type,great...
aoj_2130_cpp
Problem J: Billion Million Thousand A linguist, Nodvic Natharus Damenhof (commonly called Dr. Usoperant ), invented an artificial language Usoperant in 2007. The word usoperant means ‘one which tires’. Damenhof’s goal was to create a complex and pedantic language that would remind many difficulties in universal communi...
[ { "submission_id": "aoj_2130_10855711", "code_snippet": "#include <stdio.h>\n#include <string.h>\n\nint max(int a,int b)\n{\n return a>b ? a : b;\n}\n\nint min(int a,int b)\n{\n return a<b ? a : b;\n}\n\nint main()\n{\n int n;\n int i,j,k;\n char w[110][110];\n int p[110];\n char expre[...
aoj_2136_cpp
Problem F: Webby Subway You are an officer of the Department of Land and Transport in Oykot City. The department has a plan to build a subway network in the city central of Oykot. In the plan, n subway lines are built, and each line has two or more stations. Because of technical problems, a rail track between two stati...
[ { "submission_id": "aoj_2136_8865474", "code_snippet": "//\n// 彩色数を求める O(N2^N) のアルゴリズム\n//\n// cf.\n// https://drken1215.hatenablog.com/entry/2019/01/16/030000\n//\n// verified\n// ARC 171 D - Rolling Hash\n// https://atcoder.jp/contests/arc171/tasks/arc171_d\n//\n// AOJ 2136 Webby Subway\n// ...
aoj_2134_cpp
Problem D: Deadly Dice Game T.I. Financial Group, a world-famous group of finance companies, has decided to hold an evil gambling game in which insolvent debtors compete for special treatment of exemption from their debts. In this game, each debtor starts from one cell on the stage called the Deadly Ring. The Deadly Ri...
[ { "submission_id": "aoj_2134_10350010", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)\n#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)\n#define ...
aoj_2137_cpp
Problem G: Time Trial Some people like finishing computer games in an extremely short time. Terry A. Smith is one of such and prefers role playing games particularly. He is now trying to find a shorter play for one of the key events in a role playing game. In this event, a player is presented a kind of puzzle on a grid...
[ { "submission_id": "aoj_2137_9570105", "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_2132_cpp
Problem B: Left Hand Rule The left-hand rule, which is also known as the wall follower, is a well-known strategy that solves a two- dimensional maze. The strategy can be stated as follows: once you have entered the maze, walk around with keeping your left hand in contact with the wall until you reach the goal. In fact,...
[ { "submission_id": "aoj_2132_9582911", "code_snippet": "#include<iostream>\n#include<vector>\n\nusing namespace std;\n\nconst int N = 110;\n\nint w, h, n;\nbool wall[N][N][4], used[N][N][4];\nint dx[] = {-1, 0, 1, 0};\nint dy[] = {0, -1, 0, 1};\n\nint main() {\n while(cin >> w >> h >> n) {\n if(w ...
aoj_2142_cpp
Problem B: Bitwise Kingdom In the Bitwise Kingdom, located somewhere in the universe, there are exactly 2 N citizens living and each of them has a unique identification string that represents his or her class in the society. An identification string is a binary string of length N which consists of characters ‘ 0 ’ or ‘...
[ { "submission_id": "aoj_2142_3916277", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n\n//TEMPLATE\n#define pb push_back\n#define mp make_pair\n#define ll long long\n#define ld long double\n//#define pi 3.1415926536\n#defin...
aoj_2139_cpp
Problem I: Memory Match Memory match is a single-player game which employs a set of 2 M cards. Each card is labeled with a number between 1 and M on its face. For each number i (1 ≤ i ≤ M ), there are exactly two cards which have the number i . At the start of the game, all cards are shuffled and laid face down on a ta...
[ { "submission_id": "aoj_2139_3176197", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\n\nint main(){\n cout<<fixed<<setprecision(12);\n ll n;\n while(cin>>n && n){\n vector<vector<double>> dp(1000,vector<double>(1000,0));\n double ans=0;\n dp[n/2][0]=1;\n for(...
aoj_2138_cpp
Problem H: Vending Machine There has been marketing warfare among beverage vendors, and they have been working hard for in- crease of their sales. The Kola-Coqua Company is one of the most successful vendors among those: their impressive advertisements toward the world has brought the overwhelming market share of their...
[ { "submission_id": "aoj_2138_9570147", "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_2135_cpp
Problem E: Reverse a Road Andrew R. Klein resides in the city of Yanwoe, and goes to his working place in this city every weekday. He has been totally annoyed with the road traffic of this city. All the roads in this city are one-way, so he has to drive a longer way than he thinks he need. One day, the following though...
[ { "submission_id": "aoj_2135_10351752", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)\n#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)\n#define ...
aoj_2143_cpp
Problem C: Adaptive Time Slicing Quantization Nathan O. Davis is a student at the department of integrated systems. Today he learned digital quanti- zation in a class. It is a process that approximates analog data (e.g. electrical pressure) by a finite set of discrete values or integers. He had an assignment to write a...
[ { "submission_id": "aoj_2143_10318952", "code_snippet": "// AOJ #2143 Adaptive Time Slicing Quantization\n// 2025.3.23\n\n#include <bits/stdc++.h>\nusing namespace std;\nconst double INF = 1e12;\n\nint main(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n int N, M, L;\n while(true) {\n cin...
aoj_2141_cpp
Problem A: Girls' Party Issac H. Ives hosted a party for girls. He had some nice goods and wanted to distribute them to the girls as the presents. However, there were not enough number of presents and thus he needed to decide who would take them. He held a game for that purpose. Before the game, Issac had all the girls...
[ { "submission_id": "aoj_2141_10295302", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)\n#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)\n#define ...
aoj_2149_cpp
Problem A: Luck Manipulator Nathan O. Davis くんは,あるゲームを攻略中であり,非常にレアなアイテムを手に入れようと四苦八苦していた.このレアなアイテムは,カジノのスロットマシーンで特殊な絵柄を一列に揃えたときに手に入れることができる.スロットマシーンには N 個のリールがあり,ボタンを一回押すと現在回転している最も左側のリールが停止する.そのため,このレアアイテムを手に入れるためには N 回ボタンを押す必要がある.また,特殊な絵柄で停止させるためにはあるタイミングでボタンを押す必要がある.ところが,このボタンを押すタイミングは非常にシビアであるため,なかなか上手くいかずに困っていた.そこで...
[ { "submission_id": "aoj_2149_10946117", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing LL = long long;\n#define FOR(i,s,t ) for(int i = s; i< t ; i++)\nusing VL = vector<LL>;\n\nvoid solve() {\n\tLL N, A, B, C, X;\n\twhile (cin >> N >> A >> B >> C >> X, N) {\n\t\tVL y(N);\n\t\tFOR(i, ...
aoj_2150_cpp
Problem B: Matsuzaki Number Matsuzaki 教授は,宇宙の真理を研究している科学者である.人生,宇宙,すべての答えは 42 であると言われているが,Matsuzaki 教授はこれだけでは宇宙の真理を解明するには不十分であると考えている.Matsuzaki 教授は,宇宙の真理は 2 つのパラメータからなる関数で表されると考えており,42 はその 1 つに過ぎないというのである. Matsuzaki 教授の定義した関数 M( N , P ) は, N より大きい素数を 2 つ選んで(同じ数を 2 つでも構わない)和をとることで得られる数の全体を,小さいほうから順番に並べたときに, P 番目に現れる数を表す...
[ { "submission_id": "aoj_2150_10848227", "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 INT = 1e9;\nconst ll LINF = 1e18;\n\nstruct UF{\n vector<int> d;\n UF(int size):d(size,-1){}\n bool u(int...
aoj_2151_cpp
Problem C: Brave Princess Revisited ある貧乏な国のおてんばで勇敢なお姫様が,政略結婚のため別の国に嫁ぐことになった.ところがお姫様を亡き者としようとしている悪漢が嫁ぎ先への道の途中で刺客を放っている. お姫様を無事に相手国に送り届けるため,あなたは安全な経路を既に決定していたのだが,お姫様の今までに通ったことのない道を通ってみたいという わがままな たっての願いで別の道を通ることとなった.そこであなたは地図を見ながらお姫様が通る道を決めなおすことにした. 全ての道は,宿場同士をつなぐ街道である.便宜上,出発地点及び目的地点も宿場とする.ところが,新しい道は治安の問題を抱えていた.盗賊やお姫様を亡き...
[ { "submission_id": "aoj_2151_10855706", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_2152_cpp
Problem D: Restrictive Filesystem あなたは新型記録媒体の開発チームに所属するプログラマーである.この記録媒体はデータの読み込み及び消去はランダムアクセスが可能である.一方,データを書き込むときは,常に先頭から順番にアクセスしていき,最初に見つかった空き領域にしか書き込むことができない. あなたはこの記録媒体用のファイルシステムの構築を始めた.このファイルシステムでは,記録媒体の制限から,データは先頭の空き領域から順に書き込まれる.書き込みの途中で別のデータが存在する領域に至った場合は,残りのデータをその後ろの空き領域から書き込んでいく. データの書き込みはセクタと呼ばれる単位で行われる.セクタには ...
[ { "submission_id": "aoj_2152_10854094", "code_snippet": "#include <set>\n#include <cstdio>\n#include <vector>\n#pragma warning(disable : 4996)\nusing namespace std;\nint Q, x, y; char b[4];\nint main() {\n\twhile (scanf(\"%d\", &Q), Q) {\n\t\tvector<vector<int> > v;\n\t\twhile (Q--) {\n\t\t\tscanf(\"%s\", b...
aoj_2155_cpp
Problem A: Infected Computer Adam Ivan is working as a system administrator at Soy Group, Inc. He is now facing at a big trouble: a number of computers under his management have been infected by a computer virus. Unfortunately, anti-virus system in his company failed to detect this virus because it was very new. Adam h...
[ { "submission_id": "aoj_2155_11061883", "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_2154_cpp
Problem F: Shore Erosion あなたは地元の市役所に勤めるプログラマーである.あなたの住んでいる町は観光業が盛んで,とくに離れ小島にある海岸の海水浴場が人気がある.この島の周囲は砂浜により構成されているのだが,近年海岸浸食によって砂浜の面積が減ってきた.事態を重く見た観光課は,あなたに砂浜の形状変化のシミュレーションを依頼してきた. シミュレーションでは,現在の砂浜の形状をもとに,ある期間が経過した後の砂浜の形状を求める.簡単のため,島の海岸線の形状は多角形(凸とは限らない)とみなす.期間のうちに,砂浜は現在の海岸線からマンハッタン距離で R だけ浸食されて海に沈むものと仮定する.ここで,マンハッタン距離とは x...
[ { "submission_id": "aoj_2154_10517869", "code_snippet": "// AOJ #2154 Shore Erosion\n// 2025.5.23\n\n#include <bits/stdc++.h>\nusing namespace std;\nconst double EPS = 1e-9;\nconst double EPS2 = 1e-2;\nconst double Ma[2] = {1184.6393175351, 1427.4096013511};\nconst double Aa[2] = {1176.5504733859, 1427.3630...
aoj_2153_cpp
Problem E: Mirror Cave 双子の冒険者 Rin と Len は鏡の洞窟でお宝を探している.この洞窟には鏡の間という対になった 2 つの部屋があり,その部屋の扉の向こうには高価な宝が眠っているという. 便宜上,2 つの部屋はそれぞれ W × H のセルが格子状に並んだものとみなす.部屋の外側は壁で囲まれている.また,部屋の内側にもところどころ壁が設置されており,壁の配置されているセルには進入することができない.宝の部屋への扉を開くためには,2 人が左右対称の動きをして,同時に特定のセルに到達しなければならない.しかも,片方だけが先に到達した場合は,扉はロックされて開かなくなってしまう. 左右対称の動きとは,北と北,...
[ { "submission_id": "aoj_2153_10853099", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nstruct P {\n\tint x, y;\n\tP(int x, int y) : x(x), y(y) {}\n};\n\nint dx[] = { 1, 0, -1, 0 };\nint dy[] = { 0, 1, 0, -1 };\n\nint mp[50][50][50][50];\n\nint main()\n{\n\tint W, H, lsx, lsy, rsx, rsy, lgx...
aoj_2157_cpp
Problem C: Dial Lock A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened. You are working at a manufacturer of dial locks. Your job is to verify that every manufactured lock is unlocked by its unlocking sequence. In ot...
[ { "submission_id": "aoj_2157_10854049", "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_2156_cpp
Problem B: Magic Slayer You are in a fantasy monster-ridden world. You are a slayer fighting against the monsters with magic spells. The monsters have hit points for each, which represent their vitality. You can decrease their hit points by your magic spells: each spell gives certain points of damage , by which monster...
[ { "submission_id": "aoj_2156_10849238", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <algorithm>\n#define N 110010\nusing namespace std;\nint hp[110];\n\nstruct weapon{\n int c,p;\n}all[110],sig[110];\nint dp[2][N];\nint all_num,sig_num;\nint m,n;\nvoid init()\n{\...
aoj_2159_cpp
Problem E: Symmetry Open Binary and Object Group organizes a programming contest every year. Mr. Hex belongs to this group and joins the judge team of the contest. This year, he created a geometric problem with its solution for the contest. The problem required a set of points forming a line-symmetric polygon for the i...
[ { "submission_id": "aoj_2159_10208150", "code_snippet": "// AOJ #2159\n// Symmetry 2025.2.10\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst double EPS = 1e-9;\n \nbool dEqual(double a, double b, double eps = EPS) {\n return fabs(a-b) < eps;\n}\n \ndouble normalizeAngle(...
aoj_2161_cpp
Problem G: Defend the Bases A country Gizevom is being under a sneak and fierce attack by their foe. They have to deploy one or more troops to every base immediately in order to defend their country. Otherwise their foe would take all the bases and declare "All your base are belong to us." You are asked to write a prog...
[ { "submission_id": "aoj_2161_9574108", "code_snippet": "#include <bits/stdc++.h>\n\n\nusing namespace std;\n//make -f ../makefile SRC=\n/*\nbs on max time available for max flow >= M\n\n*/\n\n//------------------------------------------------------------------------------\nbool DEBUG = false;\nconst double ...
aoj_2158_cpp
Problem D: Double Sorting Here we describe a typical problem. There are n balls and n boxes. Each ball is labeled by a unique number from 1 to n . Initially each box contains one of these balls. We can swap two balls in adjacent boxes. We are to sort these balls in increasing order by swaps, i.e. move the ball labeled ...
[ { "submission_id": "aoj_2158_10111919", "code_snippet": "#include <stdio.h>\n#include <string.h>\n#include <algorithm>\n#include <iostream>\n#include <math.h>\n#include <assert.h>\n#include <vector>\n#include <set>\n#include <map>\n#include <queue>\n#include <map>\n\nusing namespace std;\ntypedef long long ...
aoj_2162_cpp
Problem H: Galaxy Wide Web Service The volume of access to a web service varies from time to time in a day. Also, the hours with the highest volume of access varies from service to service. For example, a service popular in the United States may receive more access in the daytime in the United States, while another ser...
[ { "submission_id": "aoj_2162_10848624", "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>; usin...
aoj_2163_cpp
Problem I: Tatami A tatami mat, a Japanese traditional floor cover, has a rectangular form with aspect ratio 1:2. When spreading tatami mats on a floor, it is prohibited to make a cross with the border of the tatami mats, because it is believed to bring bad luck. Your task is to write a program that reports how many po...
[ { "submission_id": "aoj_2163_10853925", "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_2164_cpp
Problem J: Revenge of the Round Table Two contries A and B have decided to make a meeting to get acquainted with each other. n ambassadors from A and B will attend the meeting in total. A round table is prepared for in the meeting. The ambassadors are getting seated at the round table, but they have agreed that more th...
[ { "submission_id": "aoj_2164_8393779", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconst int MOD = 1000003;\n\nclass modint {\nprivate:\n\tint x;\npublic:\n\tmodint() : x(0) {}\n\tmodint(long long n) : x(n >= 0 ? n % MOD : (MOD - (-n) % MOD) % MOD) {}\n\tint get() const { return x; }\...
aoj_2165_cpp
Problem A: Strange String Manipulation A linear congruential generator produces a series R(⋅) of pseudo-random numbers by the following for- mulas: where S , A , C , and M are all parameters. In this problem, 0 ≤ S , A , C ≤ 15 and M = 256. Now suppose we have some input string I (⋅), where each character in the string...
[ { "submission_id": "aoj_2165_11061950", "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_2168_cpp
Problem D: Luigi's Tavern Luigi's Tavern is a thriving tavern in the Kingdom of Nahaila. The owner of the tavern Luigi supports to organize a party, because the main customers of the tavern are adventurers. Each adventurer has a job: hero, warrior, cleric or mage. Any party should meet the following conditions: A party...
[ { "submission_id": "aoj_2168_10852845", "code_snippet": "#include<cstdio>\n#include<cstring>\n#include<iostream>\n#include<algorithm>\n#include<queue>\nusing namespace std;\n\nconst int N = 20000;\nconst int inf = 100000;\nint tot, id[N], nxt[N], lst[N], cap[N];\nint H, W, C, M, Nw, Nc, Nm, S, cH, cW, cC, c...
aoj_2169_cpp
Problem E: Colored Octahedra A young boy John is playing with eight triangular panels. These panels are all regular triangles of the same size, each painted in a single color; John is forming various octahedra with them. While he enjoys his playing, his father is wondering how many octahedra can be made of these panels...
[ { "submission_id": "aoj_2169_9685761", "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_2174_cpp
Problem J: Secret Operation Mary Ice is a member of a spy group. She is about to carry out a secret operation with her colleague. She has got into a target place just now, but unfortunately the colleague has not reached there yet. She needs to hide from her enemy George Water until the colleague comes. Mary may want to...
[ { "submission_id": "aoj_2174_3857380", "code_snippet": "bool debug=false;\n#include <stdio.h>\n#include <utility>\n#include <vector>\n#include <math.h>\nusing namespace std;\ntypedef pair<double,double> pd;\ntypedef pair<pd,double> ppdd;\ntypedef pair<pd,pd> ppdpd;\n#define F first\n#define S second\n#defin...
aoj_2172_cpp
Problem H: Queen's Case A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the queen. Now, they besieged the palace and have just...
[ { "submission_id": "aoj_2172_9417496", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)\n#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)\n#define all(x) begin(x), end(x)\ntemplate <type...
aoj_2177_cpp
Problem C: Champernowne Constant Champernown constant is an irrational number represented in decimal by " 0. " followed by concatenation of all positive integers in the increasing order. The first few digits of this constant are: 0.123456789101112... Your task is to write a program that outputs the K digits of Chapnern...
[ { "submission_id": "aoj_2177_5844175", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint n, k;\n\nstring solve();\nint check(int x);\n\nint main() {\n while (1) {\n cin >> n >> k;\n if (!(n + k)) break;\n cout << solve() << endl;\n }\n return 0;\n}\n\nstring solve() {\n int...
aoj_2173_cpp
Problem I: Wind Passages Wind Corridor is a covered passageway where strong wind is always blowing. It is a long corridor of width W, and there are several pillars in it. Each pillar is a right prism and its face is a polygon (not necessarily convex). In this problem, we consider two-dimensional space where the positiv...
[ { "submission_id": "aoj_2173_10854020", "code_snippet": "#include<cstdio>\n#include<iostream>\n#include<cstring>\n#include<algorithm>\n#include<vector>\n#include<cmath>\nusing namespace std;\ntypedef double LD;\nconst LD eps=1e-10;\nconst int maxn=210;\nLD sqr(LD x){return x*x;}\nint sgn(LD x){\n\treturn (x...
aoj_2171_cpp
Problem G: Strange Couple Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can ...
[ { "submission_id": "aoj_2171_10851264", "code_snippet": "#include<cstdio>\n#include<iostream>\n#include<algorithm>\n#include<cstring>\n#include<cmath>\n#define INF 0x3f3f3f3f\n#define N 110\n#define eps 1e-15\n#define LL long long\nusing namespace std;\nint n, s, t, q[N];\n\nint d[N][N], w[N][N];\nvoid Floy...
aoj_2176_cpp
Problem B: For the Peace This is a story of a world somewhere far from the earth. In this world, the land is parted into a number of countries ruled by empires. This world is not very peaceful: they have been involved in army race. They are competing in production of missiles in particular. Nevertheless, no countries h...
[ { "submission_id": "aoj_2176_10851161", "code_snippet": "#ifdef _WIN32\n#define getc_unlocked(stdin) getc(stdin)\n#endif\n#include <algorithm>\n#include <iostream>\n#include <iomanip>\n#include <sstream>\n#include <string>\n#include <list>\n#include <bitset>\n#include <vector>\n#include <stack>\n#include <q...
aoj_2170_cpp
Problem F: Marked Ancestor You are given a tree T that consists of N nodes. Each node is numbered from 1 to N , and node 1 is always the root node of T . Consider the following two operations on T : M v : (Mark) Mark node v . Q v : (Query) Print the index of the nearest marked ancestor of node v which is nearest to it....
[ { "submission_id": "aoj_2170_11051033", "code_snippet": "#include <cstdio>\n#include <iostream>\n#include <stack>\n#include <cstring>\n#include <vector>\n\nusing namespace std;\n\ntypedef pair<char, int> pci;\n\nstack<pci> s;\n\nint fa[100010];\nint p[100010];\nint vis[100010];\n\nvector<int> e[100010];\n\n...
aoj_2178_cpp
Problem D: Futon The sales department of Japanese Ancient Giant Corp. is visiting a hot spring resort for their recreational trip. For deepening their friendships, they are staying in one large room of a Japanese-style hotel called a ryokan. In the ryokan, people sleep in Japanese-style beds called futons. They all hav...
[ { "submission_id": "aoj_2178_10848267", "code_snippet": "#include <cstdio>\n#include <iostream>\n#include <cstring>\n#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <set>\n#include <queue>\n#include <stack>\n#include <map>\n#include <string>\n\nusing namespace std;\n\ntypedef long long l...
aoj_2167_cpp
Problem C: Find the Point We understand that reading English is a great pain to many of you. So we’ll keep this problem statememt simple. Write a program that reports the point equally distant from a set of lines given as the input. In case of no solutions or multiple solutions, your program should report as such. Inpu...
[ { "submission_id": "aoj_2167_8216118", "code_snippet": "#include <bits/stdc++.h>\n#define REP(i, s, n) for (int i = s; i < n; i++)\n#define rep(i, n) REP(i, 0, n)\n#define EPS (1e-6)\n#define equals(a, b) (fabs((a) - (b)) < EPS)\n#define COUNTER_CLOCKWISE 1\n#define CLOCKWISE -1\n#define ONLINE_BACK 2\n#def...
aoj_2179_cpp
Problem E: Safe Area Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan moves a circular-shaped machine within the screen, in such a way it does not overlap a laser beam. As in many sh...
[ { "submission_id": "aoj_2179_10853964", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <cstdio>\n#include <cstdlib>\n#include <vector>\n#include <cstring>\n#include <string>\n#include <cmath>\n#include <ctime>\n#include <utility>\n#include <map>\n#include <set>\n#include <queue>\n#incl...
aoj_2180_cpp
Problem F: Water Tank You built an apartment. The apartment has a water tank with a capacity of L in order to store water for the residents. The tank works as a buffer between the water company and the residents. It is required to keep the tank "not empty" at least during use of water. A pump is used to provide water i...
[ { "submission_id": "aoj_2180_10849597", "code_snippet": "#include<iostream>\n#include<stdio.h>\n#include<cstring>\n\nusing namespace std;\n\nlong long n,l,s[100000],t[100000],u[100000],i,j;\ndouble ans,lb,ub,mid;\n\nbool tr ( double t_flow ) {\n\n\tdouble cap=l;\n\tfor(i=0;i<=n+1;i++)\n\t{\n\t\tcap=cap+t_fl...
aoj_2183_cpp
Problem I: Crystal Jails Artistic Crystal Manufacture developed products named Crystal Jails. They are cool ornaments forming a rectangular solid. They consist of colorful crystal cubes. There are bright cores on the center of cubes, which are the origin of the name. The combination of various colored reflections shows...
[ { "submission_id": "aoj_2183_1429723", "code_snippet": "#include<stdio.h>\n#include<algorithm>\n#include<set>\n#include<vector>\n#include<queue>\n\nusing namespace std;\nchar in[5][5][5];\nchar tmp[5][5][5];\nint bit[30][24];\nint mw[30][24];\nint md[30][24];\nint mh[30][24];\nint SZ[30];\n\nint W,D,H;\nint...
aoj_2182_cpp
Problem H: Eleven Lover Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781 in a number 17819. He thinks a number whi...
[ { "submission_id": "aoj_2182_10849107", "code_snippet": "#include <iostream>\n#include <stdio.h>\n#include <string>\n\nusing namespace std;\n#define MAXN 88000\n\nstring s;\nlong long f[MAXN][12], g[MAXN][12];\nint a[MAXN];\n\nint num(char x)\n{\n return x - '0';\n}\n\nint mm(int x)\n{\n while (x < 0)...
aoj_2181_cpp
Problem G: Neko's Treasure Maki is a house cat. One day she fortunately came at a wonderful-looking dried fish. Since she felt not hungry on that day, she put it up in her bed. However there was a problem; a rat was living in her house, and he was watching for a chance to steal her food. To secure the fish during the t...
[ { "submission_id": "aoj_2181_10853898", "code_snippet": "#include <stdio.h>\n#include <math.h>\n#include <string.h>\n#include <stdlib.h>\n\ntypedef struct _c {\n int x,y,r;\n}circle;\n\nconst double LIT=1e-6;\n\ncircle p1[2000],p2[2000];\nint dp1[2000], dp2[2000];\n\nint cmp(const void *a, const void...
aoj_2189_cpp
Problem E: 足し算ゲーム ねこのファーブルは足し算を用いた簡単なゲームを思いつき、同じくねこで友達のオードリーと一緒にやってみることにした。 ゲームのルールは次のようなものである。まず最初に、適当な正の整数を選び、そこからスタートする。各プレーヤーは、その数のうち隣り合う2つの桁を選択して和を計算し、もとの2つの数字と置き換える。たとえば、「1234」の十の位と百の位を選ぶと、次の数は「154」となる。「5555」の十の位と百の位を選んだ場合は「5105」となる。このような操作を数が1桁になるまで交互に繰り返し、操作ができなくなったプレーヤーが負けとなる。 ゲーム開始時の整数の値が与えられる。先攻であるファーブルと後攻であ...
[ { "submission_id": "aoj_2189_1912847", "code_snippet": "#include<iostream>\n#include<string>\nusing namespace std;\nint solve(string S) {\n\tif (S.size() == 1)return 0;\n\tstring U = S;\n\tint F = (int)(U[0] - '0') + (int)(U[1] - '0');\n\tU = to_string(F) + U.substr(2, U.size() - 2);\n\treturn solve(U) + 1;...
aoj_2192_cpp
Problem H: あみだくじ なつめは大のねこ好きである。なつめは今日も日課としている野良ねこのブラッシングをするために,いつも野良ねこが集まってくる校庭の一角に向かうことにした。 そのスポットに今日は n 匹のねこが集まってきた。なつめは全員をブラッシングしてやりたかったのだが,ちょうどそこに来る直前に突然用事が出来てしまい,時間的に一匹しかブラッシングしてやれないことになってしまった。ブラッシングはどのねこも楽しみにしているので,一匹だけやると他のねこが嫉妬してしまう。そこでねこたちを納得させるために,どのねこをブラッシングするかをあみだくじで決めることにした。 あみだくじは n 本の縦線とあらかじめ引いた m 本の横線から...
[ { "submission_id": "aoj_2192_2303693", "code_snippet": "#include<iostream>\n#include<queue>\n#include<vector>\n#include<algorithm>\nusing namespace std;\n\n#define fr first\n#define sc second\n\nconst int INF=1000000000;\n\nstruct SEG{\n int siz;\n int s[1<<18];\n void init(){\n siz = 1<<17;...
aoj_2184_cpp
Problem J: Cave Explorer Mike Smith is a man exploring caves all over the world. One day, he faced a scaring creature blocking his way. He got scared, but in short time he took his knife and then slashed it to attempt to kill it. Then they were split into parts, which soon died out but the largest one. He slashed the c...
[ { "submission_id": "aoj_2184_9824183", "code_snippet": "#define _CRT_SECURE_NO_WARNINGS\n#include <iostream>\n#include <algorithm>\n#include <cmath>\n#include <cstring>\n#include <cassert>\n#include <vector>\ntypedef long long ll;\n//typedef long double ld;\ntypedef double ld;\ntypedef std::vector<int> Vint...
aoj_2187_cpp
Problem C: カードゲーム ねこのゲイツとジャッキーは、2人で遊ぶカードゲームのルールを考えた。そのルールとは次のようなものである。 まず、1から18の数字が書かれたカードをシャッフルし、それぞれのプレーヤーに9枚ずつ配る。両者は同時に1枚のカードを同時に出し、その値によってスコアを得る。値の大きいカードを出したプレーヤーは、大きい方の値と小さい方の値の和を自分のスコアに加える。その際、値の小さいカードを出したプレーヤーはスコアを得られない。また、一度場に出されたカードは二度と使うことはできない。カードをすべて使い終わった後にスコアが大きかったプレーヤーの勝ちとする。 ゲイツとジャッキーは互いに無作為にカードを選んで出してみ...
[ { "submission_id": "aoj_2187_9066307", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef int64_t ll;\n\nvector<int> a(9),b(9);\nint aw=0,bw=0;\n\nvoid ck(int k,int usd,int as,int bs){\n for(int i=0;i<9;i++){\n if((usd&(1<<i))!=0) continue;\n //cout << k << \" \" << i << endl;\n...
aoj_2194_cpp
Problem J: ねこ泥棒と金曜日のお屋敷 なつめは大のねこ好きである。なつめの通学路には通称ねこ屋敷と呼ばれている家がある。その家はたくさんのねこを飼っていることで有名で、なつめは通学途中によくこの家の前で飼いねこに遭遇し、一緒に遊んでいた。そんなある日、なつめは衝撃的な事実を知ってしまった。それは、実はねこ屋敷の主人は、機嫌が悪くなるとよく飼いねこたちを虐待している、ということだった。ねこ屋敷の主人を許せなくなったなつめは、ねこたちを救うため、主人の居ない間にねこたちを盗みだすことにした。 なつめはねこ屋敷の主人の行動パターンを観察し、毎週決まって出掛けているタイミングをねらってねこたちを盗みだすことにした。ねこ屋敷は二次元...
[ { "submission_id": "aoj_2194_3227728", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <iomanip>\n#include <complex>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <utility>\nusing namespace std;\nconst double EPS = 1e-8;\nconst double INF = 1e12;\n#define EQ(n,m) (ab...
aoj_2191_cpp
Problem G: 挨拶の多い本屋さん なつめは大のねこ好きである。なつめはある日、いつも親しくしている野良ねこたちから、ねこたちが開いている不思議な本屋に行こうと誘われた。その本屋ではたくさんのねこの写真が載った本が売られていると聞き、なつめは喜んでついていくことにした。 なつめは知らなかったのだが、ねこたちに連れられていった本屋は全国にチェーン店を持つ有名店であった。その店ではしっかりとした店員用マニュアルが用意されており、どの店舗でも店員の行動が統一されている。以下はそのマニュアルからの抜粋である。 店員からユークリッド距離10以内のドアからお客様が入店された際には、 X 秒間かけて大声で「いらっしゃいませこんにちは」といわ...
[ { "submission_id": "aoj_2191_2660721", "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_2190_cpp
Problem F: 天使の階段 なつめの住んでいる街の上に浮かんでいる雲には、天使が住んでいる。その天使はなつめと同じくねこ好きで、しばしばねこと遊びに地上に降りてくる。地上に降りるために、天使は雲から地上へ繋がる長い長い階段を作った。しかし、毎回毎回ただ降りていくだけではつまらないと思った天使は、階段に細工をして、段を踏むと音が出るようにした。これを使って、音楽を奏でながら降りていくのだ。 音楽は12種類の音を使って奏でるものである。今回、音のオクターブは無視することにして、 C, C#, D, D#, E, F, F#, G, G#, A, A#, B の12種類のみを考える。隣りあう音同士の差を半音と呼ぶ。たとえば、Cを半音...
[ { "submission_id": "aoj_2190_9073606", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef int64_t ll;\n\nvector<string> oc={\"C\",\"C#\",\"D\",\"D#\",\"E\",\"F\",\"F#\",\"G\",\"G#\",\"A\",\"A#\",\"B\"};\nvector<int> ti(50000+1),si(50000+1);\n\nint tc=0,sc=0;\n\nbool nxt(int ps,int cnt)...
aoj_2198_cpp
Problem B: Moonlight Farm あなたは大人気webゲーム「ムーンライト牧場」に熱中している.このゲームの目的は,畑で作物を育て,それらを売却して収入を得て,その収入によって牧場を大きくしていくことである. あなたは速く畑を大きくしたいと考えた.そこで手始めにゲーム中で育てることのできる作物を,時間あたりの収入効率にもとづいて並べることにした. 作物を育てるには種を買わなければならない.ここで作物 i の種の名前は L i ,値段は P i でそれぞれ与えられる.畑に種を植えると時間 A i 後に芽が出る.芽が出てから時間 B i 後に若葉が出る.若葉が出てから時間 C i 後に葉が茂る.葉が茂ってから時間 D ...
[ { "submission_id": "aoj_2198_3572710", "code_snippet": "#include<bits/stdc++.h>\n#define ll long long\n#define fi first\n#define se second\n#define rep(i, j, k) for (auto i = j; i < k; i++)\n#define rrep(i, j, k) for (auto i = j; i > k; i--)\nusing namespace std;\n\nvoid solve(int &n) {\n map<int, string> ...
aoj_2195_cpp
Problem K: Cat Numbers! ねこのアリストテレスは数学の問題を考えるのを趣味にしている。今彼が考えている問題は以下のようなものである。 1以上の自然数 A , B ( A < B ) に対して、 A から B までの自然数の和を C 、 A と B を十進表記して A , B の順に結合したものを D とすると、両者が等しくなることがある。たとえば1から5までの和は15、2から7までの和は27、7から119までの和は 7119、といった具合である。このような A と B のペアのことを cat numbers と呼ぶことにする。アリストテレスは、 A と B の桁数が与えられたときに、cat numbersを全て...
[ { "submission_id": "aoj_2195_9790609", "code_snippet": "#include <iostream>\n#include <sstream>\n#include <cstdio>\n#include <cstdlib>\n#include <cmath>\n#include <ctime>\n#include <cstring>\n#include <string>\n#include <vector>\n#include <stack>\n#include <queue>\n#include <deque>\n#include <map>\n#include...
aoj_2197_cpp
Problem A: Sum of Consecutive Integers あなたは数か月に渡る受験戦争を勝ち抜き,晴れてICPC大学に入学することができた.入学手続きの日,大学のキャンパス内では熱狂的なサークルの勧誘活動が行われており,あなたは大量のパンフレットを受け取って帰ってきた.部屋に戻ってきたあなたは受け取ったパンフレットの中から気になる一枚を見つけた.そのパンフレットは大学の広報部から渡されたものだった. パンフレットには以下のような問題が記されていた. 和が N となるような,連続する2つ以上の正の整数の組み合わせは,何組存在するでしょうか?例えば, 9 は 2+3+4 と 4+5 の 2通りの組み合わせがあります....
[ { "submission_id": "aoj_2197_10641180", "code_snippet": "#include <bits/stdc++.h>\n// using namespace std;\n\nint main() {\n while (true) {\n int N;\n std::cin >> N;\n\n if (N == 0)\n break;\n\n int ans = 0;\n\n for (int i = 1; i <= N; i++)\n for (...
aoj_2193_cpp
Problem I: 夏への扉 なつめは大のねこ好きである。なつめの家ではずっとねこを飼っておらず、ねこ好きななつめはいつも野良ねこと遊んでいた。しかし、今回なつめは決心し、自分の家でねこを一匹飼うことにした。なつめはねこを家に迎え、レノンと名付けてかわいがり始めた。 なつめの家はたくさんの部屋と、それらをつなぐたくさんの扉からなっており、扉は次の2種類がある。 人間用の普通の扉 なつめは開けることができるが、レノンが自分で開けることはできない。なつめとレノンの両方が通ることができる。一度開ければ、その後は開いたままにしておける。 ねこ用の小さな扉 レノンが自分であけて自由に通ることができる。ただし小さいために、なつめが通ることはで...
[ { "submission_id": "aoj_2193_9080420", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=int64_t;\n\nint main(){\n\n int cnt;\n cin >> cnt;\n int n,m,hs,cs;\n for(int k=0;k<cnt;k++){\n cin >> n >> m;\n cin >> hs >> cs;\n \n vector<vector<int>> dh(n+1),dc(n+1);\n in...
aoj_2202_cpp
Problem F: Canal: Water Going Up and Down ACM国には中央を東西に流れる川がある.この川は西の隣国からACM国を通り東の隣国へと流れており,ACM国内の全長は K kmである.この川にいくつかの閘門を設置し,運河として利用することが計画されている. 閘門とは,異なる2つの水位間を船が移動するための仕組みである.閘門は上流側と下流側にそれぞれ水門を持ち,それらの間に閘室と呼ばれる小さな水域を持つ.この閘室に船を入れた後に注水あるいは排水を行い,閘室の水位を上下させることで船も上下させる.以下にその模式図を示す. 図 F-1: 閘門の模式図 この川の川幅はあまり広くないため,西から東へ一方通行の...
[ { "submission_id": "aoj_2202_6370146", "code_snippet": "/*\tauthor: Kite_kuma\n\tcreated: 2022.03.03 02:02:13 */\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_2205_cpp
Problem B: 宝くじチェッカー あなたは無事進学振り分けを終え、駒場近辺から本郷近辺へ引っ越す準備の最中であった。 家の中を整理していたところ去年購入した宝くじが大量に見つかった。 交換期限を確認したところ明日までに換金しなければならないのだが、引っ越しの準備がまだ全く終わっていないため少額の当選金のために宝くじ売り場まで行くのは面倒である。 そこであなたはいくら当選金が得られるかを調べることにした。 宝くじは8桁の数字からなる。当選番号は同じく8桁で数字と'*'から構成され、持っている宝くじと数字部分が一致した場合、当選番号に応じた当選金が支払われる。 例えば所持している宝くじの番号が "12345678" の場合、当選番...
[ { "submission_id": "aoj_2205_8809123", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\n\nint main() {\n int n, m;\n \n while (true) {\n cin >> n >> m;\n \n if (n == 0 && m == 0)\n break;\n \n int ans = 0;\n vector<int> o(n);\n vector<string> b(n);\...