group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_1350_cpp
Problem F: There is No Alternative ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested construction of bridges between islands to resolve inconveniences of using boats between islands, and they demand that all the islands should be reachable from any other islands via one or mor...
[ { "submission_id": "aoj_1350_11017326", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Edge {\n int u, v, w, idx;\n bool inMST = false;\n};\n\nstruct DSU {\n vector<int> parent, rankv;\n DSU(int n) {\n parent.resize(n+1);\n rankv.resize(n+1, 0);\n ...
aoj_1353_cpp
Problem I: Sweet War There are two countries, Imperial Cacao and Principality of Cocoa. Two girls, Alice (the Empress of Cacao) and Brianna (the Princess of Cocoa) are friends and both of them love chocolate very much. One day, Alice found a transparent tube filled with chocolate balls (Figure I.1). The tube has only o...
[ { "submission_id": "aoj_1353_9511556", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\n#define rep(i,n) for(ll i=0;i<n;i++)\n\nint main(){\n ll N,A,B,D=155,an=1e18;\n cin>>N>>A>>B;\n vector<ll> R(N),S(N),SumS(N+1,0);\n rep(i,N){\n cin>>R[i]>>S[i];\n ...
aoj_1351_cpp
Problem G: Flipping Parentheses A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. A string "()" is balanced. Concatenation of two balanced strings are balanced. When a string $s$ is balanced, so is the concatenation of three strings "(", $s$, and ")" in this order. No...
[ { "submission_id": "aoj_1351_10853971", "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 300010\nint N, Q, D, sl[4 * MAXN], sr[...
aoj_1352_cpp
Problem H: Cornering at Poles You are invited to a robot contest. In the contest, you are given a disc-shaped robot that is placed on a flat field. A set of poles are standing on the ground. The robot can move in all directions, but must avoid the poles. However, the robot can make turns around the poles touching them....
[ { "submission_id": "aoj_1352_10850439", "code_snippet": "#include <algorithm>\n#include <iostream>\n#include <cstdio>\n#include <cmath>\n#define eps 1.0e-9\n#define sgn(f) ((f)<(-eps)?-1:((f)>eps))\nusing namespace std;\nconst double pi=acos(-1.0);\nint n,N;\ndouble e[999][999];\nstruct point\n{\n\tdouble ...
aoj_1356_cpp
Problem A Decimal Sequences Hanako learned the conjecture that all the non-negative integers appear in the infinite digit sequence of the decimal representation of $\pi$ = 3.14159265..., the ratio of a circle's circumference to its diameter. After that, whenever she watches a sequence of digits, she tries to count up n...
[ { "submission_id": "aoj_1356_11020302", "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_1357_cpp
Problem B Squeeze the Cylinders Laid on the flat ground in the stockyard are a number of heavy metal cylinders with (possibly) different diameters but with the same length. Their ends are aligned and their axes are oriented to exactly the same direction. We'd like to minimize the area occupied. The cylinders are too he...
[ { "submission_id": "aoj_1357_10511484", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <cassert>\n#include <vector>\n#include <algorithm>\n#include <utility>\n#include <numeric>\n#include <tuple>\n#include <ranges>\nnamespace ranges = std::ranges;\nnamespace views = std::views;\n// #incl...
aoj_1355_cpp
Problem K: $L_{\infty}$ Jumps Given two points $(p, q)$ and $(p', q')$ in the XY-plane, the $L_{\infty}$ distance between them is defined as $max(|p − p'|, |q − q'|)$. In this problem, you are given four integers $n$, $d$, $s$, $t$. Suppose that you are initially standing at point $(0, 0)$ and you need to move to point...
[ { "submission_id": "aoj_1355_10850415", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define fo(i,a,b) for (int i = (a); i < (b); i++)\n#define FO(i,a,b) for (int i = (a); i < (b); i++)\n#define fo2(i,a,b) for (i = (a); i < (b); i++)\n#define pb push_back\n#define eb emplace_back\ntypede...
aoj_1354_cpp
Problem J: Exhibition The city government is planning an exhibition and collecting industrial products. There are $n$ candidates of industrial products for the exhibition, and the city government decided to choose $k$ of them. They want to minimize the total price of the $k$ products. However, other criteria such as th...
[ { "submission_id": "aoj_1354_5960934", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing uint = unsigned int;\nusing ull = unsigned long long;\n#define rep(i,n) for(int i=0;i<int(n);i++)\n#define rep1(i,n) for(int i=1;i<=int(n);i++)\n#define per(i,n) for(int i=int...
aoj_1358_cpp
Problem C Sibling Rivalry You are playing a game with your elder brother. First, a number of circles and arrows connecting some pairs of the circles are drawn on the ground. Two of the circles are marked as the start circle and the goal circle . At the start of the game, you are on the start circle. In each turn of the...
[ { "submission_id": "aoj_1358_10772799", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define all(a) (a).begin(), (a).end()\n#define rep(i, n) for (int i = 0; i < (int)(n); i++)\n#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)\n#define range(i, l, r) for (int i = (int)(l); i < (int...
aoj_1361_cpp
Problem F Deadlock Detection You are working on an analysis of a system with multiple processes and some kinds of resource (such as memory pages, DMA channels, and I/O ports). Each kind of resource has a certain number of instances. A process has to acquire resource instances for its execution. The number of required i...
[ { "submission_id": "aoj_1361_10853918", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <cstring>\n#include <cstdio>\n#include <map>\n#include <set>\n#include <bitset>\n#include <string>\n#include <queue>\n#include <cmath>\n#include <vector>\n#define CLR0(a) (memset(a, 0, sizeof(a)))\n#...
aoj_1363_cpp
Problem H Rotating Cutter Bits The machine tool technology never stops its development. One of the recent proposals is more flexible lathes in which not only the workpiece but also the cutter bit rotate around parallel axles in synchronization. When the lathe is switched on, the workpiece and the cutter bit start rotat...
[ { "submission_id": "aoj_1363_4830348", "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 SIZE 20005\n...
aoj_1359_cpp
Problem D Wall Clocks You are the manager of a chocolate sales team. Your team customarily takes tea breaks every two hours, during which varieties of new chocolate products of your company are served. Everyone looks forward to the tea breaks so much that they frequently give a glance at a wall clock. Recently, your te...
[ { "submission_id": "aoj_1359_10926359", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\n#define pii pair<int, int>\n#define pll pair<ll, ll>\n#define vi vector<int>\n#define vl vector<ll>\n#define ov4(a, b, c, d, name, ...) name\n#define rep3(i, a, b, c) for(ll i = (a)...
aoj_1360_cpp
Problem E Bringing Order to Disorder A sequence of digits usually represents a number, but we may define an alternative interpretation. In this problem we define a new interpretation with the order relation $\prec$ among the digit sequences of the same length defined below. Let $s$ be a sequence of $n$ digits, $d_1d_2 ...
[ { "submission_id": "aoj_1360_10946335", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <cstring>\n#include <cstdio>\n#include <map>\n#include <set>\n#include <bitset>\n#include <string>\n#include <queue>\n#include <cmath>\n#include <vector>\n#define CLR0(a) (memset(a, 0, sizeof(a)))\n#...
aoj_1362_cpp
Problem G Do Geese See God? A palindrome is a sequence of characters which reads the same backward or forward. Famous ones include "dogeeseseegod" ("Do geese see God?"), "amoreroma" ("Amore, Roma.") and "risetovotesir" ("Rise to vote, sir."). An ancient sutra has been handed down through generations at a temple on Tsuk...
[ { "submission_id": "aoj_1362_10946330", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <algorithm>\n#include <cmath>\nusing namespace std;\n\n#define LL long long\n\nchar s[4010];\nchar ans[4010];\nint tot,len;\nLL K;\n\nclass rec{\n\tpublic:\n\tint l;\n\tLL s;\n\tbool bo;\n\trec operator ...
aoj_1367_cpp
Problem A Rearranging a Sequence You are given an ordered sequence of integers, ($1, 2, 3, ..., n$). Then, a number of requests will be given. Each request specifies an integer in the sequence. You need to move the specified integer to the head of the sequence, leaving the order of the rest untouched. Your task is to f...
[ { "submission_id": "aoj_1367_11060475", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nint main(){\n int n,m;cin >> n >> m;\n vector<int> a(n,true);\n \n vector<int> e(m);\n for (int i = 0; i < m; i++)cin >> e[i];\n for (int i = m-1; i >= 0; i--){\n if (a[e[i]-1])...
aoj_1368_cpp
Problem B Quality of Check Digits The small city where you live plans to introduce a new social security number (SSN) system. Each citizen will be identified by a five-digit SSN. Its first four digits indicate the basic ID number (0000 - 9999) and the last one digit is a check digit for detecting errors. For computing ...
[ { "submission_id": "aoj_1368_10862783", "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_1365_cpp
Problem J Post Office Investigation In this country, all international mails from abroad are first gathered to the central post office, and then delivered to each destination post office relaying some post offices on the way. The delivery routes between post offices are described by a directed graph $G = (V,E)$, where ...
[ { "submission_id": "aoj_1365_10865983", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nusing vi = vector<int>;\n\nconst int mxn = 50006;\n\nnamespace DominatorTree {\n\tint dfn[mxn], pre[mxn], pt[mxn], sz;\n\tint semi[mxn], dsu[mxn], idom[mxn], best[mxn];\n\tint get(int x) {\n\t\tif (x...
aoj_1369_cpp
Problem C Distribution Center The factory of the Impractically Complicated Products Corporation has many manufacturing lines and the same number of corresponding storage rooms. The same number of conveyor lanes are laid out in parallel to transfer goods from manufacturing lines directly to the corresponding storage roo...
[ { "submission_id": "aoj_1369_11062785", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nint main(){\n\tint n,m;cin >> n >> m;\n\tvector<pair<int,int>> xy(m);\n\tfor (int i = 0; i < m; i++){\n\t\tint x,y;cin >> x >> y;\n\t\ty--;\n\t\txy[i] = {x,y};\n\t}\n\n\tvector<int> ans(n,1);\n\tvector<...
aoj_1371_cpp
Problem E Infallibly Crack Perplexing Cryptarithm You are asked to crack an encrypted equation over binary numbers. The original equation consists only of binary digits ("0" and "1"), operator symbols ("+", "-", and "*"), parentheses ("(" and ")"), and an equal sign ("="). The encryption replaces some occurrences of ch...
[ { "submission_id": "aoj_1371_10011967", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep2(i, n) for (ll i = 0; i < (n); i++)\n#define rep3(i, a, b) for (ll i = a; i < (b); i++)\n#define overload(a, b, c, d, ...) d\n#define rep(...) overload(__VA_ARGS__, rep...
aoj_1370_cpp
Problem D Hidden Anagrams An anagram is a word or a phrase that is formed by rearranging the letters of another. For instance, by rearranging the letters of "William Shakespeare," we can have its anagrams "I am a weakish speller," "I'll make a wise phrase," and so on. Note that when $A$ is an anagram of $B$, $B$ is an ...
[ { "submission_id": "aoj_1370_10936210", "code_snippet": "#include <iostream>\n#include <vector>\n#include <string>\n#include <bitset>\n#include <chrono>\n#include <random>\n#include <cassert>\n\nusing namespace std;\n\n// --- Global RNG and Prime Moduli ---\nmt19937_64 rng(chrono::steady_clock::now().time_s...
aoj_1366_cpp
Problem K Min-Max Distance Game Alice and Bob are playing the following game. Initially, $n$ stones are placed in a straight line on a table. Alice and Bob take turns alternately. In each turn, the player picks one of the stones and removes it. The game continues until the number of stones on the straight line becomes ...
[ { "submission_id": "aoj_1366_10924911", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <utility>\nusing namespace std;\n\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i,n) for(ll i=0; i<ll(n); i++)\ntemplate<class T>using V = vector<T>;\n\n\nvoid tes...
aoj_1364_cpp
Problem I Routing a Marathon Race As a member of the ICPC (Ibaraki Committee of Physical Competitions), you are responsible for planning the route of a marathon event held in the City of Tsukuba. A great number of runners, from beginners to experts, are expected to take part. You have at hand a city map that lists all ...
[ { "submission_id": "aoj_1364_8974957", "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_1374_cpp
Problem H Animal Companion in Maze George, your pet monkey, has escaped, slipping the leash! George is hopping around in a maze-like building with many rooms. The doors of the rooms, if any, lead directly to an adjacent room, not through corridors. Some of the doors, however, are one-way: they can be opened only from...
[ { "submission_id": "aoj_1374_10854100", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int maxn = 1e5 + 50;\n\nint n , m , fa[maxn] , dfn[maxn] , low[maxn] , vis[maxn] , dfs_clock , scc_idx[maxn] , scc_tot , has_circle , Dp[maxn] , f[maxn] , g[maxn];\nstack < int > stk;\nvector <...
aoj_1373_cpp
Problem G Placing Medals on a Binary Tree You have drawn a chart of a perfect binary tree, like one shown in Figure G.1. The figure shows a finite tree, but, if needed, you can add more nodes beneath the leaves, making the tree arbitrarily deeper. Figure G.1. A Perfect Binary Tree Chart Tree nodes are associated with...
[ { "submission_id": "aoj_1373_10946326", "code_snippet": "#include <bits/stdc++.h>\n \n#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )\n#define REP(i,n) FOR(i,0,n)\n#define YYS(x,arr) for(auto& x:arr)\n#define ALL(x) (x).begin(),(x).end()\n#define SORT(x) sort( (x).begin(),(x).end() )\n#define RE...
aoj_1372_cpp
Problem F Three Kingdoms of Bourdelot You are an archaeologist at the Institute for Cryptic Pedigree Charts, specialized in the study of the ancient Three Kingdoms of Bourdelot. One day, you found a number of documents on the dynasties of the Three Kingdoms of Bourdelot during excavation of an ancient ruin. Since the e...
[ { "submission_id": "aoj_1372_10848526", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef unsigned long long LL;\nconst int NAME=300+10;\nconst int MAXN=100000+10;\nconst int MAXS=1010;\nint n,m,cnt,a[NAME][NAME],vis[MAXS];\nstruct node{\n int from,to;\n};\nvector<node> S[MAXS];\nv...
aoj_1377_cpp
Problem K Black and White Boxes Alice and Bob play the following game. There are a number of straight piles of boxes. The boxes have the same size and are painted either black or white. Two players, namely Alice and Bob, take their turns alternately. Who to play first is decided by a fair random draw. In Alice's turn, ...
[ { "submission_id": "aoj_1377_10851363", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define mem(t, v) memset ((t) , v, sizeof(t))\n#define all(x) x.begin(),x.end()\n#define un(x) x.erase(unique(all(x)), x.end())\n#define sf(n) scanf(\"%d\", &n)\n#define sff(a,b) s...
aoj_1379_cpp
Problem B Parallel Lines Given an even number of distinct planar points, consider coupling all of the points into pairs. All the possible couplings are to be considered as long as all the given points are coupled to one and only one other point. When lines are drawn connecting the two points of all the coupled point ...
[ { "submission_id": "aoj_1379_10851338", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef complex<int> Coord;\nCoord p[16],q[16];\nint m,use[16];\nint Cross(Coord A,Coord B)\n{\n\treturn A.real()*B.imag()-A.imag()*B.real();\n}\nint dfs(int k,int s)\n{\n\tint ans=0;\n\tif(k==m/2)\n\t\tf...
aoj_1376_cpp
Problem J Cover the Polygon with Your Disk A convex polygon is drawn on a flat paper sheet. You are trying to place a disk in your hands to cover as large area of the polygon as possible. In other words, the intersection area of the polygon and the disk should be maximized. Input The input consists of a single test cas...
[ { "submission_id": "aoj_1376_10848997", "code_snippet": "#include <bits/stdc++.h>\n#define ll long long\n#define pl pair <ll,ll>\n#define ps pair <string,string>\n#define vi vector <int>\n#define vl vector <ll>\n#define vpi vector <pi>\n...
aoj_1381_cpp
Problem D Making Perimeter of the Convex Hull Shortest The convex hull of a set of three or more planar points is, when not all of them are on one line, the convex polygon with the smallest area that has all the points of the set on its boundary or in its inside. Your task is, given positions of the points of a set, ...
[ { "submission_id": "aoj_1381_10953401", "code_snippet": "// #define _GLIBCXX_DEBUG\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1LL << 60;\n#define rep(i, a) for(ll i = 0; i < (a); i++)\n#define all(a) begin(a), end(a)\n#define sz(a) (a).size()\ntemplate<class T> in...
aoj_1375_cpp
Problem I Skinny Polygon You are asked to find a polygon that satisfies all the following conditions, given two integers, $x_{bb}$ and $y_{bb}$. The number of vertices is either 3 or 4. Edges of the polygon do not intersect nor overlap with other edges, i.e., they do not share any points with other edges except for t...
[ { "submission_id": "aoj_1375_10851227", "code_snippet": "#include <stdio.h>\n#include <bits/stdtr1c++.h>\n\n#define clr(ar) memset(ar, 0, sizeof(ar))\n#define read() freopen(\"lol.txt\", \"r\", stdin)\n#define dbg(x) cout << #x << \" = \" << x << endl\n#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - ...
aoj_1384_cpp
Problem G Rendezvous on a Tetrahedron One day, you found two worms $P$ and $Q$ crawling on the surface of a regular tetrahedron with four vertices $A$, $B$, $C$ and $D$. Both worms started from the vertex $A$, went straight ahead, and stopped crawling after a while. When a worm reached one of the edges of the tetrahe...
[ { "submission_id": "aoj_1384_10023790", "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 ll long long\n#define P pair<long double, long double>\n\nlong double S(P a, P b, P c) {\n long double x1 = b.first - a.first;\n long double x...
aoj_1380_cpp
Problem C Medical Checkup Students of the university have to go for a medical checkup, consisting of lots of checkup items, numbered 1, 2, 3, and so on. Students are now forming a long queue, waiting for the checkup to start. Students are also numbered 1, 2, 3, and so on, from the top of the queue. They have to under...
[ { "submission_id": "aoj_1380_11017034", "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_1389_cpp
Digits Are Not Just Characters Mr. Manuel Majorana Minore made a number of files with numbers in their names. He wants to have a list of the files, but the file listing command commonly used lists them in an order different from what he prefers, interpreting digit sequences in them as ASCII code sequences, not as numbe...
[ { "submission_id": "aoj_1389_3337249", "code_snippet": "#include <iostream>\n#include <string>\n#include <algorithm>\n#include <functional>\n#include <vector>\n#include <utility>\n#include <cstring>\n#include <iomanip>\n#include <numeric>\n#include <cmath>\n#include <queue>\n#define full(c) c.begin() c.end(...
aoj_1383_cpp
Problem F Pizza Delivery Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street sections. Reversals will be on one single street section between two adja...
[ { "submission_id": "aoj_1383_10852693", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\n#define FOR(i,s,t) for(int (i) = (s); (i)< (t); (i)++)\n#define FORR(i,s,t) for(int (i) = (s); (i) > (t); (i)--)\n#define debug(x) cout<<#x<<\": \"<<x<<endl;\n\ntypedef long long LL;\ntypedef vector<LL...
aoj_1385_cpp
Problem H Homework Taro is a student of Ibaraki College of Prominent Computing. In this semester, he takes two courses, mathematics and informatics. After each class, the teacher may assign homework. Taro may be given multiple assignments in a single class, and each assignment may have a different deadline. Each assi...
[ { "submission_id": "aoj_1385_10954685", "code_snippet": "// #define _GLIBCXX_DEBUG\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1LL << 60;\n#define rep(i, a) for(ll i = 0; i < (a); i++)\n#define all(a) begin(a), end(a)\n#define sz(a) (a).size()\ntemplate<class T> in...
aoj_1382_cpp
Problem E Black or White Here lies a row of a number of bricks each painted either black or white. With a single stroke of your brush, you can overpaint a part of the row of bricks at once with either black or white paint. Using white paint, all the black bricks in the painted part become white while originally white...
[ { "submission_id": "aoj_1382_10790335", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\n#define ull unsigned long long\n#define ld long double\n#define pb push_back\n#define mkp make_pair\n#define fi first\n#define se second\n#define pii pair<int, int>\n#define all(x...
aoj_1387_cpp
Problem J String Puzzle Amazing Coding Magazine is popular among young programmers for its puzzle solving contests offering catchy digital gadgets as the prizes. The magazine for programmers naturally encourages the readers to solve the puzzles by writing programs. Let's give it a try! The puzzle in the latest issue ...
[ { "submission_id": "aoj_1387_10952908", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1LL << 60;\n#define rep(i, a) for(ll i = 0; i < (a); i++)\n#define all(a) begin(a), end(a)\n#define sz(a) (a).size()\nbool chmax(auto &a, auto b) { return a > b ? a ...
aoj_1396_cpp
Four-Coloring You are given a planar embedding of a connected graph. Each vertex of the graph corresponds to a distinct point with integer coordinates. Each edge between two vertices corresponds to a straight line segment connecting the two points corresponding to the vertices. As the given embedding is planar, the lin...
[ { "submission_id": "aoj_1396_7119704", "code_snippet": "#include <queue>\n#include <vector>\n#include <cassert>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n\nint quadrant(int x, int y) {\n\tif (y == 0) return (x > 0 ? 0 : 4);\n\tif (x == 0) return (y > 0 ? 2 : 6);\n\treturn (y > 0 ? (x...
aoj_1386_cpp
Problem I Starting a Scenic Railroad Service Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a scenic valley will arise a big boom, but not quite sure how big the boom will be. A market survey was ordered and Jim has just received an ...
[ { "submission_id": "aoj_1386_10853364", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\n#define FOR(i,s,t) for(int (i) = (s); (i)< (t); (i)++)\n#define FORR(i,s,t) for(int (i) = (s); (i) > (t); (i)--)\n#define debug(x) cout<<#x<<\": \"<<x<<endl;\n\ntypedef long long LL;\ntypedef vector<LL...
aoj_1390_cpp
Arithmetic Progressions An arithmetic progression is a sequence of numbers $a_1, a_2, ..., a_k$ where the difference of consecutive members $a_{i+1} - a_i$ is a constant ($1 \leq i \leq k-1$). For example, the sequence 5, 8, 11, 14, 17 is an arithmetic progression of length 5 with the common difference 3. In this probl...
[ { "submission_id": "aoj_1390_11016106", "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_1394_cpp
Fair Chocolate-Cutting You are given a flat piece of chocolate of convex polygon shape. You are to cut it into two pieces of precisely the same amount with a straight knife. Write a program that computes, for a given convex polygon, the maximum and minimum lengths of the line segments that divide the polygon into two e...
[ { "submission_id": "aoj_1394_10416402", "code_snippet": "// AOJ #1394 Fair Chocolate-Cutting\n// 2025.4.24\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ld = long double;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0, c = gc();\n\tdo n = 10*n + (c & 0xf), c = gc(); while (c >= '0...
aoj_1391_cpp
Emergency Evacuation The Japanese government plans to increase the number of inbound tourists to forty million in the year 2020, and sixty million in 2030. Not only increasing touristic appeal but also developing tourism infrastructure further is indispensable to accomplish such numbers. One possible enhancement on tra...
[ { "submission_id": "aoj_1391_11016213", "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_1392_cpp
Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, " ICPC " is a subsequence of " MICROPROCESSOR ". A common subsequence of two sequences is a subsequence of both seq...
[ { "submission_id": "aoj_1392_10848683", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <cstdio>\n#include <cstring>\n\nusing namespace std;\n\nconst int maxn = 4444;\nint dp[maxn][maxn];\nchar P[maxn], Q[maxn];\nint nextp[maxn][2], nextq[maxn][2];\nint vis[maxn][maxn];\n\nint main()\n{...
aoj_1388_cpp
Problem K Counting Cycles Given an undirected graph, count the number of simple cycles in the graph. Here, a simple cycle is a connected subgraph all of whose vertices have degree exactly two. Input The input consists of a single test case of the following format. $n$ $m$ $u_1$ $v_1$ ... $u_m$ $v_m$ A test case repre...
[ { "submission_id": "aoj_1388_10853230", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntypedef pair<ll,ll> P;\n \nint n,m;\nvector<int> G[100001];\nvector<int> mdfG[100001];\nbool useless[100001];\nint cutted[100001];\nbool used[100001];\nvector<int> route;\nint cmp[...
aoj_1397_cpp
Ranks A finite field F 2 consists of two elements: 0 and 1. Addition and multiplication on F 2 are those on integers modulo two, as defined below. + 0 1 0 0 1 1 1 0 $\times$ 0 1 0 0 0 1 0 1 A set of vectors $v_1, ... , v_k$ over F 2 with the same dimension is said to be linearly independent when, for $c_1, ... , c_k \i...
[ { "submission_id": "aoj_1397_10851172", "code_snippet": "#include \"bits/stdc++.h\"\n#define rep(i,a,n) for(int i=a;i<=n;i++)\n#define per(i,a,n) for(int i=n;i>=a;i--)\n#define pb push_back\n#define mp make_pair\n#define FI first\n#define SE second\n#define maxn 2000\n#define mod 998244353\n#define inf 0x3f...
aoj_1401_cpp
Estimating the Flood Risk Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast to measure the altitude at many spots. As no steep slopes are in the estate,...
[ { "submission_id": "aoj_1401_10857435", "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_1398_cpp
Colorful Tree A tree structure with some colors associated with its vertices and a sequence of commands on it are given. A command is either an update operation or a query on the tree. Each of the update operations changes the color of a specified vertex, without changing the tree structure. Each of the queries asks th...
[ { "submission_id": "aoj_1398_10849670", "code_snippet": "#include <bits/stdc++.h>\n#define PII pair<int, int>\n#define LL long long\nusing namespace std;\nconst int MAXN = 100005;\nconst LL MOD = 998244353;\nconst LL INF = (LL)1e9 + 5;\n\nstruct ST {\n\tint N, maxv[9*MAXN];\n\tvoid init(vector<int> &tour, i...
aoj_1399_cpp
Sixth Sense Ms. Future is gifted with precognition. Naturally, she is excellent at some card games since she can correctly foresee every player's actions, except her own. Today, she accepted a challenge from a reckless gambler Mr. Past. They agreed to play a simple two-player trick-taking card game. Cards for the game ...
[ { "submission_id": "aoj_1399_10998176", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std; \n#define int long long \n#pragma GCC optimize(\"O3,unroll-loops\")\n\nconst int maxn=5000;\nint n;\npair<int,int> a[maxn+2];\nint tmp[maxn+2];\nvector<int>b;\nint mx=0;\n\nbool check(int mid,int pos){\n ...
aoj_1395_cpp
What Goes Up Must Come Down Several cards with numbers printed on them are lined up on the table. We'd like to change their order so that first some are in non-decreasing order of the numbers on them, and the rest are in non-increasing order. For example, (1, 2, 3, 2, 1), (1, 1, 3, 4, 5, 9, 2), and (5, 3, 1) are accept...
[ { "submission_id": "aoj_1395_10953043", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\nstruct tree {\n vector<int> fw; int n;\n tree(int sz) : fw(sz + 1, 0), n(sz) {}\n void update(int id, int val) {\n for( ; id <= n; id += id & -id) fw[id] += val;\n ...
aoj_1402_cpp
Wall Painting Here stands a wall made of a number of vertical panels. The panels are not painted yet. You have a number of robots each of which can paint panels in a single color, either red, green, or blue. Each of the robots, when activated, paints panels between a certain position and another certain position in a c...
[ { "submission_id": "aoj_1402_10851380", "code_snippet": "#include <bits/stdc++.h>\n#define sz(v) ((int)(v).size())\n#define all(v) (v).begin(), (v).end()\nusing namespace std;\nusing lint = long long;\nusing pi = pair<int, int>;\nconst int MAXN = 600005;\nconst int MAXT = 2100000;\n\nstruct seg{\n\tlint tre...
aoj_1404_cpp
Reordering the Documents Susan is good at arranging her dining table for convenience, but not her office desk. Susan has just finished the paperwork on a set of documents, which are still piled on her desk. They have serial numbers and were stacked in order when her boss brought them in. The ordering, however, is not p...
[ { "submission_id": "aoj_1404_10956907", "code_snippet": "#include<bits/extc++.h>\n#define rep(i,n) for(int i = 0; i< (n); i++)\n#define all(a) begin(a),end(a)\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int,int> P;\nconst int MOD = 1000000007;\nconst int inf = (1<<30);\nconst ll INF = (1ull<<...
aoj_1403_cpp
Twin Trees Bros. To meet the demand of ICPC (International Cacao Plantation Consortium), you have to check whether two given trees are twins or not. Example of two trees in the three-dimensional space. The term tree in the graph theory means a connected graph where the number of edges is one less than the number of nod...
[ { "submission_id": "aoj_1403_10946277", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\n\ntemplate<class T> struct Point3D {\n\ttypedef Point3D P;\n\ttypedef const P& R;\n\tT x, y, z;\n\texplicit Point3D(T x=0, T y=0, T z=0) : x(x), y(y), z(z) {}\n\tbool operator<(R...
aoj_1405_cpp
Halting Problem A unique law is enforced in the Republic of Finite Loop. Under the law, programs that never halt are regarded as viruses. Releasing such a program is a cybercrime. So, you want to make sure that your software products always halt under their normal use. It is widely known that there exists no algorithm ...
[ { "submission_id": "aoj_1405_10946316", "code_snippet": "#include <bits/stdc++.h>\n#define sz(v) ((int)(v).size())\n#define all(v) (v).begin(), (v).end()\nusing namespace std;\nusing lint = __int128;\nusing pi = pair<lint, lint>;\nconst int MAXN = 100005;\nconst int mod = 1e9 + 7;\n\nint n;\n// qry[i] : (wh...
aoj_1409_cpp
Fun Region Dr. Ciel lives in a planar island with a polygonal coastline. She loves strolling on the island along spiral paths. Here, a path is called spiral if both of the following are satisfied. The path is a simple planar polyline with no self-intersections. At all of its vertices, the line segment directions turn c...
[ { "submission_id": "aoj_1409_9464485", "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>\n#include <deque>\ntypedef long long ll;\n//typedef long double ld;\ntypedef double ld;\nconst ld IN...
aoj_1406_cpp
Ambiguous Encoding A friend of yours is designing an encoding scheme of a set of characters into a set of variable length bit sequences. You are asked to check whether the encoding is ambiguous or not. In an encoding scheme, characters are given distinct bit sequences of possibly different lengths as their codes. A cha...
[ { "submission_id": "aoj_1406_10956832", "code_snippet": "#include<bits/extc++.h>\n#define rep(i,n) for(int i = 0; i< (n); i++)\n#define all(a) begin(a),end(a)\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int,int> P;\nconst int mod = 998244353;\nconst int inf = (1<<30);\nconst ll INF = (1ull<<6...
aoj_1408_cpp
One-Way Conveyors You are working at a factory manufacturing many different products. Products have to be processed on a number of different machine tools. Machine shops with these machines are connected with conveyor lines to exchange unfinished products. Each unfinished product is transferred from a machine shop to a...
[ { "submission_id": "aoj_1408_10958013", "code_snippet": "#include <bits/extc++.h>\n\nusing namespace std;\n\n#define all(x) begin(x),end(x)\nusing ll = long long;\nusing ull = unsigned long long;\n\nstruct TwoEdgeConnectedComponents {\npublic:\n using Graph = vector<vector<int> >;\n\n Graph g, tree;\n...
aoj_1411_cpp
Three-Axis Views A friend of yours is an artist designing Image-Containing Projection Cubes (ICPCs). An ICPC is a crystal cube with its side of integer length. Some of its regions are made opaque through an elaborate laser machining process. Each of the opaque regions is a cube of unit size aligned with integer coordin...
[ { "submission_id": "aoj_1411_10855278", "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_1415_cpp
Jewelry Size Figure E.1. Jewelry She came up with a new jewelry design. The design uses two parts: a hollow circlet and a convex polygonal component. The design can be customized by specifying the edge lengths of the polygon, which should be multiples of a unit length, so that customers can embed memorial numbers in th...
[ { "submission_id": "aoj_1415_10937367", "code_snippet": "#include<bits/extc++.h>\n#define rep(i,n) for(int i = 0; i<(n); i++)\n#define all(a) begin(i),end(i)\nusing namespace std;\ntypedef long long ll;\ntypedef pair<int,int> P;\nconst int mod = 998244353;\nconst int inf = (1<<30);\nconst ll INF = (1ull<<62...
aoj_1416_cpp
Solar Car Alice and Bob are playing a game of baggage delivery using a toy solar car. A number of poles are placed here and there in the game field. At the start of a game, the solar car is placed right next to a pole, and the same or another pole is marked as the destination. Bob chooses one of the poles and places th...
[ { "submission_id": "aoj_1416_10898109", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i,n) for(ll i=0; i<ll(n); i++)\ntemplate <class T> using V = vector<T>;\ntemplate <class A, class B> void chmax(A& l, const B& r){ if(l < r) ...
aoj_1414_cpp
Colorful Rectangle You are given a set of points on a plane. Each point is colored either red, blue, or green. A rectangle is called colorful if it contains one or more points of every color inside or on its edges. Your task is to find an axis-parallel colorful rectangle with the shortest perimeter. An axis-parallel li...
[ { "submission_id": "aoj_1414_10896017", "code_snippet": "#ifdef NACHIA\n#define _GLIBCXX_DEBUG\n#else\n#define NDEBUG\n#endif\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i,n) for(ll i=0;...
aoj_1407_cpp
Parentheses Editor You are working with a strange text editor for texts consisting only of open and close parentheses. The editor accepts the following three keys as editing commands to modify the text kept in it. ‘ ( ’ appends an open parenthesis (‘ ( ’) to the end of the text. ‘ ) ’ appends a close parenthesis (‘ ) ’...
[ { "submission_id": "aoj_1407_10906534", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for(ll i = 0; i < n; ++i)\n#define vl vector<ll>\n#define vvl vector<vvl>\n\nint main(){\n string s;\n\tcin>>s;\n\t\n\tvl ansst={0};\n\tvl sums{0};\n\tmap<ll,v...
aoj_1413_cpp
Short Coding You participate in a project to explore an asteroid called Yokohama 2020. A maze-like space in its underground was found by a survey a couple of years ago. The project is to investigate the maze more in detail using an exploration robot. The shape of the maze was fully grasped by a survey with ground penet...
[ { "submission_id": "aoj_1413_9852621", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define ALL(a) begin(a),end(a)\n\nint n,m,sx,sy,gx,gy;\nvector<int>ans = {2,13,0,13,5,1}, tmp;\nstring mp[10];\n\nstring out(int op)\n{\n\tif(op==0)\n\t{\n\t\treturn \"LEFT\";\n\t}\n...
aoj_1410_cpp
Draw in Straight Lines You plan to draw a black-and-white painting on a rectangular canvas. The painting will be a grid array of pixels, either black or white. You can paint black or white lines or dots on the initially white canvas. You can apply a sequence of the following two operations in any order. Painting pixels...
[ { "submission_id": "aoj_1410_10860444", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i, n) for(ll i=0; i <ll(n); i++)\ntemplate <class T> using V = vector<T>;\ntemplate <class A, class B>\nbool chmax(A &a, B b) { return a < b ...
aoj_1417_cpp
To be Connected, or not to be, that is the Question An undirected graph is given, each of its nodes associated with a positive integer value. Given a threshold , nodes of the graph are divided into two groups: one consisting of the nodes with values less than or equal to the threshold, and the other consisting of the r...
[ { "submission_id": "aoj_1417_11047162", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)\nconstexpr ll INF = 9009009009009009009LL;\n\nstruct UnionFind {\n vector<int> par, siz;\n UnionFind(int n) : par(n, -1) , si...
aoj_1421_cpp
Suffixes may Contain Prefixes You are playing a game on character strings. At the start of a game, a string of lowercase letters, called the target string , is given. Each of the players submits one string of lowercase letters, called a bullet string , of the specified length. The winner is the one whose bullet string ...
[ { "submission_id": "aoj_1421_10872018", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i, n) for (ll i=0; i<ll(n); i++)\ntemplate <class T> using V = vector<T>;\ntemplate<class A, class B>\nbool chmax(A &a, B b) { return a < b &...
aoj_1419_cpp
High-Tech Detective The problem set document for the Yokohama Chinatown Gluttony Contest was kept in a safe at the headquarters of the Kanagawa Gourmendies Foundation. It was considered to be quite secure, but, in the morning of the very day of the contest, the executive director of the foundation found that the docume...
[ { "submission_id": "aoj_1419_10850949", "code_snippet": "#include <bits/stdc++.h>\n#define sz(x) ((int)(x).size())\n#define all(x) begin(x), end(x)\n#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)\n#define per(i, l, r) for (int i = (l), i##end = (r); i >= i##end; --i)\n#ifdef memset0\...
aoj_1418_cpp
LCM of GCDs You are given a sequence of positive integers, followed by a number of instructions specifying updates to be made and queries to be answered on the sequence. Updates and queries are given in an arbitrary order. Each of the updates replaces a single item in the sequence with a given value. Updates are accumu...
[ { "submission_id": "aoj_1418_11046941", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)\n\ntemplate <typename T>\nclass segtree {\n protected:\n const T E;\n vector<T> _data;\n const function<T(T,T)> _query;\n...
aoj_1426_cpp
Planning Railroad Discontinuation The ICPC Kingdom has a large round lake in its center, and all of its cities are developed around the lake, forming a circle of cities. Because all of them are developed under the same urban plan, the cities are made quite similar. They have exactly the same subway networks. Some of th...
[ { "submission_id": "aoj_1426_10798699", "code_snippet": "#ifdef NACHIA\n#define _GLIBCXX_DEBUG\n#else\n#define NDEBUG\n#endif\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i,n) for(ll i=0;...
aoj_1423_cpp
Lottery Fun Time The biggest fun of lottery is not in receiving the (usually a tiny amount of) prize money, but in dreaming of the big fortune you may possibly (that is, virtually never) receive. You have a number of lottery tickets at hand, each with a six-digit number. All the numbers are different, of course. Tomorr...
[ { "submission_id": "aoj_1423_11062638", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < n; ++i)\nconst ll INF = 1LL << 60;\n\nint main(){\n ll n;\n cin >> n;\n vector<string> s(n);\n unordered_map<string, ll> two_cnt, f...
aoj_1424_cpp
Reversible Compression Data compression is an essential technology in our information society. It is to encode a given string into a (preferably) more compact code string so that it can be stored and/or transferred efficiently. You are asked to design a novel compression algorithm such that even a code string is revers...
[ { "submission_id": "aoj_1424_11008127", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1LL << 60;\n#define rep(i, a) for(ll i = 0; i < (a); i++)\n#define all(a) begin(a), end(a)\n// #define sz(a) (a).size()\nbool chmin(auto& a, auto b) { return a > b ?...
aoj_1427_cpp
It's Surely Complex As you know, a complex number is often represented as the sum of a real part and an imaginary part. $3 + 2i$ is such an example, where $3$ is the real part, $2$ is the imaginary part, and $i$ is the imaginary unit. Given a prime number p and a positive integer n , your program for this problem shoul...
[ { "submission_id": "aoj_1427_10772725", "code_snippet": "#ifdef NACHIA\n// #define -D_GLIBCXX_DEBUG\n#endif\n#include <bits/stdc++.h>\nusing namespace std;\ntemplate <class T> using V = vector<T>;\ntemplate <class T> using VV = V<V<T>>;\nusing ll = long long;\n#define REP(i,n) for(ll i=0; i<ll(n); i++)\n\nt...
aoj_1420_cpp
Formica Sokobanica A new species of ant, named Formica sokobanica , was discovered recently. It attracted entomologists' attention due to its unique habit. These ants do not form colonies. Rather, individuals make up their private nests and keep their food, nuts, in the nests. A nest comprises a lot of small rooms conn...
[ { "submission_id": "aoj_1420_11046668", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)\n\nint main() {\n ll n, m; cin >> n >> m;\n vector<vector<ll>> g(n);\n rep(i, n - 1) {\n ll x, y; cin >> x >> y;\n ...
aoj_1425_cpp
Wireless Communication Network We are setting up a wireless communication network in a mountain range. Communication stations are to be located on the summits. The summits are on a straight line and have different altitudes. To minimize the cost, our communication network should have a tree structure, which is a connec...
[ { "submission_id": "aoj_1425_11062903", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = int;\nusing PLL = pair<ll, ll>;\n#define rep(i, n) for (ll i = 0; i < n; ++i)\nconstexpr ll INF = 2002002002;\n\ntemplate <typename T>\nclass segtree\n{\npublic:\n T E; ...
aoj_1432_cpp
Distributing the Treasure You are the leader of a treasure hunting team. Under your great direction, your team has made a big success in a quest, and got a lot of treasure. The only, but crucial, remaining issue is how to distribute the obtained treasure to the team members. The excavated treasure includes a variety of...
[ { "submission_id": "aoj_1432_10855106", "code_snippet": "#include <bits/stdc++.h>\n#define N 505\nusing namespace std;\ntypedef long long ll;\n\nint n, m, bel[N], in[N], lst[N]; ll dis[N];\nint col[200005];\nvector<int> E[N];\nvector<vector<int> > a; \nvector<vector<ll> > b;\n\nint main() {\n//\tfreopen(\"0...
aoj_1430_cpp
"Even" Division If you talk about an even division in the usual sense of the words, it means dividing a thing equally. Today, you need to think about something different. A graph is to be divided into subgraphs with their numbers of nodes being even, that is, multiples of two. You are given an undirected connected grap...
[ { "submission_id": "aoj_1430_10526024", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <utility>\nusing namespace std;\n\nusing ll = long long;\n#define rep(i,n) for(ll i=0; i<ll(n); i++)\n\n\nvoid testcase(){\n int N, M; cin >> N >> M;\n vector<vector<int>> ad...
aoj_1431_cpp
The Cross Covers Everything A cross-shaped infinite area on the $x$-$y$ plane can be specified by two distinct points as depicted on the figure below. Figure J.1. The cross area specified by two points numbered 2 and 4 Given a set of points on the plane, you are asked to figure out how many pairs of the points form...
[ { "submission_id": "aoj_1431_11062720", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing PLL = pair<ll, ll>;\n#define rep(i, n) for (ll i = 0; i < n; ++i)\nconstexpr ll INF = 9009009009009009009LL;\n\nint main() {\n ll n; cin >> n;\n vector<PLL> pos(n);\n ...
aoj_1440_cpp
Cake Decoration You are ordering a cake to celebrate the New Year. You have to decide the numbers of decoration items to be topped on the cake. Available items are dog figures, cat figures, red candies, and blue candies. You want all four items to decorate the cake, and all the numbers of the four items to be different...
[ { "submission_id": "aoj_1440_10749197", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <utility>\n#include <vector>\n#include <cmath>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define rep(i,n) for(int i=0; i<int(n); i++)\n\nll isqrt(ll v){\n ll w = sqr...
aoj_1441_cpp
Quiz Contest The final round of the annual World Quiz Contest is now at the climax! In this round, questions are asked one by one, and the competitor correctly answering the goal number of questions first will be the champion. Many questions have already been asked and answered. The numbers of questions correctly answe...
[ { "submission_id": "aoj_1441_10525848", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <utility>\nusing namespace std;\n\nusing ll = long long;\n#define rep(i,n) for(ll i=0; i<ll(n); i++)\n\nconst int MOD = 998244353;\n\nstruct Modint {\n int x;\n Modint() : x(...
aoj_1428_cpp
Genealogy of Puppets The Inventive and Creative Puppets Corporation (ICPC) sells a variety of educational puppets for children, and also for grown-ups who were once children and still remember it. To celebrate its centennial anniversary, ICPC has decided to offer for sale a collection of many of its most popular puppet...
[ { "submission_id": "aoj_1428_10997325", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntemplate<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }\ntemplate<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } retur...
aoj_1436_cpp
Move One Coin Some coins are placed on grid points on a two-dimensional plane. No two coins are stacked on the same point. Let's call this placement of coins the source pattern . Another placement of the same number of coins, called the target pattern , is also given. The source pattern does not match the target patter...
[ { "submission_id": "aoj_1436_10994834", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntemplate<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }\ntemplate<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } retur...
aoj_1437_cpp
Incredibly Cute Penguin Chicks The Incredibly Cute Penguin Chicks love to eat worms. One day, their mother found a long string-shaped worm with a number of letters on it. She decided to cut this worm into pieces and feed the chicks. The chicks somehow love International Collegiate Programming Contest and want to eat pi...
[ { "submission_id": "aoj_1437_11011552", "code_snippet": "// #define _GLIBCXX_DEBUG\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1LL << 60;\n#define rep(i, a) for(ll i = 0; i < (a); i++)\n#define all(a) begin(a), end(a)\n#define sz(a) (a).size()\nbool chmin(auto& a, ...
aoj_1439_cpp
Remodeling the Dungeon The Queen of Icpca resides in a castle peacefully. One day, she heard that many secret agents had been active in other nations, and got worried about the security of the castle. The castle has a rectangular dungeon consisting of h rows of w square rooms. Adjacent rooms are separated by a wall. So...
[ { "submission_id": "aoj_1439_11021025", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing lint = long long;\nusing ll = long long;\n#define rep(i, n) for(int i = 0; i < (n); ++i)\n#define all(x) (x).begin(), (x).end()\n\ntemplate<class T1, class T2>\nbool chmin(T1 &a, T2 b) {\n if(b ...
aoj_1438_cpp
Make a Loop Taro is playing with a set of toy rail tracks. All of the tracks are arc-shaped with a right central angle (an angle of 90 degrees), but with many different radii. He is trying to construct a single loop using all of them. Here, a set of tracks is said to form a single loop when both ends of all the tracks ...
[ { "submission_id": "aoj_1438_10994837", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntemplate<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }\ntemplate<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } retur...
aoj_1442_cpp
Traveling Salesperson in an Island You are a salesperson at one of the ports in an island. You have to visit all the ports of the island and then come back to the starting port. Because you cannot swim and are scared of the sea, you have to stay on the land during your journey. The island is modeled as a polygon on a t...
[ { "submission_id": "aoj_1442_10994840", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\ntemplate<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }\ntemplate<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } retur...
aoj_1443_cpp
New Year Festival The ICPC (Incredibly Colossal and Particularly Comfortable) Theater is giving a number of traditional events to celebrate the New Year! Each of the events has its own unalterable duration. Start times of the events are flexible as long as no two events overlap. An event may start immediately after ano...
[ { "submission_id": "aoj_1443_10324479", "code_snippet": "#ifdef NACHIA\n#define _GLIBCXX_DEBUG\n#endif\n\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <utility>\n#include <queue>\nusing namespace std;\nusing ll = long long;\ntemplate<class A, class B> void chmax(A& a, const B& b){ ...
aoj_1446_cpp
Ferris Wheel The big Ferris wheel, Cosmo Clock 21 , is a landmark of Yokohama and adds beauty to the city's night view. The ICPC city also wants something similar. The ICPC city plans to build an illuminated Ferris wheel with an even number of gondolas. All the gondolas are to be colored with one of the given set of ca...
[ { "submission_id": "aoj_1446_10891370", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for (int i = 0; i < n; i++)\n#define all(v) begin(v), end(v)\ntemplate <int modulo>\nstruct modint {\n int x;\n modint() : x(0) {}\n modint(int64_t y) : x(y >= 0 ? y % modulo :...
aoj_1445_cpp
Rank Promotion Quiz Solver is a popular online computer game. Each time a player opens the mobile application of the game, a new quiz is displayed. The player submits an answer to the quiz, and then it is judged either as correct or incorrect, which is accumulated in the database. When the player shows high accuracy fo...
[ { "submission_id": "aoj_1445_11064032", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for(ll i=0;i<n;i++)\n\nint main() {\n ll n, c, p, q;\n cin >> n >> c >> p >> q;\n string S;\n cin >> S;\n\n ll Y = 0, N = 0, rank = 0, reset_index...
aoj_1448_cpp
Chayas Once upon a time, there were a number of chayas (teahouses) along one side of an east-west road in Yokohama. Although the total number of chayas is known, the information about their locations was considered to be lost totally. Recently, a document describing the old townscapes of Yokohama has been found. The do...
[ { "submission_id": "aoj_1448_10986485", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\n#define rep(i, a, b) for (int i = a; i < (b); ++i)\n#define sz(x) (int)(x).size()\n#define all(x) x.begin(), x.end()\ntypedef pair<int, int> pii;\ntypedef vector<int> vi;\ntempla...
aoj_1449_cpp
Color Inversion on a Huge Chessboard You are given a set of square cells arranged in a chessboard-like pattern with n horizontal rows and n vertical columns. Rows are numbered 1 through n from top to bottom, and columns are also numbered 1 through n from left to right. Initially, the cells are colored as in a chessboar...
[ { "submission_id": "aoj_1449_11064211", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for(ll i=0;i<n;i++)\nusing VLL = vector<ll>;\n\nint main() {\n ll n, q;\n cin >> n >> q;\n if (n == 1) {\n rep(i, q) {\n string key;\n...
aoj_1451_cpp
Task Assignment to Two Employees Hanako is the CEO of a small company with two employees. She currently has some number of tasks and aims to earn some profits by making the employees do the tasks. Employees can enhance their skills through the tasks and, with higher skills, a larger profit can be earned from the same t...
[ { "submission_id": "aoj_1451_10863868", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define REP(i, n) for (ll i=0; i<ll(n); i++)\ntemplate <class T> using V = vector<T>;\ntemplate<class A, class B>\nbool chmax(A &a, B b) { return a < b &...
aoj_1447_cpp
Nested Repetition Compression You have a number of strings of lowercase letters to be sent in e-mails, but some of them are so long that typing as they are would be tiresome. As you found repeated parts in them, you have decided to try out a simple compression method in which repeated sequences are enclosed in parenthe...
[ { "submission_id": "aoj_1447_10973431", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\n#define rep(i, a, b) for (int i = a; i < (b); ++i)\n#define sz(x) (int)(x).size()\n#define all(x) x.begin(), x.end()\ntypedef pair<int, int> pii;\ntypedef vector<int> vi;\ntempla...
aoj_1454_cpp
Probing the Disk This is an interactive problem. A thin black disk is laid flat on the square bottom of a white box. The sides of the box bottom are $10^5$ units long. Somehow, you are not allowed to look into the box, but you want to know how large the disk is and where in the box bottom the disk is laid. You know tha...
[ { "submission_id": "aoj_1454_10997207", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for (int i = 0; i < (int)(n); ++i)\nmap<tuple<int, int, int, int>, double> cache;\ndouble query(int x0, int y0, int x1, int y1) {\n if (cache.find({x0, y0, x1, y1}) != cache.end())\n ...
aoj_1462_cpp
Remodeling the Dungeon 2 The Queen of the Kingdom of Icpca resides in a castle peacefully. One day, she decided to remodel the dungeon of the castle. The dungeonis a rectangular grid consisting of square cells. Some cells are enterable rooms, while others are duct spaces which are not enterable. All pairs of adjacent c...
[ { "submission_id": "aoj_1462_10149732", "code_snippet": "#ifdef NACHIA\n#define _GLIBCXX_DEBUG\n#else\n#define NDEBUG\n#endif\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\nusing i64 = long long;\nusing u64 = unsigned long long;\n#define rep(i,n) for(int i=0; i<int(n); i++...
aoj_1450_cpp
Fortune Telling Your fortune is to be told by a famous fortune teller. She has a number of tarot cards and a six-sided die. Using the die, she will choose one card as follows and that card shall tell your future. Initially, the cards are lined up in a row from left to right. The die is thrown showing up one of the numb...
[ { "submission_id": "aoj_1450_11016330", "code_snippet": "#include <bits/stdc++.h>\n\n#define SPED \\\n ios_base::sync_with_stdio(false); ...
aoj_1453_cpp
Do It Yourself? You are the head of a group of $n$ employees including you in a company. Each employee has an employee ID, which is an integer 1 through n, where your ID is 1. Employees are often called by their IDs for short: #1, #2, and so on. Every employee other than you has a unique immediate boss , whose ID is sm...
[ { "submission_id": "aoj_1453_10890422", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for (int i = 0; i < n; i++)\n#define all(v) begin(v), end(v)\nusing ll = long long;\nmultiset<ll> st[500010];\nint main() {\n cin.tie(0);\n ios::sync_with_stdio(false);\n int n...
aoj_1460_cpp
The Farthest Point Anant is on one of the vertices, say the starting vertex, of a rectangular cuboid (a hexahedron with all of its faces being rectangular). The surface of the cuboid constitutes the entire world of the ant. We’d like to know which point on the surface of the cuboid is the farthest for the ant from the ...
[ { "submission_id": "aoj_1460_10054266", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nbool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }\nbool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }\nusing ld = long double;\nusing vec = complex<ld>;\n\nld dist(ld a, ld b, ld c, ld ...
aoj_1464_cpp
Mixing Solutions Let’s prepare for an experiment with the chemical Yokohama Yellow , or YY in short. You have several containers of aqueous solution of YY. While YY is evenly dissolved in each solution, the concentration may differ among containers. You will take arbitrary amounts of solution from some of the containe...
[ { "submission_id": "aoj_1464_10448025", "code_snippet": "//\n// 有理数\n//\n// verified\n// AOJ 1426 Remodeling the Dungeon 2 (ICPC Asia 2024 H)\n// https://onlinejudge.u-aizu.ac.jp/problems/1464\n//\n\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n\n// 有理数\ntemplate<class T> struct frac {\n // ...
aoj_1461_cpp
Beyond the Former Explorer You are standing at the very center of a field, which is divided into a grid of cells running north-south and east-west. A great treasure is hidden somewhere within one of these cells. John Belzoni , a descendant of the famous treasure hunter Giovanni Battista Belzoni , actually discovered th...
[ { "submission_id": "aoj_1461_10133440", "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_1458_cpp
Tree Generators One of the problems in the International Parsing Contest caught your attention. Two expressions are given as input, each representing a procedure to generate a single tree. The gen eration procedure is randomized, meaning different trees may be generated each time the procedure is performed. You are as...
[ { "submission_id": "aoj_1458_11065336", "code_snippet": "//https://zenn.dev/antyuntyun/articles/atcoder-cpp-template\n#include <iostream>\n#include <bits/stdc++.h>\n// #include <atcoder/all>\nusing namespace std;\n// using namespace atcoder;\n\n// clang-format off\n// cin cout の結びつけ解除, stdioと同期しない(入出力非同期化)\...
aoj_1457_cpp
Omnes Viae Yokohamam Ducunt? " Omnes viae Romam ducunt " is an old Latin proverb meaning "all roads lead to Rome." It is still desirable to have access to the capital from all the regions of a country. The Kingdom of Kanagawa has a number of cities, including the capital city, Yokohama. The Ministry of Transport of t...
[ { "submission_id": "aoj_1457_11055587", "code_snippet": "#include<bits/stdc++.h>\n#define rep(i,n) for(ll i=0;i<(ll)(n);i++)\nusing namespace std;\nusing ll=long long;\nusing P=pair<ll,ll>;\n\nconst ll INF=1001001001001001001;\n\nint main(){\n ll n,m;cin>>n>>m;\n vector<ll> p(n);\n rep(i,n)cin>>p[i...