group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_1231_cpp
Problem H: Super Star During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors or singers. It is a revolutionary theory in as...
[ { "submission_id": "aoj_1231_10848858", "code_snippet": "//\n// main.cpp\n// poj 2069 Problem B : Super Star\n//\n// Created by nuu_tong on 2018/4/20.\n// Copyright © 2018年 apple. All rights reserved.\n//\n\n#include <iostream>\n#include <cmath>\n#include <cstdio>\nusing namespace std;\nstruct Point\n{\...
aoj_1246_cpp
Problem G: Concert Hall Scheduling You are appointed director of a famous concert hall, to save it from bankruptcy. The hall is very popular, and receives many requests to use its two fine rooms, but unfortunately the previous director was not very efficient, and it has been losing money for many years. The two rooms a...
[ { "submission_id": "aoj_1246_9706976", "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_1242_cpp
Problem C: Area of Polygons Yoko’s math homework today was to calculate areas of polygons in the xy -plane. Vertices are all aligned to grid points (i.e. they have integer coordinates). Your job is to help Yoko, not good either at math or at computer programming, get her home- work done. A polygon is given by listing t...
[ { "submission_id": "aoj_1242_10851351", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<algorithm>\n#include<cmath>\nusing namespace std;\nconst double eps=1e-8;\nstruct Point{double x,y;}p[1005];\nstruct seg{Point A,B;}s[1005];\nstruct SEG{int x,y;SEG(int _x=0,int _y=0){x=_x;y=_y;}}t[1005];...
aoj_1250_cpp
Problem C: Leaky Cryptography The ACM ICPC judges are very careful about not leaking their problems, and all communications are encrypted. However, one does sometimes make mistakes, like using too weak an encryption scheme. Here is an example of that. The encryption chosen was very simple: encrypt each chunk of the inp...
[ { "submission_id": "aoj_1250_4304282", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long int;\nusing ull = unsigned long long int;\nusing P = pair<ll, ll>;\n\nll decode(string s){\n ll res = 0;\n for(auto c : s){\n res <<= 4;\n if(isdigit(c)){\n ...
aoj_1245_cpp
Problem F: Gap Let’s play a card game called Gap. You have 28 cards labeled with two-digit numbers. The first digit (from 1 to 4) represents the suit of the card, and the second digit (from 1 to 7) represents the value of the card. First, you shuffle the cards and lay them face up on the table in four rows of seven car...
[ { "submission_id": "aoj_1245_10853948", "code_snippet": "#include <iostream>\n#include <cstring>\n#include <climits>\n#include <queue>\n#include <unordered_set>\n \nusing namespace std;\n \nclass State\n{\npublic:\n /**\n * 表格数字\n */\n int table[4][8];\n /**\n * 移动回数\n */\n int t...
aoj_1248_cpp
Problem A: The Balance Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Alth...
[ { "submission_id": "aoj_1248_10852694", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nll EX_GCD(ll a, ll b, ll& x, ll& y) {\n\tll d = a;\n\tif (b != 0) {\n\t\td = EX_GCD(b, a % b, y, x);\n\t\ty -= (a / b) * x;\n\t}\n\telse {\n\t\tx = 1;\n\t\ty = 0;\n\t}\n\treturn ...
aoj_1249_cpp
Problem B: Make a Sequence Your company’s next product will be a new game, which is a three-dimensional variant of the classic game “Tic-Tac-Toe”. Two players place balls in a three-dimensional space (board), and try to make a sequence of a certain length. People believe that it is fun to play the game, but they still ...
[ { "submission_id": "aoj_1249_10896082", "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_1253_cpp
Problem F: Dice Puzzle Let’s try a dice puzzle. The rules of this puzzle are as follows. Dice with six faces as shown in Figure 1 are used in the puzzle. Figure 1: Faces of a die With twenty seven such dice, a 3 × 3 × 3 cube is built as shown in Figure 2. Figure 2: 3 × 3 × 3 cube When building up a cube made of dice, t...
[ { "submission_id": "aoj_1253_10946393", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nenum POS {\n TOP = 1,\n FRONT,\n RIGHT,\n LEFT,\n BACK,\n BOTTOM\n};\n\n// dice[top][front][pos];\nint dice[7][7][7];\n\nvoid init() {\n int right[7][7] = {};\n right[1][2] = 3;...
aoj_1254_cpp
Problem G: Color the Map You were lucky enough to get a map just before entering the legendary magical mystery world. The map shows the whole area of your planned exploration, including several countries with complicated borders. The map is clearly drawn, but in sepia ink only; it is hard to recognize at a glance which...
[ { "submission_id": "aoj_1254_10852648", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstring>\n#include<cmath>\nusing namespace std;\nconst double eps=1e-5;\nstruct Point\n{ int x,y;\n Point(){}\n Point(int _,int __){x=_;y=__;}\n};\nbool operator == (const Point &x,const Point &y)...
aoj_1255_cpp
Problem H: Inherit the Spheres In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to contain positions and radiuses of spheres. ...
[ { "submission_id": "aoj_1255_6790069", "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_1259_cpp
Problem C: Colored Cubes There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same. Two cubes are said to be identically colored if some suitable rotations of one of th...
[ { "submission_id": "aoj_1259_9220763", "code_snippet": "#include <algorithm>\n#include <cmath>\n#include <cstdlib>\n#include <iomanip>\n#include <iostream>\n#include <list>\n#include <map>\n#include <numeric>\n#include <queue>\n#include <set>\n#include <stack>\n#include <string>\n#include <unordered_set>\n#...
aoj_1258_cpp
Problem B: Book Replacement The deadline of Prof. Hachioji’s assignment is tomorrow. To complete the task, students have to copy pages of many reference books in the library. All the reference books are in a storeroom and only the librarian is allowed to enter it. To obtain a copy of a reference book’s page, a student ...
[ { "submission_id": "aoj_1258_4181658", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <vector>\n#include <array>\n#include <string>\n#include <stack>\n#include <queue>\n#include <deque>\n#include <unordered_map>\n#include <unordered_set>\n#include <set>\n#include <tuple>\n#include <cmath...
aoj_1252_cpp
Problem E: Confusing Login Names Meikyokan University is very famous for its research and education in the area of computer science. This university has a computer center that has advanced and secure computing facilities including supercomputers and many personal computers connected to the Internet. One of the policies...
[ { "submission_id": "aoj_1252_10850969", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing VI = vector<int>;\nusing VVI = vector<VI>;\nusing PII = pair<int, int>;\nusing LL = long long;\nusing VL = vector<LL>;\nusing VVL = vector<VL>;\nusing PLL = pair<LL, LL>;\nusing VS = vector<strin...
aoj_1260_cpp
Problem D: Organize Your Train In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. All freight trains travel at night, so these trains containing various types of cars are settled in your parking lines early in the mo...
[ { "submission_id": "aoj_1260_10851287", "code_snippet": "#include <cmath>\n#include <ctime>\n#include <cstdio>\n#include <cctype>\n#include <cstdlib>\n#include <cstring>\n#include <iostream>\n#include <sstream>\n#include <algorithm>\n#include <set>\n#include <stack>\n#include <queue>\n#include <string>\n#in...
aoj_1261_cpp
Problem E: Mobile Computing There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful stones on the planet, and the Yaen people love to collect them. They bring the stones back home and make nice mobile arts of them to decorate their 2-dimensional living rooms. In their 2-dimensio...
[ { "submission_id": "aoj_1261_4673799", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <algorithm>\n#include <iostream>\n#include <cmath>\n#include <vector>\nusing namespace std;\n\nconst int N = 7, M = 1 << N;\nint tr[M]; //-1: root, 0: no use, else:left value\nint value[M];\nint ...
aoj_1257_cpp
Problem A: Sum of Consecutive Prime Numbers Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representat...
[ { "submission_id": "aoj_1257_10734986", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nset<int>primes;\nint main(){\n int n;\n while(true){\n cin>>n;\n primes.clear();\n if(n==0)\n break;\n for(int i=2;i<=n;++i)\n primes.insert(i);\n ...
aoj_1263_cpp
Problem G: Network Mess Gilbert is the network admin of Ginkgo company. His boss is mad about the messy network cables on the floor. He finally walked up to Gilbert and asked the lazy network admin to illustrate how computers and switches are connected. Since he is a programmer, he is very reluctant to move throughout ...
[ { "submission_id": "aoj_1263_1352467", "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\nusing namespace std;\n\nconst int MAX_V = 50 * 30;\nconst int IINF = INT_MAX;\n\nstruct Edge { int src,dst; };\nvector<Edge> G[MAX_V];\nvector<int> comp...
aoj_1262_cpp
Problem F: Atomic Car Race In the year 2020, a race of atomically energized cars will be held. Unlike today’s car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of t...
[ { "submission_id": "aoj_1262_3167974", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n int n;\n while ( cin >> n, n ) {\n vector<int> a(n+1);\n vector<double> d(10001, 100000000.0);\n d[0] = 0;\n vector<int> is(10001, 0);\n a[0] = 0;\n for ( int i = 1; i...
aoj_1265_cpp
Problem I: Shy Polygons You are given two solid polygons and their positions on the xy -plane. You can move one of the two along the x -axis (they can overlap during the move). You cannot move it in other directions. The goal is to place them as compactly as possible, subject to the following condition: the distance be...
[ { "submission_id": "aoj_1265_10848496", "code_snippet": "/*\n * Created By phyxnj@uestc\n * Last Compiler:\n * Sun, 29 Jul 2012 02:07:44 +0800\n */\n#include <cstdio>\n#include <cstring>\n#include <ctime>\n#include <algorithm>\n#include <cstdlib>\n#include <cmath>\n#include <set>\n#include <vector>\n#...
aoj_1267_cpp
Problem B: How I Mathematician Wonder What You Are! After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician, uses a big astronomical telescope and lets his image processing program count stars. The hardest part of the program is to judge if a shining object in the sky is r...
[ { "submission_id": "aoj_1267_3894056", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cmath>\n#include <cstring>\n\n#include <iostream>\n#include <complex>\n#include <string>\n#include <algorithm>\n#include <numeric>\n#include <vector>\n#include <queue>\n#include <stack>\n#include <map>\n...
aoj_1269_cpp
Problem D: Sum of Different Primes A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers n and k , you should count the number of ways to express n as a sum of k different primes. Here, two ways are considered to be the same if they sum up t...
[ { "submission_id": "aoj_1269_11031582", "code_snippet": "//____ ____.__ __ _________ .__ .__ ________\n//\\ \\ / /|__| _____/ |_ ___________ \\_ ___ \\| |__ _____ _________ |__| / _____/_____ ____ ____\n// \\ Y / | |/ ___\\ __...
aoj_1266_cpp
Problem A: How I Wonder What You Are! One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be limi...
[ { "submission_id": "aoj_1266_4858020", "code_snippet": "#include <iostream> \n#include<vector>\n#include<algorithm>\n#include<map>\n#include<string>\n#include<iomanip>\n#include<set>\n#include<queue>\n#include<deque>\n#include<sstream>\n#include<cmath>\n#include<bitset>\nusing namespace std;\n#define rep(i,...
aoj_1268_cpp
Problem C: Cubic Eight-Puzzle Let's play a puzzle using eight cubes placed on a 3 × 3 board leaving one empty square. Faces of cubes are painted with three colors. As a puzzle step, you can roll one of the cubes to the adjacent empty square. Your goal is to make the specified color pattern visible from above by a numbe...
[ { "submission_id": "aoj_1268_10852687", "code_snippet": "#include<cmath>\n#include<cstdio>\n#include<cstring>\n#include<iostream>\nusing namespace std;\nconst int n=3;\nconst int dx[]={-1,1,0,0},dy[]={0,0,-1,1};\nint fx,fy,t[4][4],ans;\nstruct node{\n\tint x,y;\n\tnode(int x=0,int y=0):x(x),y(y){}\n}a[4][4]...
aoj_1273_cpp
Problem H: The Best Name for Your Baby In the year 29XX, the government of a small country somewhere on the earth introduced a law restricting first names of the people only to traditional names in their culture, in order to preserve their cultural uniqueness. The linguists of the country specifies a set of rules once ...
[ { "submission_id": "aoj_1273_10851276", "code_snippet": "#include <cctype>\n#include <cstddef>\n#include <cstring>\n#include <functional>\n#include <iostream>\n#include <map>\n#include <queue>\n#include <string>\n#include <utility>\n#include <vector>\nint n, l, tot, to[501];\nstd::string s[51], f[21][501];\...
aoj_1264_cpp
Problem H: Bingo A Bingo game is played by one gamemaster and several players. At the beginning of a game, each player is given a card with M × M numbers in a matrix (See Figure 10). As the game proceeds, the gamemaster announces a series of numbers one by one. Each player punches a hole in his card on the announced nu...
[ { "submission_id": "aoj_1264_10853849", "code_snippet": "#include <iostream>\n#include <string.h>\n#include <cstdio>\n#include <algorithm>\n#include <vector>\n#include <map>\nusing namespace std;\n\nconst int maxn = 7, maxv = 107, maxt = 10007, maxnum = 100000000;\n int n, m, res, total;\n int has...
aoj_1272_cpp
Problem G: Polygons on the Grid The ultimate Tantra is said to have been kept in the most distinguished temple deep in the sacred forest somewhere in Japan. Paleographers finally identified its location, surprisingly a small temple in Hiyoshi, after years of eager research. The temple has an underground secret room bui...
[ { "submission_id": "aoj_1272_9593544", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Point {\n int x, y;\n int cross(const Point p) const { return x * p.y - y * p.x; }\n Point operator-(const Point p) const { return {x - p.x, y - p.y}; }\n int operator*(const Point p) const {...
aoj_1275_cpp
Problem A: And Then There Was One Let’s play a stone removing game. Initially, n stones are arranged on a circle and numbered 1, ... , n clockwise (Figure 1). You are also given two numbers k and m . From this state, remove stones one by one following the rules explained below, until only one remains. In step 1, remove...
[ { "submission_id": "aoj_1275_10895099", "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_1270_cpp
Problem E: Manhattan Wiring There is a rectangular area containing n × m cells. Two cells are marked with "2", and another two with "3". Some cells are occupied by obstacles. You should connect the two "2"s and also the two "3"s with non-intersecting lines. Lines can run only vertically or horizontally connecting cente...
[ { "submission_id": "aoj_1270_10865943", "code_snippet": "#include <bits/stdc++.h>\ntypedef unsigned int T;\nT n, m;\nT ns[10][10];\nbool vis[10][10][70000];\nT ans[10][10][70000];\nT san[] = {\n\t1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049\n};\n\nT f(T x, T y, T S) {\n\tif (x >= n) {\n\t\tif (S) ret...
aoj_1277_cpp
Problem C: Minimal Backgammon Here is a very simple variation of the game backgammon, named “Minimal Backgammon”. The game is played by only one player, using only one of the dice and only one checker (the token used by the player). The game board is a line of ( N + 1) squares labeled as 0 (the start) to N (the goal). ...
[ { "submission_id": "aoj_1277_3231955", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n int N, T, L, B;\n cout << fixed << setprecision(6);\n while (cin >> N >> T >> L >> B, N) {\n map<int, bool> Lose;\n for (int i = 0; i < L; i++) {\n int l;\n cin >> l;\n...
aoj_1271_cpp
Problem F: Power Calculus Starting with x and repeatedly multiplying by x , we can compute x 31 with thirty multiplications: x 2 = x × x , x 3 = x 2 × x , x 4 = x 3 × x , ... , x 31 = x 30 × x . The operation of squaring can appreciably shorten the sequence of multiplications. The following is a way to compute x 31 wit...
[ { "submission_id": "aoj_1271_10852802", "code_snippet": "/*\n *Author: Zhaofa Fang\n *Created time: 2013-09-09-16.49 星期一\n */\n#include <cstdio>\n#include <cstdlib>\n#include <sstream>\n#include <iostream>\n#include <cmath>\n#include <cstring>\n#include <algorithm>\n#include <string>\n#include <utilit...
aoj_1276_cpp
Problem B: Prime Gap The sequence of n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n . For example, (24, 25, 26, 27, 28) between 23 and 29 is a prime gap of length 6. Your mission is to...
[ { "submission_id": "aoj_1276_10803560", "code_snippet": "#define _CRT_SECURE_NO_WARNINGS\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define int long long\n#define endl '\\n'\n#define print(v) for(auto& x:v)cout<<x<<' ';cout<<endl\n\nconst int N = 2e6;\nint minp[N];\nbitset<N> vi...
aoj_1279_cpp
Problem E: Geometric Map Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane. Figure 4 is an example of a street map, where some line segments represent streets and the others ar...
[ { "submission_id": "aoj_1279_4161973", "code_snippet": "#include<iostream>\n#include<string>\n#include<cstdio>\n#include<vector>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<iomanip>\n#include<queue>\n#include<ciso646>\n#include<random>\n#include<map>\n#include<set>\n#include<bitset...
aoj_1280_cpp
Problem F: Slim Span Given an undirected weighted graph G , you should find one of spanning trees specified as follows. The graph G is an ordered pair ( V , E ), where V is a set of vertices { v 1 , v 2 , ... , v n } and E is a set of undirected edges { e 1 , e 2 , ... , e m }. Each edge e ∈ E has its weight w ( e ). A...
[ { "submission_id": "aoj_1280_11066219", "code_snippet": "#include <iostream>\n#include <vector>\n#include <tuple>\n#include <algorithm>\nusing namespace std;\n\nclass unionfind{\npublic:\n unionfind(int n): n_(n), m_(n) {\n parent_.resize(n);\n size_.resize(n);\n for(int i=0; i<n; i+...
aoj_1282_cpp
Problem H: Bug Hunt In this problem, we consider a simple programming language that has only declarations of one- dimensional integer arrays and assignment statements. The problem is to find a bug in the given program. The syntax of this language is given in BNF as follows: where < new line > denotes a new line charact...
[ { "submission_id": "aoj_1282_10680131", "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 std;\nusing namespace __gnu_pbds;\n\n\nstruct custom_hash {\nstatic uint64_t splitmix64(u...
aoj_1278_cpp
Problem D: Lowest Pyramid You are constructing a triangular pyramid with a sheet of craft paper with grid lines. Its base and sides are all of triangular shape. You draw the base triangle and the three sides connected to the base on the paper, cut along the outer six edges, fold the edges of the base, and assemble them...
[ { "submission_id": "aoj_1278_10067849", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\n#define rep(i,n) for(int i=0;i<n;i++)\n#define rep2(i,s,t) for(int i=s;i<t;i++)\n\nll sqrtz(ll x){\n if(x<0)return -201;\n ll z=sqrt(x)+2;\n while(z*z>x){\n z--;\n...
aoj_1283_cpp
Problem I: Most Distant Point from the Sea The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: "Where is the most distant point from the sea?" The answer to this question for Honshu was found in 1996. The most distant point is located in former Us...
[ { "submission_id": "aoj_1283_8998626", "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_1281_cpp
Problem G: The Morning after Halloween You are working for an amusement park as an operator of an obakeyashiki , or a haunted house, in which guests walk through narrow and dark corridors. The house is proud of their lively ghosts, which are actually robots remotely controlled by the operator, hiding here and there in ...
[ { "submission_id": "aoj_1281_10851166", "code_snippet": "#include<cstdio>\n#include<cstring>\n#include<cctype>\n#include<queue>\nusing namespace std;\n\nconst int maxs = 20;\nconst int maxn = 150;\nconst int dx[]= {1,-1,0,0,0};\nconst int dy[]= {0,0,1,-1,0};\n\ninline int ID(int a, int b, int c)\n{\n ret...
aoj_1287_cpp
Problem C: Stopped Watches In the middle of Tyrrhenian Sea, there is a small volcanic island called Chronus. The island is now uninhabited but it used to be a civilized island. Some historical records imply that the island was annihilated by an eruption of a volcano about 800 years ago and that most of the people in th...
[ { "submission_id": "aoj_1287_9666489", "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_1286_cpp
Problem B: Expected Allowance Hideyuki is allowed by his father Ujisato some 1000 yen bills every month for his pocket money. In the first day of every month, the number of bills is decided as follows. Ujisato prepares n pieces of m -sided dice and declares the cutback k . Hideyuki rolls these dice. The number of bills...
[ { "submission_id": "aoj_1286_10895025", "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_1292_cpp
Problem H: Top Spinning Spinning tops are one of the most popular and the most traditional toys. Not only spinning them, but also making one’s own is a popular enjoyment. One of the easiest way to make a top is to cut out a certain shape from a cardboard and pierce an axis stick through its center of mass. Professional...
[ { "submission_id": "aoj_1292_4783909", "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\n#define LOOP 50000\n...
aoj_1284_cpp
Problem J: The Teacher’s Side of Math One of the tasks students routinely carry out in their mathematics classes is to solve a polynomial equation. It is, given a polynomial, say X 2 - 4 X + 1, to find its roots (2 ± √3). If the students’ task is to find the roots of a given polynomial, the teacher’s task is then to fi...
[ { "submission_id": "aoj_1284_10851232", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cstdlib>\n#include <cmath>\n#include <cctype>\n#include <algorithm>\n#include <vector>\n#include <set>\n#include <map>\n#include <iomanip>\n#include <cassert>\n\nusing namespace std...
aoj_1295_cpp
Problem A: Cubist Artwork International Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the museum building. The artwork is a collection of cubes that are piled up on ...
[ { "submission_id": "aoj_1295_5841742", "code_snippet": "#pragma region Macros\n#include <bits/stdc++.h>\nusing namespace std;\ntemplate <class T> inline bool chmax(T &a, T b) {\n if(a < b) {\n a = b;\n return 1;\n }\n return 0;\n}\ntemplate <class T> inline bool chmin(T &a, T b) {\n ...
aoj_1289_cpp
Problem E: Spherical Mirrors A long time ago in a galaxy, far, far away, there were N spheres with various radii. Spheres were mirrors, that is, they had reflective surfaces . . . . You are standing at the origin of the galaxy (0, 0, 0), and emit a laser ray to the direction ( u , v , w ). The ray travels in a straight...
[ { "submission_id": "aoj_1289_7221053", "code_snippet": "#include <iostream>\n#include <cmath>\nusing namespace std;\n\nstruct Point3D {\n\tdouble px, py, pz;\n};\n\nPoint3D operator+(const Point3D &a1, const Point3D &a2) {\n\treturn Point3D{ a1.px + a2.px, a1.py + a2.py, a1.pz + a2.pz };\n}\n\nPoint3D opera...
aoj_1288_cpp
Problem D: Digits on the Floor Taro attempts to tell digits to Hanako by putting straight bars on the floor. Taro wants to express each digit by making one of the forms shown in Figure 1. Since Taro may not have bars of desired lengths, Taro cannot always make forms exactly as shown in Figure 1. Fortunately, Hanako can...
[ { "submission_id": "aoj_1288_10946400", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\nusing namespace std;\nint n, xa[10010], xb[10010], ya[10010], yb[10010], v[1010][1010], xx1, xx2, q1[10010];\nint q[10010], qq[10010], r, ll, rr, in[10010], v1[10010], ans[100], c1, c2, c3;\ns...
aoj_1291_cpp
Problem G: Search of Concatenated Strings The amount of information on the World Wide Web is growing quite rapidly. In this information explosion age, we must survive by accessing only the Web pages containing information relevant to our own needs. One of the key technologies for this purpose is keyword search. By usin...
[ { "submission_id": "aoj_1291_10851194", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstring>\n#include<algorithm>\nusing namespace std;\n\nconst int N=12;\nint i,j,n,m;\nchar s[6000],ss[6000];\nchar c[20][50];\nbool f[5500][1<<N];\nint len,ll,l[N+3];\nbool b[5030][N+1];\n\nvoid check(int...
aoj_1290_cpp
Problem F: Traveling Cube On a small planet named Bandai, a landing party of the starship Tadamigawa discovered colorful cubes traveling on flat areas of the planet surface, which the landing party named beds. A cube appears at a certain position on a bed, travels on the bed for a while, and then disappears. After a lo...
[ { "submission_id": "aoj_1290_10946409", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <queue>\n#include <algorithm>\n\nusing namespace std;\n\n#define K\t0\t// Black\n#define W\t128\t// White\n#define R\t1\t// Red\n#define G\t2\t// Green\n#define B\t3\t// Blue\n#define...
aoj_1300_cpp
Problem F: Chemist's Math You have probably learnt chemical equations (chemical reaction formulae) in your high-school days. The following are some well-known equations. 2H 2 + O 2 → 2H 2 O (1) C a (OH) 2 + CO 2 → C a CO 3 + H 2 O ...
[ { "submission_id": "aoj_1300_1055603", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <vector>\n#include <queue>\n#include <cmath>\n#include <algorithm>\n#include <functional>\n#include <map>\n#include <cctype>\nusing namespace std;\n#define rep(i,n) for(int i=0;i<(n);++i)\n#define rep1(i...
aoj_1294_cpp
Problem J: Zigzag Given several points on a plane, let’s try to solve a puzzle connecting them with a zigzag line. The puzzle is to find the zigzag line that passes through all the given points with the minimum number of turns. Moreover, when there are several zigzag lines with the minimum number of turns, the shortest...
[ { "submission_id": "aoj_1294_10853309", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstdlib>\n#include<algorithm>\n#include<cstring>\n#include<cmath>\n#include<ctime>\n#include<map>\n#include<string>\n#include<vector>\n#include<set>\n\nusing namespace std;\n#define For(i,l,r) for (int i ...
aoj_1299_cpp
Problem E: Origami Through-Hole Origami is the traditional Japanese art of paper folding. One day, Professor Egami found the message board decorated with some pieces of origami works pinned on it, and became interested in the pinholes on the origami paper. Your mission is to simulate paper folding and pin punching on t...
[ { "submission_id": "aoj_1299_3228821", "code_snippet": "#include <iostream>\n#include <cstdio>\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;\n#define EQ(n,m) (abs(...
aoj_1296_cpp
Problem B: Repeated Substitution with Sed Do you know "sed," a tool provided with Unix? Its most popular use is to substitute every occurrence of a string contained in the input string (actually each input line) with another string β . More precisely, it proceeds as follows. Within the input string, every non-overlappi...
[ { "submission_id": "aoj_1296_9003254", "code_snippet": "// (⁠◕⁠ᴗ⁠◕⁠✿⁠)\n\n// #pragma GCC target(\"avx2\")\n// #pragma GCC optimize(\"O3\")\n// #pragma GCC optimize(\"unroll-loops\")\n#include <bits/stdc++.h>\n#define rep(i, n) for (ll i = 0; i < (n); i++)\n#define srep(i, s, n) for (ll i = s; i < (n); i++)\...
aoj_1297_cpp
Problem C: Swimming Jam Despite urging requests of the townspeople, the municipal office cannot afford to improve many of the apparently deficient city amenities under this recession. The city swimming pool is one of the typical examples. It has only two swimming lanes. The Municipal Fitness Agency, under this circumst...
[ { "submission_id": "aoj_1297_10853354", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <iostream>\n#include <algorithm>\n\nusing namespace std;\n\nint n, tot, tot2, ans, lamp [100], lamp2 [100], Time [100], t [100];\n\nstruct data\n{\n\tint Time, lamp;\n} a [100];\n\nbool cmpp (int x, int ...
aoj_1303_cpp
Problem I: Hobby on Rails ICPC (International Connecting Points Company) starts to sell a new railway toy. It consists of a toy tramcar and many rail units on square frames of the same size. There are four types of rail units, namely, straight (S), curve (C), left-switch (L) and right-switch (R) as shown in Figure 9. A...
[ { "submission_id": "aoj_1303_4937474", "code_snippet": "#include<iostream>\n#include<cassert>\nusing namespace std;\n#define REP(i,b,n) for(int i=b;i<n;i++)\n#define rep(i,n) REP(i,0,n)\n\n#define N 0\n#define E 1\n#define S 2\n#define W 3\n\nint dx[]={0,1,0,-1};\nint dy[]={-1,0,1,0};\nint curdir[]={S,W,N...
aoj_1298_cpp
Problem D: Separate Points Numbers of black and white points are placed on a plane. Let's imagine that a straight line of infinite length is drawn on the plane. When the line does not meet any of the points, the line divides these points into two groups. If the division by such a line results in one group consisting on...
[ { "submission_id": "aoj_1298_10522105", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define all(v) (v).begin(),(v).end()\n#define pb(a) push_back(a)\n#define rep(i, n) for(int i=0;i<n;i++)\n#define foa(e, v) for(auto&& e : v)\nusing ll = long long;\nconst ll MOD7 = 1000000007, MOD998 = ...
aoj_1301_cpp
Problem G: Malfatti Circles The configuration of three circles packed inside a triangle such that each circle is tangent to the other two circles and to two of the edges of the triangle has been studied by many mathematicians for more than two centuries. Existence and uniqueness of such circles for an arbitrary triangl...
[ { "submission_id": "aoj_1301_10852904", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <cstdlib>\n#include <algorithm>\n#include <cmath>\n#include <iostream>\nusing namespace std;\nstruct Point\n{\n\tdouble x, y;\n}Tri[10];\ndouble length(Point p)\n{\n\treturn (sqrt(p.x * p.x + p.y * p.y))...
aoj_1305_cpp
Problem A: Membership Management Peter is a senior manager of Agile Change Management (ACM) Inc., where each employee is a member of one or more task groups. Since ACM is agile, task groups are often reorganized and their members frequently change, so membership management is his constant headache. Peter updates the me...
[ { "submission_id": "aoj_1305_10739683", "code_snippet": "#include<stdio.h>\n#include<string.h>\n#include<string>\n#include<vector>\n#include<stdlib.h>\n#include<algorithm>\n#include<iostream>\nusing namespace std;\n\nvector<string> q[111];\nint n;\nchar s[300];\n\nint main()\n{\n //freopen(\"x.in\",...
aoj_1307_cpp
Problem C: Towns along a Highway There are several towns on a highway. The highway has no forks. Given the distances between the neighboring towns, we can calculate all distances from any town to others. For example, given five towns (A, B, C, D and E) and the distances between neighboring towns like in Figure C.1, we ...
[ { "submission_id": "aoj_1307_10850484", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <algorithm>\n#include <map>\n#include <iostream>\n#include <vector>\nusing namespace std;\nint d[500];\nint sum[100];\nint n;\nvector<int>ans[1148576];\nint cnt;\nbool vis[1148576];\nint dis[500];\nint n...
aoj_1304_cpp
Problem J: Infected Land The earth is under an attack of a deadly virus. Luckily, prompt actions of the Ministry of Health against this emergency successfully confined the spread of the infection within a square grid of areas. Recently, public health specialists found an interesting pattern with regard to the transitio...
[ { "submission_id": "aoj_1304_10946407", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <cmath>\n#include <algorithm>\nusing namespace std;\n#define rep(i,n) for (int i = 0; i < (n); i++)\nconst int dx[8] = {1,1,1,-1,-1,-1,0,0};\nconst int dy[8] = {1,-1,0,1,-1,0,1,-1};\n...
aoj_1309_cpp
Problem E: The Two Men of the Japanese Alps Two experienced climbers are planning a first-ever attempt: they start at two points of the equal altitudes on a mountain range, move back and forth on a single route keeping their altitudes equal, and finally meet with each other at a point on the route. A wise man told them...
[ { "submission_id": "aoj_1309_10852715", "code_snippet": "#define PII pair<int,int>\n#define PDD pair<double,double>\n#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int N=10240;\nconst double EPS=1E-7;\n\nvector<PDD> v;\nint n,cnt,x[N],y[N],f[N],h[N],nextbase[N],prvbase[N],nxt[102][N],prv[102][N];...
aoj_1306_cpp
Problem B: Balloon Collecting "Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player ...
[ { "submission_id": "aoj_1306_6728978", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\narray<array<array<int,4>,101>,50501> dp;\n\nint main(){\n int n, INF = 1 << 30, r = 50500;\n while(cin >> n, n){\n int ans = -1;\n for(int t = 0; t <= r; t++){\n for(int p ...
aoj_1308_cpp
Problem D: Awkward Lights You are working as a night watchman in an office building. Your task is to check whether all the lights in the building are turned off after all the office workers in the building have left the office. If there are lights that are turned on, you must turn off those lights. This task is not as ...
[ { "submission_id": "aoj_1308_10853874", "code_snippet": "#include <stdio.h>\n#include <string.h>\n#include <algorithm>\n#include <iostream>\n#include <queue>\n#include <map>\n#include <set>\n#include <vector>\n#include <math.h>\n#include <string>\nusing namespace std;\n\nconst int MAXN = 1000;\nint equ,var;...
aoj_1310_cpp
Problem F: Find the Multiples You are given a sequence a 0 a 1 ... a N -1 digits and a prime number Q . For each i ≤ j with a i ≠ 0, the subsequence a i a i +1 ... a j can be read as a decimal representation of a positive integer. Subsequences with leading zeros are not considered. Your task is to count the number of p...
[ { "submission_id": "aoj_1310_10851362", "code_snippet": "#include <cstdio>\n#include <map>\n#include <iostream>\n#include <cstring>\nusing namespace std;\nusing std::map;\nint a[100010];\nmap<long long,int> mp;\nlong long pow_mod(long long a,long long b,long long p)\n{\n\tlong long ans = 1;\n\twhile(b) {\n\...
aoj_1302_cpp
Problem H: Twenty Questions Consider a closed world and a set of features that are defined for all the objects in the world. Each feature can be answered with "yes" or "no". Using those features, we can identify any object from the rest of the objects in the world. In other words, each object can be represented as a fi...
[ { "submission_id": "aoj_1302_10848269", "code_snippet": "#include<iostream>\n#include<fstream>\n#include<iomanip>\n#include<cstdio>\n#include<cstdlib>\n#include<cstring>\n#include<cmath>\n#include<iomanip>\n#include<algorithm>\n#include<list>\n#include<map>\n#include<set>\n#include<queue>\n#include<deque>\n...
aoj_1311_cpp
Problem G: Test Case Tweaking You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they are not interesting. You want to produce a dataset whose answer is a desired value such as the number repres...
[ { "submission_id": "aoj_1311_10848586", "code_snippet": "/* ***********************************************\nAuthor :kuangbin\nCreated Time :2013/11/15 16:30:39\nFile Name :G.cpp\n************************************************ */\n\n#include <stdio.h>\n#include <string.h>\n#include <iostream>\...
aoj_1315_cpp
Problem A: Gift from the Goddess of Programming The goddess of programming is reviewing a thick logbook, which is a yearly record of visitors to her holy altar of programming. The logbook also records her visits at the altar. The altar attracts programmers from all over the world because one visitor is chosen every yea...
[ { "submission_id": "aoj_1315_4851862", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst vector<int> convert={1440,60,1};\nvector<int> month={0,31,28,31,30,31,30,31,31,30,31,30};\n\nint time(string s,string t){\n int M=(s[0]-'0')*10+(s[1]-'0')-1;\n int D=(s[3]-'0')*10+(s[4]-'0')-1...
aoj_1313_cpp
Problem I: Intersection of Two Prisms Suppose that P 1 is an infinite-height prism whose axis is parallel to the z -axis, and P 2 is also an infinite-height prism whose axis is parallel to the y -axis. P 1 is defined by the polygon C 1 which is the cross section of P 1 and the xy -plane, and P 2 is also defined by the ...
[ { "submission_id": "aoj_1313_6066782", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define INF 2000000000 // 2e9\n#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)\n#define all(x) (x).begin(), (x).end()\n#define sq(x) ((x) * (x))\n\n#define rep(i, x) for (int i =...
aoj_1316_cpp
Problem B: The Sorcerer's Donut Your master went to the town for a day. You could have a relaxed day without hearing his scolding. But he ordered you to make donuts dough by the evening. Loving donuts so much, he can't live without eating tens of donuts everyday. What a chore for such a beautiful day. But last week, yo...
[ { "submission_id": "aoj_1316_11047140", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<int, 2>;\nusing a3 = array<ll, 3>;\n\nbool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }\nbool chmax(auto& a, const auto& b) { return a < b ? a = ...
aoj_1314_cpp
Problem J: Matrix Calculator Dr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot use it outside his laboratory because the software consumes much of reso...
[ { "submission_id": "aoj_1314_10908049", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int MOD = 32768;\ntypedef vector<int> List;\ntypedef vector<vector<int>> Matrix;\nMatrix variables[26];\n\nMatrix parseExpr(const char*& p);\n\nvoid skip(const char *&p)\n{\n while ( p && *p...
aoj_1318_cpp
Problem D: Long Distance Taxi A taxi driver, Nakamura, was so delighted because he got a passenger who wanted to go to a city thousands of kilometers away. However, he had a problem. As you may know, most taxis in Japan run on liquefied petroleum gas (LPG) because it is cheaper than gasoline. There are more than 50,000...
[ { "submission_id": "aoj_1318_10849725", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstdlib>\n#include <vector>\n#include <queue>\n#include <map>\n#include <string>\n#include <cstring>\n#include <algorithm>\n\nusing namespace std;\n\nconst int maxn = 6000;\nconst int maxm = 6090;\ncon...
aoj_1317_cpp
Problem C: Weaker than Planned The committee members of the Kitoshima programming contest had decided to use crypto-graphic software for their secret communication. They had asked a company, Kodai Software, to develop cryptographic software that employed a cipher based on highly sophisticated mathematics. According to ...
[ { "submission_id": "aoj_1317_7228208", "code_snippet": "#ifdef LOCAL\n#define _GLIBCXX_DEBUG\n#endif\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing vi = vector<int>;\ntemplate <class T = int>\nusing V = vector<T>;\n\n\n#define repname(a, b, c, d, ...) d\n#define rep(...) ...
aoj_1322_cpp
Problem H: ASCII Expression Mathematical expressions appearing in old papers and old technical articles are printed with typewriter in several lines, where a fixed-width or monospaced font is required to print characters (digits, symbols and spaces). Let us consider the following mathematical expression. It is printed ...
[ { "submission_id": "aoj_1322_5951862", "code_snippet": "#define MOD_TYPE 1\n\n#pragma region Macros\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n//#include <atcoder/all>\n\n\n#include <utility>\n\nnamespace atcoder {\n\nnamespace internal {\n\n// @param m `1 <= m`\n// @return x mod m\nconstexpr long...
aoj_1320_cpp
Problem F: City Merger Recent improvements in information and communication technology have made it possible to provide municipal service to a wider area more quickly and with less costs. Stimulated by this, and probably for saving their not sufficient funds, mayors of many cities started to discuss on mergers of their...
[ { "submission_id": "aoj_1320_10954681", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint n;\nvector<int> ls;\nvector<vector<int>> v; // v[i][j] = overlap length a[i] suffix vs a[j] prefix\nunordered_map<long long,int> cac; // memo for sediv\nunordered_map<int,int> bp; // single-bit -> ...
aoj_1312_cpp
Problem H: Where's Wally Do you know the famous series of children's books named "Where's Wally"? Each of the books contains a variety of pictures of hundreds of people. Readers are challenged to find a person called Wally in the crowd. We can consider "Where's Wally" as a kind of pattern matching of two-dimensional gr...
[ { "submission_id": "aoj_1312_10849705", "code_snippet": "#include <cstdio>\n#include <algorithm>\n#include <vector>\n#include <map>\n#include <set>\n#include <queue>\n#include <stack>\n#include <list>\n#include <cctype>\n#include <functional>\n#include <iterator>\n#include <cstring>\n#include <cmath>\n#incl...
aoj_1323_cpp
Problem I: Encircling Circles You are given a set of circles C of a variety of radii (radiuses) placed at a variety of positions, possibly overlapping one another. Given a circle with radius r , that circle may be placed so that it encircles all of the circles in the set C if r is large enough. There may be more than o...
[ { "submission_id": "aoj_1323_6159804", "code_snippet": "#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\n#include<iostream>\n#include<string>\n#include<cstdio>\n#include<vector>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<iomanip>\n#include<queue>\n#include<cis...
aoj_1319_cpp
Problem E: Driving an Icosahedral Rover After decades of fruitless efforts, one of the expedition teams of ITO (Intersolar Tourism Organization) finally found a planet that would surely provide one of the best tourist attractions within a ten light-year radius from our solar system. The most attractive feature of the p...
[ { "submission_id": "aoj_1319_10851601", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nconst int nt[20][3]={\n{5,1,4},\n{6,2,0},\n{7,3,1},\n{8,4,2},\n{9,0,3},\n{0,10,11},\n{1,11,12},\n{2,12,13},\n{3,13,14},\n{4,14,10},\n{15,5,9},\n{16,6,5},\n{17,7,6},\n{18,8,7},\n{19,9,8},\n{10,19,16},\n{...
aoj_1321_cpp
Problem G: Captain Q′s Treasure You got an old map, which turned out to be drawn by the infamous pirate “Captain Q”. It shows the locations of a lot of treasure chests buried in an island. The map is divided into square sections, each of which has a digit on it or has no digit. The digit represents the number of chests...
[ { "submission_id": "aoj_1321_10851230", "code_snippet": "#include <iostream>\n\n#include <cstdio>\n\n#include <string.h>\n\n#include <string>\n\n#include <algorithm>\n\n#include <map>\n\nusing namespace std;\n\n\nconst int maxn = 16;\n\nconst int inf = 100000000;\n\nstruct node\n\n{\n\n int x, y, c;\n\n}...
aoj_1324_cpp
Problem J: Round Trip Jim is planning to visit one of his best friends in a town in the mountain area. First, he leaves his hometown and goes to the destination town. This is called the go phase. Then, he comes back to his hometown. This is called the return phase. You are expected to write a program to find the minimu...
[ { "submission_id": "aoj_1324_10858211", "code_snippet": "#include<cstdio>\n#include<cstring>\n#include<cmath>\n#include<algorithm>\n#include<iostream>\n#include<queue>\n#include<stack>\n#include<vector>\n#include<map>\n#include<set>\n#include<string>\nusing namespace std;\n#define INF 199999999\n#define eps...
aoj_1325_cpp
Problem A: Ginkgo Numbers We will define Ginkgo numbers and multiplication on Ginkgo numbers. A Ginkgo number is a pair < m , n > where m and n are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers. The multiplication on Ginkgo numbers is defined by < m , n > · < x , y > = < mx − ny , my + nx >. For...
[ { "submission_id": "aoj_1325_10853137", "code_snippet": "#include<cstring>\n#include<string>\n#include<sstream>\n#include<fstream>\n#include<iostream>\n#include<iomanip>\n#include<cstdio>\n#include<cctype>\n#include<algorithm>\n#include<queue>\n#include<deque>\n#include<map>\n#include<set>\n#include<vector>...
aoj_1327_cpp
Problem C: One-Dimensional Cellular Automaton There is a one-dimensional cellular automaton consisting of N cells. Cells are numbered from 0 to N − 1. Each cell has a state represented as a non-negative integer less than M . The states of cells evolve through discrete time steps. We denote the state of the i-th cell at...
[ { "submission_id": "aoj_1327_11043071", "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_1328_cpp
Problem D: Find the Outlier Professor Abacus has just built a new computing engine for making numerical tables. It was designed to calculate the values of a polynomial function in one variable at several points at a time. With the polynomial function f ( x ) = x 2 + 2 x + 1, for instance, a possible expected calculatio...
[ { "submission_id": "aoj_1328_10496662", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nint d;\ndouble a[1003][1004];\ndouble k[20005];\nbool solve(){\n//\tfor(int i=1;i<=d+3;i++){\n\t////\tfor(int j=1;j<=d+2;j++){\n\t//\t\tcout<<a[i][j]<<\" \";\n\t//\t}\n\t//\tcout<<endl;\n\t//}\n\tint n=d+...
aoj_1326_cpp
Problem B: Stylish Stylish is a programming language whose syntax comprises names , that are sequences of Latin alphabet letters, three types of grouping symbols , periods ('.'), and newlines. Grouping symbols, namely round brackets ('(' and ')'), curly brackets ('{' and '}'), and square brackets ('[' and ']'), must ma...
[ { "submission_id": "aoj_1326_9614938", "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_1336_cpp
Problem B: The Last Ant A straight tunnel without branches is crowded with busy ants coming and going. Some ants walk left to right and others right to left. All ants walk at a constant speed of 1 cm/s. When two ants meet, they try to pass each other. However, some sections of the tunnel are narrow and two ants cannot ...
[ { "submission_id": "aoj_1336_10881257", "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_1331_cpp
Problem G: Let There Be Light Suppose that there are some light sources and many spherical balloons. All light sources have sizes small enough to be modeled as point light sources, and they emit light in all directions. The surfaces of the balloons absorb light and do not reflect light. Surprisingly in this world, ball...
[ { "submission_id": "aoj_1331_10958572", "code_snippet": "#include <cstdio>\n#include <set>\n#include <cmath>\nusing namespace std;\nstruct Point\n{\n double x;\n double y;\n double z;\n void read()\n {\n scanf(\"%lf %lf %lf\",&x,&y,&z);\n }\n Point(double x=0,double y=0,double z=...
aoj_1333_cpp
Problem I: Beautiful Spacing Text is a sequence of words, and a word consists of characters. Your task is to put words into a grid with W columns and sufficiently many lines. For the beauty of the layout, the following conditions have to be satisfied. The words in the text must be placed keeping their original order. T...
[ { "submission_id": "aoj_1333_10851267", "code_snippet": "//#include<CSpreadSheet.h>\n\n#include<iostream>\n#include<cmath>\n#include<cstdio>\n#include<sstream>\n#include<cstdlib>\n#include<string>\n#include<string.h>\n#include<cstring>\n#include<algorithm>\n#include<vector>\n#include<map>\n#include<set>\n#i...
aoj_1330_cpp
Problem F: Never Wait for Weights In a laboratory, an assistant, Nathan Wada, is measuring weight differences between sample pieces pair by pair. He is using a balance because it can more precisely measure the weight difference between two samples than a spring scale when the samples have nearly the same weight. He is ...
[ { "submission_id": "aoj_1330_11066164", "code_snippet": "#include <iostream>\n#include <vector>\n#include <utility>\nusing namespace std;\n\nclass unionfind{\npublic:\n unionfind(int n): n_(n) {\n parent_.resize(n);\n size_.resize(n);\n diff_.resize(n);\n for(int i=0; i<n; i++...
aoj_1334_cpp
Problem J: Cubic Colonies In AD 3456, the earth is too small for hundreds of billions of people to live in peace. Interstellar Colonization Project with Cubes (ICPC) is a project that tries to move people on the earth to space colonies to ameliorate the problem. ICPC obtained funding from governments and manufactured s...
[ { "submission_id": "aoj_1334_4876386", "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 10005\n\n...
aoj_1335_cpp
Problem A: Equal Sum Sets Let us consider sets of positive integers less than or equal to n . Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s , r...
[ { "submission_id": "aoj_1335_11030135", "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_1329_cpp
Problem E: Sliding Block Puzzle In sliding block puzzles, we repeatedly slide pieces (blocks) to open spaces within a frame to establish a goal placement of pieces. A puzzle creator has designed a new puzzle by combining the ideas of sliding block puzzles and mazes. The puzzle is played in a rectangular frame segmented...
[ { "submission_id": "aoj_1329_10853885", "code_snippet": "#include<cstdio>\n#include<cstring>\n#include<queue>\n#include<iostream>\nusing namespace std;\nconst int inf=0x3f3f3f3f;\nconst int maxn=60;\nint n,m;\nchar mp[maxn][maxn];\nconst int cx[]={-1,-1,0,1,2,2,0,1};\nconst int cy[]={0,1,2,2,0,1,-1,-1};\nst...
aoj_1338_cpp
Problem D: Clock Hands We have an analog clock whose three hands (the second hand, the minute hand and the hour hand) rotate quite smoothly. You can measure two angles between the second hand and two other hands. Write a program to find the time at which "No two hands overlap each other" and "Two angles between the sec...
[ { "submission_id": "aoj_1338_9808827", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for(int i = 0; i < (n); i++)\n#define srep(i, s, t) for(int i = (s); i < (t); i++)\n#define len(x) ((int)(x).size())\n#define all(x) (x).begin(), (x).end()\ntemplate < class T > bool chm...
aoj_1337_cpp
Problem C: Count the Regions There are a number of rectangles on the x-y plane. The four sides of the rectangles are parallel to either the x -axis or the y -axis, and all of the rectangles reside within a range specified later. There are no other constraints on the coordinates of the rectangles. The plane is partition...
[ { "submission_id": "aoj_1337_10852755", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <map>\n#include <algorithm>\nusing namespace std;\nconst int maxn = 555;\nint l[maxn],r[maxn],t[maxn],b[maxn];\nint X[maxn],Y[maxn],g[maxn][maxn];\nmap<int,int>mpx;\nmap<int,int>mpy;...
aoj_1344_cpp
Problem J: C(O|W|A*RD*|S)* CROSSWORD Puzzle The first crossword puzzle was published on December 21, 1913 by Arthur Wynne. To celebrate the centennial of his great-great-grandfather's invention, John "Coward" Wynne 1 was struggling to make crossword puzzles. He was such a coward that whenever he thought of a tricky clu...
[ { "submission_id": "aoj_1344_5432770", "code_snippet": "#include <iostream>\n#include <string>\n#include <vector>\n#include <cstring>\n#include <algorithm>\n#include <cctype>\n#include <cassert>\n#include <array>\n#include <set>\nusing namespace std;\n\n#define ALL(v) begin(v),end(v)\n\nnamespace{\n\nstruct...
aoj_1332_cpp
Problem H: Company Organization You started a company a few years ago and fortunately it has been highly successful. As the growth of the company, you noticed that you need to manage employees in a more organized way, and decided to form several groups and assign employees to them. Now, you are planning to form n group...
[ { "submission_id": "aoj_1332_10851055", "code_snippet": "#include <cstring>\n#include <cstdio>\n#include <algorithm>\n#include <vector>\n#include <string>\n#include <iostream>\n\nusing namespace std;\n\nconst int MAXN = 1e4+10;\nconst int MAXG = 110;\n\nint n,m;\nint x[MAXN],op[MAXN],y[MAXN];\n\nint f[MAXG]...
aoj_1339_cpp
Problem E: Dragon's Cruller Dragon's Cruller is a sliding puzzle on a torus. The torus surface is partitioned into nine squares as shown in its development in Figure E.1. Here, two squares with one of the sides on the development labeled with the same letter are adjacent to each other, actually sharing the side. Figure...
[ { "submission_id": "aoj_1339_10857961", "code_snippet": "#include<map>\n#include<set>\n#include<cmath>\n#include<queue>\n#include<cctype>\n#include<cstdio>\n#include<vector>\n#include<cstdlib>\n#include<cstring>\n#include<algorithm>\ntypedef long long LL;\n#define HASH 1000003\n#define MAXN 1000010\nint fir...
aoj_1340_cpp
Problem F: Directional Resemblance Vectors have their directions and two vectors make an angle between them. Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle. Input The input is a sequence of datasets. A dataset specifies a set of three-dimensional vectors...
[ { "submission_id": "aoj_1340_10848362", "code_snippet": "#include <bits/stdc++.h>\n//using namespace std;\n\ntypedef long double LD;\n\nconst LD INF = 1e15;\nconst LD eps = 1e-13;\nconst int N = 155555;\n\nint n, m, S, W;\n\ninline LD norm(const LD &x) {\n\treturn x * x;\n}\n\nstruct OriP {\n\tint x, y, z;\...
aoj_1347_cpp
Problem C: Shopping Your friend will enjoy shopping. She will walk through a mall along a straight street, where $N$ individual shops (numbered from 1 to $N$) are aligned at regular intervals. Each shop has one door and is located at the one side of the street. The distances between the doors of the adjacent shops are ...
[ { "submission_id": "aoj_1347_2717021", "code_snippet": "#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <cstdio>\n#include <functional>\n#include <numeric>\n#include <stack>\n#include <queue>\n#include <map>\n#include <set>\n#include <utility>\n#in...
aoj_1342_cpp
Problem H: Don't Burst the Balloon An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom. You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls nor the needles. Java Specific: Submitted ...
[ { "submission_id": "aoj_1342_9782093", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)\n#define rrep(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)), (v)...
aoj_1345_cpp
Problem A: Bit String Reordering You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required. The initial bit string is simply represented by a sequence of bits, while the target is specified ...
[ { "submission_id": "aoj_1345_10500246", "code_snippet": "#include <iostream>\n#include <cassert>\n#include <vector>\n#include <algorithm>\n#include <ranges>\n#include <map>\nnamespace ranges = std::ranges;\nint N, M;\nstd::vector<int> rle(std::vector<int> a) {\n std::vector<int> res;\n for (int i = 0,...
aoj_1341_cpp
Problem G: Longest Chain Let us compare two triples a = (x a , y a , z a ) and b = (x b , y b , z b ) by a partial order ∠ defined as follows. a ∠ b ⇔ x a < x b and y a < y b and z a < z b Your mission is to find, in the given set of triples, the longest ascending series a 1 ∠ a 2 ∠ ... ∠ a k . Input The input is a se...
[ { "submission_id": "aoj_1341_10853188", "code_snippet": "#include<map>\n#include<set>\n#include<queue>\n#include<cctype>\n#include<cstdio>\n#include<vector>\n#include<cstdlib>\n#include<cstring>\n#include<algorithm>\ntypedef long long LL;\n#define MAXN 300010\nint A, B, C = ~(1<<31), M = (1<<16)-1;\nint myR...
aoj_1343_cpp
Problem I: Hidden Tree Consider a binary tree whose leaves are assigned integer weights. Such a tree is called balanced if, for every non-leaf node, the sum of the weights in its left subtree is equal to that in the right subtree. For instance, the tree in the following figure is balanced. Figure I.1. A balanced tree A...
[ { "submission_id": "aoj_1343_10853732", "code_snippet": "#include<map>\n#include<set>\n#include<cmath>\n#include<queue>\n#include<cctype>\n#include<cstdio>\n#include<vector>\n#include<cstdlib>\n#include<cstring>\n#include<algorithm>\ntypedef long long LL;\n#define MAXN 1010\nconst int mt = 131072;\nint a[MA...
aoj_1348_cpp
Problem D: Space Golf You surely have never heard of this new planet surface exploration scheme, as it is being carried out in a project with utmost secrecy. The scheme is expected to cut costs of conventional rovertype mobile explorers considerably, using projected-type equipment nicknamed "observation bullets". Bulle...
[ { "submission_id": "aoj_1348_4963406", "code_snippet": "#include<bits/stdc++.h> \nusing namespace std;\ntypedef long long ll;\ntemplate<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}\ntemplate<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>b)return 0; a=b; return 1;}...
aoj_1349_cpp
Problem E: Automotive Navigation The International Commission for Perfect Cars (ICPC) has constructed a city scale test course for advanced driver assistance systems. Your company, namely the Automotive Control Machines (ACM), is appointed by ICPC to make test runs on the course. The test course consists of streets, ea...
[ { "submission_id": "aoj_1349_10848168", "code_snippet": "#include<map>\n#include<set>\n#include<cmath>\n#include<queue>\n#include<cctype>\n#include<cstdio>\n#include<vector>\n#include<cstdlib>\n#include<cstring>\n#include<algorithm>\ntypedef long long LL;\nbool go[55][55][4];\nbool f[55][55][1010][4];\nstru...