group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_1111_cpp
Cyber Guardian In the good old days, the Internet was free from fears and terrorism. People did not have to worry about any cyber criminals or mad computer scientists. Today, however, you are facing atrocious crackers wherever you are, unless being disconnected. You have to protect yourselves against their attacks. Co...
[ { "submission_id": "aoj_1111_10849586", "code_snippet": "#include<stdio.h>\n#include<string.h>\n#include<iostream>\n#include<algorithm>\n#include<queue>\n#include<vector>\n#include<cmath>\nconst int Max = 1111;\ntypedef long long LL;\nusing namespace std;\n\nint n,m,cnt;\nchar rule[3][Max][111];\nchar str [...
aoj_1127_cpp
Building a Space Station You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task. The space station is made up with a number of units, called cells. All cells are sphere-shaped, but thei...
[ { "submission_id": "aoj_1127_11065898", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\n\nstatic int bigint = 1e9;\nstatic ll biglong = 1e18;\nstatic ld eps = 1e-9;\n#define rep(i,s,n) for(int i=s;i<(int)(n);i++)\n#define sz(x) (int)(x).size()...
aoj_1133_cpp
Problem E: Water Tank Mr. Denjiro is a science teacher. Today he has just received a specially ordered water tank that will certainly be useful for his innovative experiments on water flow. Figure 1: The water tank The size of the tank is 100cm (Width) * 50cm (Height) * 30cm (Depth) (see Figure 1). For the experimen...
[ { "submission_id": "aoj_1133_9144865", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#if __has_include(<atcoder/all>)\n#include <atcoder/all>\nusing namespace atcoder;\ntemplate<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}\nistream &oper...
aoj_1130_cpp
Problem B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of b...
[ { "submission_id": "aoj_1130_8840090", "code_snippet": "//会う時と+1のとき\n\n//いくつもとけるように\n//countの初期値直した テストケース2つokおそらくいける タリーズでwifi繋がらずまだ\n//69のaojテストケースでanswer45なのに1\n//隣接リストを用意→@からbfs -1でなかった点を数え上げる\n#include <iostream>\n#include <queue>\nusing namespace std;\n\nint bfs(int src, int n, int G[410][410]){ //src...
aoj_1136_cpp
Problem B: Polygonal Line Search Multiple polygonal lines are given on the xy -plane. Given a list of polygonal lines and a template, you must find out polygonal lines which have the same shape as the template. A polygonal line consists of several line segments parallel to x -axis or y -axis. It is defined by a list o...
[ { "submission_id": "aoj_1136_2163060", "code_snippet": "#include <iostream>\n#include <string>\n#include <queue>\n#include <stack>\n#include <algorithm>\n#include <list>\n#include <vector>\n#include <complex>\n#include <utility>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <cmath>\n#...
aoj_1134_cpp
Problem F: Name the Crossing The city of Kyoto is well-known for its Chinese plan: streets are either North-South or East-West. Some streets are numbered, but most of them have real names. Crossings are named after the two streets crossing there, e.g. Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo st...
[ { "submission_id": "aoj_1134_9634624", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\ntypedef pair<ll,ll> pi;\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) R...
aoj_1128_cpp
Square Carpets Mr. Frugal bought a new house. He feels deeply in love with his new house because it has a comfortable living room in which he can put himself completely at ease. He thinks his new house is a really good buy. But, to his disappointment, the floor of its living room has some scratches on it. The floor ha...
[ { "submission_id": "aoj_1128_6005812", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n//#define int long long\ntypedef long long ll;\nusing namespace std;\n#define inf 0x3f3f3f3f\n#define se second\n#define fi first\nconst int mx = 1E4;\nint n,m;\nint a[14][14];\nint dp[14][14];\nint vis[1...
aoj_1132_cpp
Problem D: Circle and Points You are given N points in the xy -plane. You have a circle of radius one and move it on the xy -plane, so as to enclose as many of the points as possible. Find how many points can be simultaneously enclosed at the maximum. A point is considered enclosed by a circle when it is inside or on t...
[ { "submission_id": "aoj_1132_10853887", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nconst int N = 300;\ntypedef complex <double> point;\npoint a[N];\ndouble kc[N][N];\ndouble x[N],y[N];\nint n;\nint quetgoc(int i,double r,int n){\n vector<pair<double,bool> > goc;\n for(int j=0;j<n;...
aoj_1135_cpp
Problem A: Ohgas' Fortune The Ohgas are a prestigious family based on Hachioji. The head of the family, Mr. Nemochi Ohga, a famous wealthy man, wishes to increase his fortune by depositing his money to an operation company. You are asked to help Mr. Ohga maximize his profit by operating the given money during a specif...
[ { "submission_id": "aoj_1135_1862389", "code_snippet": "#include <iostream>\nusing namespace std;\nint main(){\n int a, moneyF, yearL, vary, i1, i2, i3, s, moneyB1, moneyB2, risi1, risi2, moneyto, max;\n double per;\n i1 = 0;\n cin >> a;\n while(1){\n i1++;\n if(i1>a){break;}\n ...
aoj_1140_cpp
Problem F: Cleaning Robot Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture. Consider the room floor paved with square tiles whose size fits the cleaning robot (1 × 1). There are 'clean tiles' and 'dirty tiles', and the robot can change a 'dirty tile' to a 'clean ...
[ { "submission_id": "aoj_1140_10851274", "code_snippet": "// clang-format off\n//#pragma GCC optimize(\"Ofast\")\n//#pragma GCC target(\"avx\")\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n#define stoi stoll\n#define Endl endl\n#define itn int\n#define fi first\n#define se second\n...
aoj_1142_cpp
Problem B: Organize Your Train part II RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1. Figure B-1: Layout of the exchange lines A freight train consists of 2 to 72 freight cars. There are 26 type...
[ { "submission_id": "aoj_1142_10999336", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <string>\n#include <set>\nusing namespace std;\n\nint main() {\n int N;\n cin >> N;\n for (int i=0; i<N; ++i) {\n string word;\n set<string> S;\n cin >> word;\n f...
aoj_1131_cpp
Problem C: Unit Fraction Partition A fraction whose numerator is 1 and whose denominator is a positive integer is called a unit fraction. A representation of a positive rational number p / q as the sum of finitely many unit fractions is called a partition of p / q into unit fractions. For example, 1/2 + 1/6 is a partit...
[ { "submission_id": "aoj_1131_10848172", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint n, a;\n\nint gcd(int a, int b) {\n\tif (a%b == 0) {\n\t\treturn b;\n\t} else {\n\t\treturn gcd(b, a % b);\n\t}\n}\n\nint dfs(int p, int q, int m, int prod, int c) {\n\t// if (...
aoj_1139_cpp
Problem E: Earth Observation with a Mobile Robot Team A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication de...
[ { "submission_id": "aoj_1139_9672115", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef vector<ll> vi;\ntypedef vector<vi> vvi;\ntypedef long double ld;\ntypedef pair<ll,ll> pi;\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)...
aoj_1141_cpp
Problem A: Dirichlet's Theorem on Arithmetic Progressions Good evening, contestants. If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d , i.e., a , a + d , a + 2 d , a + 3 d , a + 4 d , ..., contains infinitely many prime numbers. This fact is known as Dirich...
[ { "submission_id": "aoj_1141_10849693", "code_snippet": "#include<stdio.h>\n#include<math.h>\n\nint isprime(int m){\n if(m<2)\n return 0;\n for(int i=2;i<=(int)sqrt(m);i++){\n if(0==m%i)\n return 0;\n }\n return 1;\n}\n\nint main(){\n int a,b,c;\n while(scanf(\"%d%...
aoj_1138_cpp
Problem D: Traveling by Stagecoach Once upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in this problem is to write a program which determines the route for him. There are several cities in...
[ { "submission_id": "aoj_1138_10865848", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <cmath>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\nusing namespace std;\n\nconst int INF = 0x3f3f3f3f;\nconst int MAX_N = 8;\nconst int MAX_M = 30;\n\nint N, M, P, A, B;\n\nint t[MAX...
aoj_1143_cpp
Problem C: Hexerpents of Hexwamp Hexwamp is a strange swamp, paved with regular hexagonal dimples. Hexerpents crawling in this area are serpents adapted to the environment, consisting of a chain of regular hexagonal sections. Each section fits in one dimple. Hexerpents crawl moving some of their sections from the dimp...
[ { "submission_id": "aoj_1143_10476119", "code_snippet": "// AOJ #1143 Hexerpents of Hexwamp\n// 2025.5.12\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing pii = pair<int,int>;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tif (c ==...
aoj_1149_cpp
Problem C: Cut the Cake Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest pâtissiers in the world. Those who are invited to his birthday party are gourmets from around the world. They are eager to see and eat his extremely creative cakes. Now a large box-shaped cake is being carried into the ...
[ { "submission_id": "aoj_1149_9370376", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i, n) for (int i = 0; i < (int)(n); i++)\n#define all(x) (x).begin(),(x).end()\n#define eb emplace_back\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing vl = vector<long long>;\nusing vv...
aoj_1151_cpp
Problem E: Twirl Around Let's think about a bar rotating clockwise as if it were a twirling baton moving on a planar surface surrounded by a polygonal wall (see Figure 1). Figure 1. A bar rotating in a polygon Initially, an end of the bar (called "end A") is at (0,0), and the other end (called "end B") is at (0, L ) w...
[ { "submission_id": "aoj_1151_1380113", "code_snippet": "#include<cstdio>\n#include<cmath>\n#include<utility>\n#include<vector>\n#include<complex>\n#include<iostream>\n#include<algorithm>\n \nusing namespace std;\n \ntypedef long double Real;\ntypedef complex<Real> Point;\ntypedef complex<Real> Vector;\nty...
aoj_1145_cpp
Problem E: The Genome Database of All Space Life In 2300, the Life Science Division of Federal Republic of Space starts a very ambitious project to complete the genome sequencing of all living creatures in the entire universe and develop the genomic database of all space life. Thanks to scientific research over many ye...
[ { "submission_id": "aoj_1145_10852720", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define REP(i, n) for (int i = 0; i < (n); i++)\n#define int long long\n#define FOR(i, m, n) for (int i = (m); i < (n); i++)\n#define all(x) x.begin(), x.end()\nusing pii = pair<int, int>;\nconstexpr...
aoj_1144_cpp
Problem D: Curling 2.0 On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only a single stone. The purpose of the game is to lead the stone from the start to ...
[ { "submission_id": "aoj_1144_10883658", "code_snippet": "#include <iostream> // cout, endl, cin\n#include <string> // string, to_string, stoi\n#include <vector> // vector\n#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound\n#include <utility> // pair, make_pair\n#include <cstdio...
aoj_1155_cpp
Problem C: How can I satisfy thee? Let me count the ways... Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "true" are represented by 0, 1 and 2 respectively. Let "-" be a unary operator (i.e. a sy...
[ { "submission_id": "aoj_1155_4920981", "code_snippet": "#include <iostream>\n#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\nint a,b,c,ch[80],ans,A,B,C,D;\nstring s;\nint no(int n){\n if(n==0)return 2;\n if(n==1)return 1;\n return 0;\n}\nint h(int x,int y){\n if(x*y==0)retu...
aoj_1152_cpp
Problem F: Dr. Podboq or: How We Became Asymmetric After long studying how embryos of organisms become asymmetric during their development, Dr. Podboq, a famous biologist, has reached his new hypothesis. Dr. Podboq is now preparing a poster for the coming academic conference, which shows a tree representing the develo...
[ { "submission_id": "aoj_1152_9685131", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef long double ld;\ntypedef pair<ll,ll> pi;\ntypedef vector<ll> vi;\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()\ntempl...
aoj_1154_cpp
Problem B: Monday-Saturday Prime Factors Chief Judge's log, stardate 48642.5. We have decided to make a problem from elementary number theory. The problem looks like finding all prime factors of a positive integer, but it is not. A positive integer whose remainder divided by 7 is either 1 or 6 is called a 7 N +{1,6} nu...
[ { "submission_id": "aoj_1154_10946380", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nint next(int i) {\n return i%7 == 1 ? i+5 : i+2;\n}\n\nbool isprime(int x) {\n for(int i=6; i<x; i=next(i)) {\n if(x%i == 0) return false;\n }\n return true;\n}\n\nint main() {\n int n;\n wh...
aoj_1150_cpp
Problem D: Cliff Climbing At 17:00, special agent Jack starts to escape from the enemy camp. There is a cliff in between the camp and the nearest safety zone. Jack has to climb the almost vertical cliff by stepping his feet on the blocks that cover the cliff. The cliff has slippery blocks where Jack has to spend time ...
[ { "submission_id": "aoj_1150_10853812", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <queue>\n#include <cstdio>\nusing namespace std;\n#define reps(i,j,k) for(int i = j ; i < k ; ++i)\n#define rep(i,j) reps(i,0,j)\n\n\nconst int ldx[] = {1,1,2,1,2,3,1,2,1};\nconst int ldy[] = {2,1,1,...
aoj_1148_cpp
Problem B: Analyzing Login/Logout Records You have a computer literacy course in your university. In the computer system, the login/logout records of all PCs in a day are stored in a file. Although students may use two or more PCs at a time, no one can log in to a PC which has been logged in by someone who has not log...
[ { "submission_id": "aoj_1148_10848565", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n\nint main(){\n\tint N,M;\n\tint r;\n\twhile( cin >> N >> M && N ){\n\t\tcin >> r;\n\t\tvector<int> imos[M];\n\t\tfor(int i = 0 ; i < M ; i++) imos[i].resize(60*24+1);\n\t\tfor(int i = 0 ; i < r ; i++)...
aoj_1160_cpp
Problem B: How Many Islands? You are given a marine area map that is a mesh of squares, each representing either a land or sea area. Figure B-1 is an example of a map. Figure B-1: A marine area map You can walk from a square land area to another if they are horizontally, vertically, or diagonally adjacent to each other...
[ { "submission_id": "aoj_1160_11039024", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (int i = 0; i < (n); ++i)\n\nvector<int> dh = {1, 0, -1, 0, 1, 1, -1, -1};\nvector<int> dw = {0, 1, 0, -1, 1, -1, 1, -1};\n\nbool isInside(int h, int w, vec...
aoj_1146_cpp
Problem F Secrets in Shadows Long long ago, there were several identical columns (or cylinders) built vertically in a big open space near Yokohama (Fig. F-1). In the daytime, the shadows of the columns were moving on the ground as the sun moves in the sky. Each column was very tall so that its shadow was very long. The...
[ { "submission_id": "aoj_1146_10214589", "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;\ntypedef long double ld;\n//typedef double ld;\ntypedef std::vector<int> Vi...
aoj_1156_cpp
Problem D: Twirling Robot Let's play a game using a robot on a rectangular board covered with a square mesh (Figure D-1). The robot is initially set at the start square in the northwest corner facing the east direction. The goal of this game is to lead the robot to the goal square in the southeast corner. Figure D-1: ...
[ { "submission_id": "aoj_1156_10848675", "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_1157_cpp
Problem E: Roll-A-Big-Ball ACM University holds its sports day in every July. The "Roll-A-Big-Ball" is the highlight of the day. In the game, players roll a ball on a straight course drawn on the ground. There are rectangular parallelepiped blocks on the ground as obstacles, which are fixed on the ground. During th...
[ { "submission_id": "aoj_1157_10849696", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ndouble EPS = 1e-9;\ntypedef complex<double> P;\n\nstruct L : public vector<P> {\n L(const P &a, const P &b) {\n push_back(a); push_back(b);\n }\n};\ndouble cross(const P& a, const P& b) {\n retur...
aoj_1159_cpp
Problem A: Next Mayor One of the oddest traditions of the town of Gameston may be that even the town mayor of the next term is chosen according to the result of a game. When the expiration of the term of the mayor approaches, at least three candidates, including the mayor of the time, play a game of pebbles, and the wi...
[ { "submission_id": "aoj_1159_10851347", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n\tint n,p;\n\twhile( cin >> n >> p and n ){\n\t\tint c[50] = {};\n\t\tint owan = p;\n\t\tfor(int i = 0 ; ; i = (i+1) % n ){\n\t\t\tif( owan ){\n\t\t\t\t--owan;\n\t\t\t\tc[i]++;\n\t\t\t}els...
aoj_1161_cpp
Problem C: Verbal Arithmetic Let's think about verbal arithmetic. The material of this puzzle is a summation of non-negative integers represented in a decimal format, for example, as follows. 905 + 125 = 1030 In verbal arithmetic, every digit appearing in the equation is masked with an alphabetic character. A problem...
[ { "submission_id": "aoj_1161_10851225", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n\nlong long weight[128];\n\nint to[128];\nint cnt = 0;\nvector<char> appear;\nvector<string> s;\n\nint taboo[128];\n\n\nbool bad(string &s,int to[128]){\n\tif( s.size() == 1 ) return 0;\n\tif( to[s[0]]...
aoj_1162_cpp
Problem D: Discrete Speed Consider car trips in a country where there is no friction. Cars in this country do not have engines. Once a car started to move at a speed, it keeps moving at the same speed. There are acceleration devices on some points on the road, where a car can increase or decrease its speed by 1. It can...
[ { "submission_id": "aoj_1162_10849611", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Node{\n\tint pos;\n\tint speed;\n\tdouble cost;\n\tint prev;\n};\nbool operator < (const Node &a,const Node &b){\n\treturn a.cost > b.cost;\n}\n\n\n\nint main(){\n\tint n,m;\n\twhile(cin >> n >>...
aoj_1163_cpp
Problem E: Cards There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards. A blue card and a red card can be paired when both of the numbers printed on them have a common divisor greater than 1. There ma...
[ { "submission_id": "aoj_1163_10915351", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\n\nint dfs(vector<vector<tuple<int,int,int>>>& G,vector<bool>& checked,int cv,int cf,int goal){\n if(cv==goal) return cf;\n checked[cv]=true;\n\n int ca=0;\n for(auto& nv:...
aoj_1165_cpp
Problem A: Pablo Squarson's Headache Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth. At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same si...
[ { "submission_id": "aoj_1165_9262894", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define all(a) a.begin(),a.end()\n#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)\n#define rep(i, n) reps(i, 0, n)\n#define rreps(i, a, n) for (int i = (a); i > (int)(n);...
aoj_1166_cpp
Problem B: Amazing Mazes You are requested to solve maze problems. Without passing through these mazes, you might not be able to pass through the domestic contest! A maze here is a rectangular area of a number of squares, lined up both lengthwise and widthwise, The area is surrounded by walls except for its entry and...
[ { "submission_id": "aoj_1166_10936796", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (int i = 0; i < (int)(n); i++)\n#define oke cout << \"Yes\" << '\\n';\n#define dame cout << \"No\" << '\\n';\n#define all(a) a.begin(), a.end()\n#define rall(...
aoj_1167_cpp
Problem C: Pollock's conjecture The n th triangular number is defined as the sum of the first n positive integers. The n th tetrahedral number is defined as the sum of the first n triangular numbers. It is easy to show that the n th tetrahedral number is equal to n ( n +1)( n +2) ⁄ 6. For example, the 5th tetrahedral n...
[ { "submission_id": "aoj_1167_11043743", "code_snippet": "#include <bits/stdc++.h>\n#pragma GCC target(\"avx2\")\n#ifndef LOCAL\n#pragma GCC optimize(\"O3\")\n#endif\n#pragma GCC optimize(\"unroll-loops\")\n\n#ifdef ONLINE_JUDGE\n#include <boost/multiprecision/cpp_int.hpp>\n#include <atcoder/all>\n#endif\n#i...
aoj_1164_cpp
Problem F: Tighten Up! We have a flat panel with two holes. Pins are nailed on its surface. From the back of the panel, a string comes out through one of the holes to the surface. The string is then laid on the surface in a form of a polygonal chain, and goes out to the panel's back through the other hole. Initiall...
[ { "submission_id": "aoj_1164_8550653", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Point {\n double x, y;\n Point operator+(const Point p) const { return {x + p.x, y + p.y}; }\n double operator*(const Point p) const { return x * p.x + y * p.y; }\n Point operator-(const Poin...
aoj_1158_cpp
Problem F: ICPC: Intelligent Congruent Partition of Chocolate The twins named Tatsuya and Kazuya love chocolate. They have found a bar of their favorite chocolate in a very strange shape. The chocolate bar looks to have been eaten partially by Mam. They, of course, claim to eat it and then will cut it into two pieces ...
[ { "submission_id": "aoj_1158_10335906", "code_snippet": "// AOJ #1158 ICPC: Intelligent Congruent Partition of Chocolate\n// 2025.3.30\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ull = unsigned long long;\n\nconstexpr int dY[4] = {0, 1, 0, -1};\nconstexpr int dX[4] = {1, 0, -1, 0};\n\nstruct St...
aoj_1172_cpp
Chebyshev's Theorem If n is a positive integer, there exists at least one prime number greater than n and less than or equal to 2 n . This fact is known as Chebyshev's theorem or the Bertrand-Chebyshev theorem, which had been conjectured by Joseph Louis François Bertrand (1822–1900) and was proven by Pafnuty Lvovich Ch...
[ { "submission_id": "aoj_1172_10609798", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<ll, 2>;\nusing a3 = array<ll, 3>;\n\ntemplate <typename A> void chmin(A &l, const A &r) {\n if(r < l)\n l = r;\n}\ntemplate <typename A> void chmax(A &l,...
aoj_1168_cpp
Problem D: Off Balance You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building. Submitted designs will look...
[ { "submission_id": "aoj_1168_5490233", "code_snippet": "#include <stdio.h>\n#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i,n) for (int i = 0; i < (n); ++i)\n#define Inf 1000000000\n\nstruct dsu {\n\tpublic:\n\tdsu() : _n(0) {}\n\texplicit dsu(int n) : _n(n), parent_or_size(n, -1) {}\n\n\tint ...
aoj_1171_cpp
Problem G: Laser Beam Reflections A laser beam generator, a target object and some mirrors are placed on a plane. The mirrors stand upright on the plane, and both sides of the mirrors are flat and can reflect beams. To point the beam at the target, you may set the beam to several directions because of different reflec...
[ { "submission_id": "aoj_1171_10851220", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <complex>\n#include <vector>\n#include <cmath>\n#define sz(x) int((x).size())\n#define mkp make_pair\n#define frs first\n#define scn second\n#define phb push_back\n#define ppb pop_back\nusing namespa...
aoj_1169_cpp
Problem E: The Most Powerful Spell Long long ago, there lived a wizard who invented a lot of "magical patterns." In a room where one of his magical patterns is drawn on the floor, anyone can use magic by casting magic spells! The set of spells usable in the room depends on the drawn magical pattern. Your task is to com...
[ { "submission_id": "aoj_1169_10853923", "code_snippet": "/*\n* Copyright (C) 2015 All rights reserved.\n* \n* filename: 9019.cpp\n* author: doublehh\n* e-mail: sserdoublehh@foxmail.com\n* create time: 2015-06-08\n* last modified: 2015-06-08 16:08:16\n*/\n#include<bits/stdc++.h>\nusing namespac...
aoj_1173_cpp
The Balance of the World The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a string is balanced with respect to brackets so that we can observe the balance of the world. A string that will be given to the pr...
[ { "submission_id": "aoj_1173_9723425", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main()\n{\n\twhile(true)\n\t{\n\t\tstring s;\n\t\tgetline(cin,s);\n\t\tif(s==\".\")\n\t\t\tbreak;\n\t\tvector <int> v;\n\t\tbool ans=true;\n\t\tfor(int i=0; i<s.size(); i++)\n\t\t{\n\t\t\tif(s[i]=='...
aoj_1170_cpp
Problem F: Old Memories In 4272 A.D., Master of Programming Literature, Dr. Isaac Cornell Panther-Carol, who has miraculously survived through the three World Computer Virus Wars and reached 90 years old this year, won a Nobel Prize for Literature. Media reported every detail of his life. However, there was one thing t...
[ { "submission_id": "aoj_1170_8289540", "code_snippet": "#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nint D, N;\nlong long val1[49], pow1[49];\nlong long val2[49], pow2[49];\nstring S;\nstring T[39];\nstring U = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ.\";\nstr...
aoj_1177_cpp
Watchdog Corporation In Northern Kyushu, you are running a company which rents watchdogs in response to the customers' order. The distinguishing point of your service is that you also install fences to enhance the performance of watchdogs. The dog is put on a leash, which is tied up to a peg. You are installing fences ...
[ { "submission_id": "aoj_1177_1150744", "code_snippet": "#include <cstdio>\n#include <cmath>\n#include <cstring>\n#include <cstdlib>\n#include <climits>\n#include <ctime>\n#include <queue>\n#include <stack>\n#include <algorithm>\n#include <list>\n#include <vector>\n#include <set>\n#include <map>\n#include <i...
aoj_1174_cpp
Identically Colored Panels Connection Dr. Fukuoka has invented fancy panels. Each panel has a square shape of a unit size and has one of the six colors, namely, yellow, pink, red, purple, green and blue. The panel has two remarkable properties. One property is that, when two or more panels with the same color are p...
[ { "submission_id": "aoj_1174_10853966", "code_snippet": "#include <algorithm>\n#include <cstdio>\n#include <cstring>\n\nusing std::max;\n\nint N, M, target, a[8][8], f, t, ans, x[64], y[64];\n\nint w[10];\n\nvoid copy(int b[8][8], int a[8][8]) {\n\tfor(int i = 0; i < N; ++i) {\n\t\tfor(int j = 0; j < M; ++j...
aoj_1175_cpp
And Then, How Many Are There? To Mr. Solitarius, who is a famous solo play game creator, a new idea occurs like every day. His new game requires discs of various colors and sizes. To start with, all the discs are randomly scattered around the center of a table. During the play, you can remove a pair of discs of the sam...
[ { "submission_id": "aoj_1175_10946386", "code_snippet": "#include<cstdio>\n#include<cstdlib>\n#include<cstring>\n#include<map>\n#include<set>\n#include<string>\n#include<iostream>\n#include<algorithm>\nusing namespace std;\n#define MP(i,j) make_pair(i,j)\ntypedef long long int64;\ntypedef long double real;\...
aoj_1176_cpp
Planning Rolling Blackouts Faced with seriously tight power supply-demand balance, the electric power company for which you are working implemented rolling blackouts in this spring. It divided the servicing area into several groups of towns, and divided a day into several blackout periods. At each blackout period...
[ { "submission_id": "aoj_1176_10866686", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <iostream>\n#include <algorithm>\nconst int oo=1073741819;\nusing namespace std;\nint n,m,s,w_time;\nint sum[50][50],t[50][50][50][50],a[50][50];\nstruct sta{\n int tot,max;\n}f[50...
aoj_1178_cpp
A Broken Door There is a rectangular maze consisting of a number of square rooms arranged in grid. The maze is surrounded by walls except for its entry and exit. The entry to the maze is at the leftmost part of the upper side of the rectangular area, that is, the upper side of the uppermost leftmost room of the maze i...
[ { "submission_id": "aoj_1178_10946388", "code_snippet": "#include<cstring>\n#include<cstdio>\n#include<algorithm>\nusing namespace std;\nint n, m, bak, cl, qx[909], qy[909], dis[33][33], pas[77][77], x, y, dx[4], dy[4], mn[33][33], ans[77][77][2];\nint main()\n{\n\tdx[0] = -1; dy[0] = 0;\n\tdx[1] = 0; dy[1]...
aoj_1179_cpp
Millennium A wise king declared a new calendar. "Tomorrow shall be the first day of the calendar, that is, the day 1 of the month 1 of the year 1. Each year consists of 10 months, from month 1 through month 10, and starts from a big month . A common year shall start with a big month, followed by small months and big ...
[ { "submission_id": "aoj_1179_10683989", "code_snippet": "#line 1 \"speedrun.cpp\"\n#include <bits/stdc++.h>\n#line 1 \"/home/ardririy/repos/cp-libs/libraries-cpp/input.hpp\"\n\n\n#line 6 \"/home/ardririy/repos/cp-libs/libraries-cpp/input.hpp\"\nusing namespace std;\nvector<long long> i64_vec_IN(int n) {vect...
aoj_1180_cpp
Recurring Decimals A decimal representation of an integer can be transformed to another integer by rearranging the order of digits. Let us make a sequence using this fact. A non-negative integer a 0 and the number of digits L are given first. Applying the following rules, we obtain a i +1 from a i . Express the integer...
[ { "submission_id": "aoj_1180_10853944", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cmath>\n#include <cstdlib>\n#include <algorithm>\n#include <vector>\n#include <map>\n#include <queue>\n#include <set>\nusing namespace std;\n#define SZ(v) ((int)(v).size())\n#define...
aoj_1187_cpp
ICPC Ranking Your mission in this problem is to write a program which, given the submission log of an ICPC (International Collegiate Programming Contest), determines team rankings. The log is a sequence of records of program submission in the order of submission. A record has four fields: elapsed time, team number, pro...
[ { "submission_id": "aoj_1187_3560625", "code_snippet": "#define _CRT_SECURE_NO_WARNINGS\n#include <stdio.h>\n#include <algorithm>\n#include <utility>\n#include <functional>\n#include <cstring>\n#include <queue>\n#include <stack>\n#include <math.h>\n#include <iterator>\n#include <vector>\n#include <string>\...
aoj_1181_cpp
Biased Dice Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall onto the plane or dice already there, without rotatin...
[ { "submission_id": "aoj_1181_10609938", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconst long long MOD1 = 1000000007;\nconst long long MOD2 = 998244353;\n#define all(v) v.begin(), v.end()\n#define rall(a) a.rbegin(), a.rend()\n#define fi first\n#define se second\n// #define endl \"\\...
aoj_1185_cpp
Patisserie ACM Amber Claes Maes, a patissier, opened her own shop last month. She decided to submit her work to the International Chocolate Patissier Competition to promote her shop, and she was pursuing a recipe of sweet chocolate bars. After thousands of trials, she finally reached the recipe. However, the recipe re...
[ { "submission_id": "aoj_1185_10882539", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nstruct Bimatch{\n vector<vector<int>> g;\n vector<int> d, mc, used, vv;\n Bimatch(int n, int m): g(n), mc(m, -1), used(n){\n }\n void add(int u, int v){\n g[u].push_back(v);\n }\n void bfs(){\n...
aoj_1183_cpp
Chain-Confined Path There is a chain consisting of multiple circles on a plane. The first (last) circle of the chain only intersects with the next (previous) circle, and each intermediate circle intersects only with the two neighboring circles. Your task is to find the shortest path that satisfies the following conditi...
[ { "submission_id": "aoj_1183_10853933", "code_snippet": "/*\n * Author: xioumu\n * Created Time: 2012/7/20 10:46:25\n * File Name: e.cpp\n * solve: e.cpp\n */\n#include<cstdio>\n#include<cstring>\n#include<cstdlib>\n#include<cmath>\n#include<algorithm>\n#include<string>\n#include<map>\n#include<set>\nusin...
aoj_1184_cpp
Generic Poker You have a deck of N × M cards. Each card in the deck has a rank. The range of ranks is 1 through M , and the deck includes N cards of each rank. We denote a card with rank m by m here. You can draw a hand of L cards at random from the deck. If the hand matches the given pattern, some bonus will be reward...
[ { "submission_id": "aoj_1184_8998859", "code_snippet": "#line 2 \"cp-library/src/cp-template.hpp\"\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing uint = unsigned int;\nusing ull = unsigned long long;\nusing i32 = int;\nusing u32 = unsigned int;\nusing...
aoj_1182_cpp
Railway Connection Tokyo has a very complex railway system. For example, there exists a partial map of lines and stations as shown in Figure D-1. Figure D-1: A sample railway network Suppose you are going to station D from station A. Obviously, the path with the shortest distance is A→B→D. However, the path with the sh...
[ { "submission_id": "aoj_1182_10852690", "code_snippet": "/*\n * Author:heroming\n * File:heroming.cpp\n * Time:2012-7-19 9:33:45\n */\n#include <iostream>\n#include <cstdio>\n#include <string>\n#include <cstring>\n#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <queue>\nusing namespace s...
aoj_1186_cpp
Integral Rectangles Let us consider rectangles whose height, h , and width, w , are both integers. We call such rectangles integral rectangles . In this problem, we consider only wide integral rectangles, i.e., those with w > h . We define the following ordering of wide integral rectangles. Given two wide integral rect...
[ { "submission_id": "aoj_1186_9327994", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<vector>\nusing namespace std;\nbool solve()\n{\n int H,W;\n cin>>H>>W;\n if(H==0&&W==0)return 0;\n vector<pair<int,int>>bigger;\n auto comp=[](pair<int,int>p,pair<int,int>q)\n {\n ...
aoj_1188_cpp
Hierarchical Democracy The presidential election in Republic of Democratia is carried out through multiple stages as follows. There are exactly two presidential candidates. At the first stage, eligible voters go to the polls of his/her electoral district. The winner of the district is the candidate who takes a majority...
[ { "submission_id": "aoj_1188_10851154", "code_snippet": "#include <iostream>\n#include <sstream>\n#include <algorithm>\n#include <string>\n#include <vector>\n#include <numeric>\n#define sz(x) int((x).size())\n#define all(x) (x).begin(), (x).end()\n#define phb push_back\nusing namespace std;\n\nint Z;\nstrin...
aoj_1189_cpp
Prime Caves An international expedition discovered abandoned Buddhist cave temples in a giant cliff standing on the middle of a desert. There were many small caves dug into halfway down the vertical cliff, which were aligned on square grids. The archaeologists in the expedition were excited by Buddha's statues in tho...
[ { "submission_id": "aoj_1189_10852870", "code_snippet": "#include \"bits/stdc++.h\"\n\n#define REP(i,n) for(ll i=0;i<n;++i)\n#define RREP(i,n) for(ll i=n-1;i>=0;--i)\n#define FOR(i,m,n) for(ll i=m;i<n;++i)\n#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)\n#define ALL(v) (v).begin(),(v).end()\n#define PB(a) push_...
aoj_1190_cpp
Anchored Balloon A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation. Figure E-1: A balloon and ropes on the ground Now the balloon takes off, and you...
[ { "submission_id": "aoj_1190_10433181", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing ll = long long;\n\ntypedef complex<double> Point;\nconst double EPS = 1e-8;\n\nstruct Circle {\n Point p;\n double r;\n};\n\n// 円の交点を求めるメソッド\npair<Point, Point> cc_cross(const Circle& c1, c...
aoj_1193_cpp
Chain Disappearance Puzzle We are playing a puzzle. An upright board with H rows by 5 columns of cells, as shown in the figure below, is used in this puzzle. A stone engraved with a digit, one of 1 through 9, is placed in each of the cells. When three or more stones in horizontally adjacent cells are engraved with t...
[ { "submission_id": "aoj_1193_9527420", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nll MOD = 1'000'000'007;\nll inf = (1LL << 62);\n\n// clang-format off\nauto getll(){ll n; cin >> n; return n;}\nauto getstr(){string s; cin >> s; return s;}\nauto getdb(){double n; ...
aoj_1191_cpp
Rotate and Rewrite Two sequences of integers A: A 1 A 2 ... A n and B: B 1 B 2 ... B m and a set of rewriting rules of the form " x 1 x 2 ... x k → y " are given. The following transformations on each of the sequences are allowed an arbitrary number of times in an arbitrary order independently. Rotate : Moving the fi...
[ { "submission_id": "aoj_1191_10335939", "code_snippet": "// AOJ #1191 Rotate and Rewrite\n// 2025.3.30\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define NMAX 50\nconst int BAS = 1000;\nint A[NMAX+5], B[NMAX+5];\nbool dpA[NMAX+5][NMAX+5][600];\nbool dpB[NMAX+5][NMAX+5][600];\nint sudpA[NMAX+5][NMA...
aoj_1194_cpp
Vampire Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into ash. Nevertheless, last night, he attended to the meeting of Immortal and Corpse Programmers Circle, and he has to go home in the near dawn. Fortunately, there are many tall buildings around Mr. C's home, and while the sunlight is b...
[ { "submission_id": "aoj_1194_10850501", "code_snippet": "#include <cstdio>\n#include <cmath>\n#include <algorithm>\n#include <vector>\n\nusing namespace std;\n\nconst double EPS = 1e-9;\nbool EQ(double a, double b) { return abs(a - b) < EPS; }\n\ndouble getHeight(double r, double x) {\n\treturn sqrt(r * r -...
aoj_1195_cpp
Encryption System A programmer developed a new encryption system. However, his system has an issue that two or more distinct strings are `encrypted' to the same string. We have a string encrypted by his system. To decode the original string, we want to enumerate all the candidates of the string before the encryption. ...
[ { "submission_id": "aoj_1195_10848117", "code_snippet": "#include <stdio.h>\n#include <memory.h>\n#include <string.h>\n#define MAX 30\n\nchar ch[MAX], p[MAX];\nint len, b[MAX], ac[30], cnt;\nchar ch2[1050000][22];\n\nvoid dfs(int now, int sw){\n\tint i;\n\tb[now]=sw;\n\tif (now==len){\n\t\tfor (i=1;i<=len;i...
aoj_1192_cpp
Tax Rate Changed VAT (value-added tax) is a tax imposed at a certain rate proportional to the sale price. Our store uses the following rules to calculate the after-tax prices. When the VAT rate is x %, for an item with the before-tax price of p yen, its after-tax price of the item is p (100+ x ) / 100 yen, fractions ...
[ { "submission_id": "aoj_1192_10851356", "code_snippet": "#include <cstdio>\n#include <algorithm>\n\nusing namespace std;\n\nint main(void) {\n\tint x, y, s;\n\twhile(scanf(\"%d %d %d\", &x, &y, &s), !(x == 0 and y == 0 and s == 0)) {\n\t\tint ans = 0;\n\n\t\tfor(int i = 1; i < s; i++) {\n\t\t\tint j = s - i...
aoj_1196_cpp
Bridge Removal ICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the project is to remove all the bridges connecting the islands. There are n islands...
[ { "submission_id": "aoj_1196_10853372", "code_snippet": "#include <stdio.h>\n#include <vector>\n#define MAX 810\n\nint n, p[MAX], d[MAX], check[MAX];\nint val, answer=2147483647;\nstruct data{\n\tint go, dis;\n};\nstd::vector<data> vec[MAX];\nint dy[MAX][2];\n\nvoid reset(void){\n\tint i;\n\tanswer=21474836...
aoj_1197_cpp
A Die Maker The work of die makers starts early in the morning. You are a die maker. You receive orders from customers, and make various kinds of dice every day. Today, you received an order of a cubic die with six numbers t 1 , t 2 , ..., t 6 on whichever faces. For making the ordered die, you use a tool of flat-board...
[ { "submission_id": "aoj_1197_9857905", "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_1198_cpp
Don't Cross the Circles! There are one or more circles on a plane. Any two circles have different center positions and/or different radiuses. A circle may intersect with another circle, but no three or more circles have areas nor points shared by all of them. A circle may completely contain another circle or two circle...
[ { "submission_id": "aoj_1198_9340740", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing Real = long double;\nusing Point = complex<Real>;\nconst Real EPS = 1e-9, PI = acos(-1);\n\ninline bool eq(Real a, Real b) {\n return fabs(b - a) < EPS;\n}\n\nPoint operator*(const Point &p, cons...
aoj_1200_cpp
Problem A: Goldbach's Conjecture Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p 1 and p 2 such that n = p 1 + p 2 . This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can fin...
[ { "submission_id": "aoj_1200_11059833", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i,a,b) for(int i=(a);i<(b);i++)\n\nvector<int> ans_table(const int LIM=(1<<16)){\n vector<int>res(LIM);\n vector<int> isP(LIM,1);\n vector<int>primes;\n isP[...
aoj_1202_cpp
Problem C: Mobile Phone Coverage A mobile phone company ACMICPC (Advanced Cellular, Mobile, and Internet-Connected Phone Corporation) is planning to set up a collection of antennas for mobile phones in a city called Maxnorm. The company ACMICPC has several collections for locations of antennas as their candidate plans,...
[ { "submission_id": "aoj_1202_3709040", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing ll = long long;\n// #define int ll\nusing PII = pair<ll, ll>;\n\n#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)\n#define REP(i, n) FOR(i, 0, n)\n#define ALL(x) x.begin(), x.end()\n\ntempl...
aoj_1201_cpp
Problem B: Lattice Practices Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4 × 4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows: The cocoon bed can be...
[ { "submission_id": "aoj_1201_9634679", "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()\n#define LB(A,x) (lower_bound(ALL(A),x)-A.begin())\n#define UB(A,x) (upper_bound...
aoj_1214_cpp
Problem G: Walking Ant Ants are quite diligent. They sometimes build their nests beneath flagstones. Here, an ant is walking in a rectangular area tiled with square flagstones, seeking the only hole leading to her nest. The ant takes exactly one second to move from one flagstone to another. That is, if the ant is on th...
[ { "submission_id": "aoj_1214_5976490", "code_snippet": "#include<iostream>\n#include<cstring>\n#include<cstdio>\n#include<sstream>\n#include<algorithm>\n#include<cstdlib>\n#include<queue>\n#include<set>\n#include<map>\n#include<cmath>\n#include<ctime>\n#include<stack>\n#include<functional>\n#define INF 2100...
aoj_1203_cpp
Problem D: Napoleon's Grumble Legend has it that, after being defeated in Waterloo, Napoleon Bonaparte, in retrospect of his days of glory, talked to himself "Able was I ere I saw Elba." Although, it is quite doubtful that he should have said this in English, this phrase is widely known as a typical palindrome . A pali...
[ { "submission_id": "aoj_1203_1892938", "code_snippet": "#include<iostream>\n#include<vector>\n#include<string>\n#include<algorithm>\t\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#include<iomanip>\n#define loop(i,...
aoj_1208_cpp
Problem A: Rational Irrationals Rational numbers are numbers represented by ratios of two integers. For a prime number p , one of the elementary theorems in the number theory is that there is no rational number equal to √ p . Such numbers are called irrational numbers. It is also known that there are rational numbers a...
[ { "submission_id": "aoj_1208_8658705", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define overload4(_1, _2, _3, _4, name, ...) name\n#define rep1(n) for(int i = 0; i < (int)(n); ++i)\n#define rep2(i, n) for(int i = 0; i < (int)(n); ++i)\n#define rep3(i, a, b) for(int i = (a); i < (...
aoj_1204_cpp
Problem E: Pipeline Scheduling An arithmetic pipeline is designed to process more than one task simultaneously in an overlapping manner. It includes function units and data paths among them. Tasks are processed by pipelining : at each clock, one or more units are dedicated to a task and the output produced for the task...
[ { "submission_id": "aoj_1204_2581073", "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>\ntypedef long long int ll;\ntypedef unsigned lo...
aoj_1218_cpp
Problem C: Push!! Mr. Schwarz was a famous powerful pro wrestler. He starts a part time job as a warehouseman. His task is to move a cargo to a goal by repeatedly pushing the cargo in the warehouse, of course, without breaking the walls and the pillars of the warehouse. There may be some pillars in the warehouse. Excep...
[ { "submission_id": "aoj_1218_3807528", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing ull = unsigned long long;\n\nconstexpr long double EPS = 1e-15;\nconst long double PI = acos(-1);\nconstexpr int inf = 2e9;\nconstexpr ll INF = 2e18;\nconstexpr ll MOD = 1e9+7...
aoj_1216_cpp
Problem A: Lost in Space William Robinson was completely puzzled in the music room; he could not find his triangle in his bag. He was sure that he had prepared it the night before. He remembered its clank when he had stepped on the school bus early that morning. No, not in his dream. His triangle was quite unique: no t...
[ { "submission_id": "aoj_1216_3807101", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <string>\n#include <numeric>\n\n#define REP(i, a, b) for (int i = int(a); i < int(b); i++)\nusing namespace std;\ntypedef long long int ll;\n\n// clang-format off\n#ifdef _DEBUG_\n#...
aoj_1209_cpp
Problem B: Square Coins People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 17 2 ), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland. There are f...
[ { "submission_id": "aoj_1209_2539223", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nint count( int S[], int m, int n )\n{\n if (n == 0)\n return 1;\n if (n < 0)\n return 0;\n if (m <=0 && n >= 1)\n return 0;\n return count( S, m - 1, n ) + count( S, m, n...
aoj_1215_cpp
Problem H: Co-occurrence Search A huge amount of information is being heaped on WWW. Albeit it is not well-organized, users can browse WWW as an unbounded source of up-to-date information, instead of consulting established but a little out-of-date encyclopedia. However, you can further exploit WWW by learning more abou...
[ { "submission_id": "aoj_1215_2683439", "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_1217_cpp
Problem B: Family Tree A professor of anthropology was interested in people living in isolated islands and their history. He collected their family trees to conduct some anthropological experiment. For the experiment, he needed to process the family trees with a computer. For that purpose he translated them into text f...
[ { "submission_id": "aoj_1217_2170790", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nint dep[100010];\nint par[100010][19];\nvector<int> g[100010];\nvoid dfs(int v,int u,int d){\n dep[v]=d;\n for(int i=0; i<g[v].size(); i++){\n int w=g[v][i];if(w==u) continue;\n par[w][0]=v;dfs(w,...
aoj_1221_cpp
Problem F: Numoeba A scientist discovered a strange variation of amoeba. The scientist named it numoeba . A numoeba, though it looks like an amoeba, is actually a community of cells, which always forms a tree. The scientist called the cell leader that is at the root position of the tree. For example, in Fig. 1, the lea...
[ { "submission_id": "aoj_1221_1092280", "code_snippet": "#include<iostream>\n#include<vector>\n#include<tuple>\n#include<algorithm>\nusing namespace std;\n\nconst int MOD = 12345678;\nconst int NIL = -1;\n\nclass Numoeba {\npublic:\n Numoeba(const int n) :max_cell_(1), root_(0) {create_cell(n);}\n tupl...
aoj_1227_cpp
Problem D: 77377 At the risk of its future, International Cellular Phones Corporation (ICPC) invests its resources in developing new mobile phones, which are planned to be equipped with Web browser, mailer, instant messenger, and many other advanced communication tools. Unless members of ICPC can complete this stiff jo...
[ { "submission_id": "aoj_1227_746368", "code_snippet": "// start: 10:34\n// stop: 10:43\n// start: 10:50\n// stop: 11:22\n#include <cstdio>\n#include <cstdlib>\n#include <cmath>\n#include <climits>\n#include <cctype>\n#include <algorithm>\n#include <numeric>\n#include <iostream>\n#include <string>\n#include ...
aoj_1219_cpp
Problem D: Pump up Batteries Bill is a boss of security guards. He has pride in that his men put on wearable computers on their duty. At the same time, it is his headache that capacities of commercially available batteries are far too small to support those computers all day long. His men come back to the office to cha...
[ { "submission_id": "aoj_1219_7227174", "code_snippet": "#include <iostream>\n#include <queue>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nstruct E{\n\tint ot;\n\tint nt;\n\tint t;\n\tint no;\n\tint s;\n\tbool operator<(const E& e)const{\n\t\tif(t!=e.t)return t>e.t;\n\t\treturn no>e.no;...
aoj_1225_cpp
Problem B: e-Market The city of Hakodate recently established a commodity exchange market. To participate in the market, each dealer transmits through the Internet an order consisting of his or her name, the type of the order (buy or sell), the name of the commodity, and the quoted price. In this market a deal can be m...
[ { "submission_id": "aoj_1225_1083098", "code_snippet": "#define _USE_MATH_DEFINES\n#define INF 0x3f3f3f3f\n\n#include <iostream>\n#include <cstdio>\n#include <sstream>\n#include <cmath>\n#include <cstdlib>\n#include <algorithm>\n#include <queue>\n#include <stack>\n#include <limits>\n#include <map>\n#include...
aoj_1222_cpp
Problem G: Telescope Dr. Extreme experimentally made an extremely precise telescope to investigate extremely curi- ous phenomena at an extremely distant place. In order to make the telescope so precise as to investigate phenomena at such an extremely distant place, even quite a small distortion is not allowed. However,...
[ { "submission_id": "aoj_1222_3709885", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\nusing ll = long long;\n// #define int ll\nusing PII = pair<ll, ll>;\n\n#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)\n#define REP(i, n) FOR(i, 0, n)\n#define ALL(x) x.begin(), x.end()\n\ntempl...
aoj_1226_cpp
Problem C: Fishnet A fisherman named Etadokah awoke in a very small island. He could see calm, beautiful and blue sea around the island. The previous night he had encountered a terrible storm and had reached this uninhabited island. Some wrecks of his ship were spread around him. He found a square wood-frame and a long...
[ { "submission_id": "aoj_1226_3043409", "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-10;\nconst double INF = 1e12;\n#define EQ(n,m) (abs((n)-(m)) < EPS)\n#...
aoj_1224_cpp
Problem A: Starship Hakodate-maru The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls. There, however, is an inconvenience. The shapes of the fuel containers # 1 and # 2 are always cubic and regular tetrahedral respectively. B...
[ { "submission_id": "aoj_1224_4858248", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int n;\n while(cin >>n,n){\n int ans = 0;\n for(int i=0;i*i*i<151200; i++){\n int sum = 0;\n for(int j=0; sum <= n ;j++){\n ans = ma...
aoj_1229_cpp
Problem F: Young, Poor and Busy Ken and Keiko are young, poor and busy. Short explanation: they are students, and ridden with part-time jobs. To make things worse, Ken lives in Hakodate and Keiko in Tokyo. They want to meet, but since they have neither time nor money, they have to go back to their respective jobs immed...
[ { "submission_id": "aoj_1229_2940627", "code_snippet": "#include<bits/stdc++.h>\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define BIG_NUM 2000000000\n#define MOD 1000000007\n#define EPS 0.000000001\nusing namespace std;\n\n\n#define NUM 100\n#define BASE 480\n#define MAX 600\n\nenum T...
aoj_1228_cpp
Problem E: Beehives Taro and Hanako, students majoring in biology, have been engaged long in observations of beehives. Their interest is in finding any egg patterns laid by queen bees of a specific wild species. A queen bee is said to lay a batch ofeggs in a short time. Taro and Hanako have never seen queen bees laying...
[ { "submission_id": "aoj_1228_2649936", "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_1232_cpp
Problem A: Calling Extraterrestrial Intelligence Again A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November l6, l974. The message consisted of l679 bits and was meant to be translated to a rectangular picture with 23 × 7...
[ { "submission_id": "aoj_1232_10896784", "code_snippet": "#include<bits/stdc++.h>\n// #include<atcoder/all>\n// #include<boost/multiprecision/cpp_int.hpp>\n\nusing namespace std;\n// using namespace atcoder;\n// using bint = boost::multiprecision::cpp_int;\nusing ll = long long;\nusing ull = unsigned long lo...
aoj_1230_cpp
Problem G: Nim Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones on the table (we know the number of stones exactly). We play in turn and at each turn, you or I can remove one to four stones from the heap. You play first and the one who removed the last stone loses. In ...
[ { "submission_id": "aoj_1230_9710661", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint n;\nmap <pair <int, int>, int> mp;\n\nbool get_res(vector <int> &v, int id, int s) {\n if(s == 0) return 1;\n if(mp[{id, s}]) return mp[{id, s}];\n\n bool res = 0;\n for(int i = 1; i <= ...
aoj_1237_cpp
Problem F: Shredding Company You have just been put in charge of developing a new shredder for the Shredding Company. Although a ``normal'' shredder would just shred sheets of paper into little pieces so that the contents would become unreadable, this new shredder needs to have the following unusual basic characteristi...
[ { "submission_id": "aoj_1237_3989783", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n//repetition\n#define FOR(i,a,b) for(ll i=(a);i<(b);++i)\n#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)\n\n//container util\n#define all(x) (x).begin(),(x).end()\n\n//typedef\ntypedef long long ll;\...
aoj_1239_cpp
Problem H: Viva Confetti Do you know confetti ? They are small discs of colored paper, and people throw them around during parties or festivals. Since people throw lots of confetti, they may end up stacked one on another, so there may be hidden ones underneath. A handful of various sized confetti have been dropped on a...
[ { "submission_id": "aoj_1239_4761256", "code_snippet": "#include<iostream>\n#include<cfloat>\n#include<cassert>\n#include<cmath>\n#include<cstdio>\n#include<vector>\n#include<set>\n#include<algorithm>\n\nusing namespace std;\n\n#define EPS (1e-15)\n#define equals(a, b) (fabs((a) - (b)) < EPS )\n#define dle(...
aoj_1234_cpp
Problem C: GIGA Universe Cup Following FIFA World Cup, a larger competition called ``GIGA Universe Cup'' is taking place somewhere in our universe. Both FIFA World Cup and GIGA Universe Cup are two rounds competitions that consist of the first round, also known as ``group league,'' and the second called ``final tournam...
[ { "submission_id": "aoj_1234_4943973", "code_snippet": "#include <stdio.h>\n#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i,n) for (int i = 0; i < (n); ++i)\n#define Inf 1000000000\n\nvector<double> p(9);\n\nvector<vector<string>> get(vector<pair<pair<string,string>,pair<int,int>>> S){\n\n\tma...
aoj_1233_cpp
Problem B: Equals are Equals Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were...
[ { "submission_id": "aoj_1233_8484392", "code_snippet": "#include <bits/stdc++.h>\n\nconstexpr int W = 26;\nusing Var = std::array<int, W>;\nstd::ostream& operator<<(std::ostream& os, const Var& var) {\n os << '(';\n for (int i = 0; i < W; i++) {\n if (var[i] == 0) continue;\n os << '(' <...
aoj_1238_cpp
Problem G: True Liars After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had heard from patriarchs in his childhood. This must be t...
[ { "submission_id": "aoj_1238_5010193", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstring>\nusing namespace std;\n\nconst int N = 2010;\nint fa[N], siz[N], a[N], f[N][N], pre[N][N], ans[N], b[N], c[N]; \nbool vis[N], in[N];\nint findfa(int x) {\n\treturn fa[x] == x ? x : fa[x] = findfa(...
aoj_1241_cpp
Problem B: Lagrange's Four-Square Theorem The fact that any positive integer has a representation as the sum of at most four positive squares (i.e. squares of positive integers) is known as Lagrange’s Four-Square Theorem. The first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission ...
[ { "submission_id": "aoj_1241_10895268", "code_snippet": "#include<bits/stdc++.h>\n// #include<atcoder/all>\n// #include<boost/multiprecision/cpp_int.hpp>\n\nusing namespace std;\n// using namespace atcoder;\n// using bint = boost::multiprecision::cpp_int;\nusing ll = long long;\nusing ull = unsigned long lo...
aoj_1247_cpp
Problem H: Monster Trap Once upon a time when people still believed in magic, there was a great wizard Aranyaka Gondlir. After twenty years of hard training in a deep forest, he had finally mastered ultimate magic, and decided to leave the forest for his home. Arriving at his home village, Aranyaka was very surprised a...
[ { "submission_id": "aoj_1247_8388160", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define chmin(x,y) x = min(x,y)\n#define chmax(x,y) x = max(x,y)\n#define BIG_NUM 2000000000\n#define HUGE_NUM 4000000000000000000 //オーバーフローに...
aoj_1243_cpp
Problem D: Weather Forecast You are the God of Wind. By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else. But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small hu...
[ { "submission_id": "aoj_1243_10865810", "code_snippet": "#include<cstdio>\n#include<iostream>\n#include<cstring>\n#include<cmath>\n#include<cstdlib>\n#include<vector>\n#include<stack>\n#include<algorithm>\n#include<queue>\n#include<string>\n#define OK 1\n#define INF 2147483647\n#define LINF 9223372036854775...