group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_0400_cpp
Maze & Items Maze & Items is a puzzle game in which the player tries to reach the goal while collecting items. The maze consists of $W \times H$ grids, and some of them are inaccessible to the player depending on the items he/she has now. The score the player earns is defined according to the order of collecting items....
[ { "submission_id": "aoj_0400_10272755", "code_snippet": "// AOJ #400 Maze and Items\n// 2025.3.7\n\n#include <bits/stdc++.h>\nusing namespace std;\n\nstruct Edge { int d, req; };\nstruct State { int r, c, req, d; };\n\nint W, H;\npair<int,int> keyPos[12];\nint scoreTab[10][10];\nvector<Edge> edgeCandidate[1...
aoj_0401_cpp
Playing with Stones Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows: Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in each of the areas. Koshiro and Ukiko alternately select an area and perf...
[ { "submission_id": "aoj_0401_11026208", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> vi;\ntypedef vector<vi> vvi;\ntypedef vector<vvi> vvvi;\ntypedef vector<ll> vll;\ntypedef vector<vll> vvll;\ntypedef vector<vvll> vvvll;\ntypedef pair<int,int...
aoj_0402_cpp
K-th Exclusive OR Exclusive OR (XOR) is an operation on two binary numbers $x$ and $y$ (0 or 1) that produces 0 if $x = y$ and $1$ if $x \ne y$. This operation is represented by the symbol $\oplus$. From the definition: $0 \oplus 0 = 0$, $0 \oplus 1 = 1$, $1 \oplus 0 = 1$, $1 \oplus 1 = 0$. Exclusive OR on two non-nega...
[ { "submission_id": "aoj_0402_10799212", "code_snippet": "#include <bits/stdc++.h>\n \nusing namespace std;\n\nusing ll = long long;\n\nconst int LOG = 20;\nconst int X = 1 << LOG;\n\nstruct Trie {\n struct Node {\n vector<int> nxt = {-1, -1};\n int sz = 0;\n };\n\n vector<Node> t = {N...
aoj_0409_cpp
Floor The floor of Dr. Hideyo's house is covered with square tiles. Dr. Hideyo, who has an interest in art, decides to paint the tiles with red, yellow, and blue paint. To begin, he selects one appropriate tile in the room and paint it with the following method. Change the color of the tile to be painted in the followi...
[ { "submission_id": "aoj_0409_5708849", "code_snippet": "#include <iostream>\nusing namespace std;\n\nint fib(int n)\n{\n if(n==0 || n==1) \n return 1;\n return fib(n-1)+fib(n-2);\n}\n\nint main()\n{\n int x, y;\n cin >> x >> y;\n int x_min = 0;\n int x_max = 1;\n int y_min = 0;\n...
aoj_0403_cpp
Road Construction The Zuia Kingdom has finally emerged through annexation of $N$ cities, which are identified by index from $1$ to $N$. You are appointed the Minister of Transport of the newly born kingdom to construct the inter-city road network. To simplify the conceptual design planning, you opted to consider each c...
[ { "submission_id": "aoj_0403_10435662", "code_snippet": "// AOJ #0403 Road Construction\n// 2025.4.30\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tdo n = 10*n + (c & 0xf), c = gc(); while (c >= '0');...
aoj_0410_cpp
Akabeko 20 Akabeko 20 is a group that performs at a dedicated theater in the Izua region. Each member of Akabeko 20 is supposed to participate in a performance every certain number of days. Today's performance was attended by all the members. As a producer, you are asked by the members to tell the combination of the me...
[ { "submission_id": "aoj_0410_10875635", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)\n#define all(a) (a).begin(),(a).end()\n\nint main() {\n cin.tie(nullptr);\n ios_base::sync_with_stdio(false);\n...
aoj_0411_cpp
Arrows $L$ squares are lined up in a row on the left and right. The pieces are placed on top of some of the squares. Each piece is marked with an arrow pointing to the left or to the right. No more than one piece can be placed on a single square. A piece in any square can be moved to an unoccupied square, but it can on...
[ { "submission_id": "aoj_0411_10873461", "code_snippet": "#include<bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, l, n) for(int i = int(l); i < int(n); i++)\n#define ll long long\n#define all(x) (x).begin(), (x).end()\n#define rall(x) (x).rbegin(), (x).rend()\n\ntemplate<class T> bool chmin(T &a, T...
aoj_0418_cpp
Laver Nori (laver) is produced in the villages along the beaches of the Hibara Sea. All laver is formed into rectangles. When drying the laver in the sun, two sheets of laver are placed on the same rug so that the top of the first sheet is parallel to the top of the second sheet. Genm, a part-time worker, can place the...
[ { "submission_id": "aoj_0418_9796637", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i,n) for(int i=0;i<(n);++i)\nusing namespace std;\nusing ll = long long;\n\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n \n vector<int> a(4),b(4);\n rep(i,4) cin >> a[i];\n rep...
aoj_0412_cpp
Castle in the Sky Tsuruga, the Castle in the Sky, floats in the sky above the country of Aizu. There are days when sunlight is blocked by the castle. Compensation is paid to the inhabitants of the areas where sunlight is blocked for a certain number of days. As the compensation payer for the country of Aizu, you will n...
[ { "submission_id": "aoj_0412_10948637", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#if __has_include(<atcoder/all>)\n#include <atcoder/all>\nusing namespace atcoder;\n#endif\n#ifndef ONLINE_JUDGE\n#define _GLIBCXX_DEBUG\n#include <iostream>\ntemplate <typename T, typename U>\nostream& ...
aoj_0414_cpp
Prayers of Iwashiro In the ancient nation of Iwashiro, priests offer prayers to appease disasters when they occur. The priest selects a string $S$ from an ancient text and proceeds with the ritual by repeating the following Pick one place in the string $S$ and update $S$ by replacing a letter written there with another...
[ { "submission_id": "aoj_0414_10873537", "code_snippet": "#include<bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, l, n) for(int i = int(l); i < int(n); i++)\n#define ll long long\n#define all(x) (x).begin(), (x).end()\n#define rall(x) (x).rbegin(), (x).rend()\n\ntemplate<class T> bool chmin(T &a, T...
aoj_0413_cpp
Tournament Record We had a tournament in which $N$ people participated. In the tournament, the participants play against each other one-on-one to decide who wins and who loses. The winner moves on to the next match, and the one who remains in the end is the winner. Since there is only one venue for the tournament, only...
[ { "submission_id": "aoj_0413_10875577", "code_snippet": "#include <bits/stdc++.h>\nusing ll = long long;\nusing namespace std;\ntypedef long double ld;\nusing pii = pair<int,int>;\nusing dat = pair<ld,pair<int,int>>;\nusing pq = priority_queue<dat, vector<dat>, greater<dat>>;\nvector<pii> dir = {{0,1},{1,0}...
aoj_0415_cpp
Dungeion 3 You are a famous adventurer and have already conquered two dungeons. You have obtained a map of a new dungeon with several passages and treasure chests on it. The map shows the value of the treasures in each treasury. You can enter the dungeon from any of the treasuries and escape the dungeon from any of the...
[ { "submission_id": "aoj_0415_10825469", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#ifdef LOCAL\n#include <debug.hpp>\n#else\n#define debug(...)\n#endif\n\nstruct LowLink {\n int N;\n // articulation: 関節点, bridge: 橋\n vector<int> order, low, articulati...
aoj_0421_cpp
Tow Polygons Yae decided to make a polygon by connecting three or more straight sticks and give it to her boyfriend, Jo. The sticks can only be connected at their end points. All end points must be on the same plane. Only two sticks can be connected at a single junction point, and the angle between them can be determin...
[ { "submission_id": "aoj_0421_10851078", "code_snippet": "//#pragma GCC target (\"avx2\")\n//#pragma GCC optimize(\"O3\")\n//#pragma GCC optimize(\"unroll-loops\")\n//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#define _USE_MATH_DEFINES\n#include<iostream>\n#include<strin...
aoj_0424_cpp
Into the Wild In recent years, the country of Izua has been plagued by animals that come down from the mountains to the city. You have done a lot of research to try to bring the animals back to the mountains, and you have discovered the following. Each animal has a unique name. If you insert a letter anywhere in the na...
[ { "submission_id": "aoj_0424_9797246", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i,n) for(int i=0;i<(n);++i)\nusing namespace std;\nusing ll = long long;\n\nstruct Bipartite_Matching\n{\n vector< vector< int > > graph;\n vector< int > dist, match;\n vector< bool > used, vv;\n\n Bipartite_Ma...
aoj_0420_cpp
Digit K At the Aizu Akabeko store, we sell a unique "lottery" called Digit K. Each lottery ticket has $N$ numbers in a row, going from left to right. The numbers written on them are from 1 to 9. The purchaser of a lottery ticket can eliminate $K$ numbers from these numbers and earn points for the number of $N-K$ number...
[ { "submission_id": "aoj_0420_11012035", "code_snippet": "#include <iostream>\n#include <vector>\n#include <queue>\n#include <stack>\n#include <algorithm>\n#include <set>\n#include <map>\nusing ll = long long;\nusing namespace std;\n\nint main(){\n\tint N, K;\n\tcin >> N >> K;\n\tvector<int> A(N);\n\tfor (in...
aoj_0423_cpp
Gym with Many Rules The gym in Izua Village has $N$ units of training equipment, numbered from 1 to $N$. To use a piece of training equipment once, you need one ticket with the number of the equipment written on it. The number of calories burned when using each piece of training equipment is determined for each piece o...
[ { "submission_id": "aoj_0423_11012290", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n \n int N, R;\n if (!(cin >> N >> R)) return 0;\n vector<long long> t(N+1), e(N+1);\n for (int i = 1; i <= N; ++i) ...
aoj_0422_cpp
Bug You are designing the world's most powerful computer system, "Nayuta". However, during the implementation of the prototype of this system, you find a bug that causes the system to stop when the instruction sequence meets certain conditions. The system works by giving an instruction string of length $N$ as a program...
[ { "submission_id": "aoj_0422_11011801", "code_snippet": "#include <iostream>\n#include <vector>\n#include <set>\n#include <map>\n#include <queue>\n#include <deque>\n\n#include <iomanip>\nusing namespace std;\n\nusing ll = long long;\n\nvoid showbit(int bit, int T) {\n\tfor (int i = 0;i < T;i++) if (bit & (1...
aoj_0426_cpp
Sum of the Number of Triangles We are given a rectangular region in the coordinate plane with the origin $O$ at the lower left and the point at coordinates $(W,H)$ at the upper right. Consider a collection of points in this region that contains at least three points whose $x$-coordinates and $y$-coordinates are both in...
[ { "submission_id": "aoj_0426_10998228", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\ntypedef long long ll;\ntypedef vector<int> vi;\ntypedef vector<vi> vvi;\ntypedef vector<vvi> vvvi;\ntypedef vector<ll> vll;\ntypedef vector<vll> vvll;\ntypedef vector<vvll> vvvll;\ntypedef pair<int,int...
aoj_0435_cpp
Highway Network The highway network in Zuia consists of cities (points) and the roads that connect them. The Ivashilo Motorway, which runs through the Ivashilo region, is an important national artery. The upstream sections of the Ivashilo Motorway are constructed as follows. There are $N$ cities (points) assigned the n...
[ { "submission_id": "aoj_0435_9455961", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nint n,m;\nvector<vector<int>>s(51,vector<int>(0));\nvector<int>t(51,0);\n\nvoid dfs(int now,int bit,int cost){\n if(now==n){\n for(int j=1;j<=n;j++){\n if(bit&1<<j){\n t...
aoj_0427_cpp
Resource of the Planet Yanaizu Humanity has finally discovered the planet Yanaizu, which is home to intelligent life. As science progressed on Yanaiizu, collaboration with us gradually became more and more active. On the planet Yanaizu, an insect called Beko is considered to be an important resource. It grows from a la...
[ { "submission_id": "aoj_0427_11012306", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#pragma GCC optimize(\"Ofast,unroll-loops\")\n#pragma GCC target(\"avx2,popcnt\")\n\n// --------- Fast IO ----------\nnamespace fastio {\n static const int SZ = 1 << 20;\n char ibuf[SZ]; int ipos...
aoj_0425_cpp
Chemical Substance Alpha At Aizu Pharmaceutical, we are constantly researching chemical substances. The chemical we are currently researching is code-named "alpha," which has a structure consisting of molecules numbered $1$ through $N$ arranged in a straight line from leftmost to rightmost. Using the technology develop...
[ { "submission_id": "aoj_0425_11004563", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)\n\nint main() {\n\tcin.tie(nullptr);\n\tios_base::sync_with_stdio(false);\n\t\n\tint N, K, Q;\n\tcin >> N >> K >> Q;\...
aoj_0432_cpp
Rotating Photo PCK is developing an application for processing photos by rotating them. In this application, a square photo is input, and then the photo is rotated by several rotation commands, each of which rotates the photo 90 degrees clockwise or counterclockwise around a point in the middle of the photo (the inters...
[ { "submission_id": "aoj_0432_10872765", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for (int i = 0; i < (n); i++)\n#define all(a) a.begin(), a.end()\n\nvector<string> rotate(vector<string> s)\n{\n int n = s.size();\n vector<vector<char>> re...
aoj_0436_cpp
Warehouse Robot Aizu Transport is developing a warehouse guard robot. In our warehouse, points in the warehouse are managed by coordinates (x,y) as shown in the floor plan below. In the warehouse, shelves with square bottoms are arranged in a regular pattern to facilitate the management of cargo. If we represent the po...
[ { "submission_id": "aoj_0436_10875344", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ld=long double;\n#define fi first\n#define se second\n#define i128 __int128_t\n#define all(x) x.begin(),x.end()\n#define rep(i,n) for(int i=0;i<(int)(n);++i)\n#define si(a) (long)(a.size())\ntempla...
aoj_0434_cpp
Processing Machine Aizu Kogyo undertakes manufacturing work using a processing machine. The processing machine owned by Aizu Kogyo is shown on the left in Figure 1. This machine can process any rectangular object, and its width, depth, and height can be freely set. There is a blade 1 cm wide and 1 cm deep on the top of...
[ { "submission_id": "aoj_0434_10873736", "code_snippet": "#include<bits/stdc++.h>\n//#include<atcoder/all>\n\nusing namespace std;\n//using namespace atcoder;\n#define rep(i,n) for(ll i=0; i<n; i++)\n#define rrep(i,n) for(ll i=n-1; i>=0; i--)\n#define print(a) cout<<a<<endl\ntypedef long long ll;\n#define yn...
aoj_0437_cpp
Copy and Sum There are two sequences, A and B, of length $N$. Denote the $i$-th elements of A and B by $a_i$ and $b_i$, respectively. $i$ is an integer between $1$ and $N$. Perform the following operations on these sequences of numbers. copy($x$, $y$, $z$) : replace $a_x, a_{x+1}, ..., a_{x+z-1}$ with $b_y, b_{y+1}, .....
[ { "submission_id": "aoj_0437_11022398", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)\n\ntemplate<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id>\nstruct LazySegTree {\n...
aoj_0438_cpp
Passport A new planet has been found that looks just like Earth. Each planet has countries numbered from $1$ to $N$. These countries are connected by rail and airlines. If there is an air route between country $i$ and country $j$ that satisfies $i When you enter each country, you will have the first letter of that coun...
[ { "submission_id": "aoj_0438_10785688", "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_0439_cpp
Coloured Mountain Hut You are in charge of $N$ huts and the roads that connect them. Each hut has a number from $1$ to $N$. There are $N-1$ paths in total. All paths are the same length and can be taken in either direction. Also, from any hut, you can reach any other hut by going through some of the paths. All the huts...
[ { "submission_id": "aoj_0439_10902262", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing pll = pair<ll, ll>;\n#define vc vector\nusing vl = vc<ll>;\n\n#define ov(a, b, c, name, ...) name\n#define rep2(i, l, r) for (ll i = (l); i < ll(r); i++)\n#define rep1(i, n...
aoj_0444_cpp
Slot Machines Aizu Industry has developed a new slot machine. This slot machine displays $W$ numbers horizontally and $H$ numbers vertically from 0 to 9. An example of the numbers displayed where $W=5$ and $H=3$ is shown in Figure 1. Figure 1: Example of numbers displayed on a slot machine ($W=5, H=3$) In this slot mac...
[ { "submission_id": "aoj_0444_10958156", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nint main() {\n int h, w;\n cin >> w >> h;\n vector<string> s(h);\n for (auto &i : s) cin >> i;\n vector<vector<long long>> c(w, vector<long long>(10, 0));\n vector<vector<long long>> dp...
aoj_0445_cpp
Hanbunko Twin siblings, Yae and Joe, received a rice cracker as a snack from their mother. The rice cracker is shaped like a convex polygon and has slits on all the diagonals to make it easier to break. They want to split the rice cracker into two pieces, but since they are not strong enough, they can only do so by cla...
[ { "submission_id": "aoj_0445_11014143", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\nint main(){\n\tint N;\n\tcin>>N;\n\tll x[N*2+1],y[N*2+1];\n\tfor(int i=1;i<=N;i++){\n\t\tcin>>x[i]>>y[i];\n\t\tx[i+N]=x[i];\n\t\ty[i+N]=y[i];\n\t}\n\tll all=0;\n\tfor(int i=2;i<N;i++)...
aoj_0449_cpp
Persimmon As autumn deepens, the persimmon tree in our garden has borne fruit again this year. However, the weather was not good this year, so there were only three fruits. The sun shone from the top of the persimmon tree and created shadows on the ground, which were circular and overlapped or separated depending on th...
[ { "submission_id": "aoj_0449_9570638", "code_snippet": "#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native\")\n#pragma GCC optimize(\"unroll-loops\")\n#include <bits/stdc++.h>\n\ndouble R;\ndouble X[3], Y[3];\nconst double STEP{1.75 * 1e-5};\ndouble U[3], D[3];\n\ndouble calc(doubl...
aoj_0443_cpp
Minimum MAW A contiguous substring of a string $S$ is a sequence of characters of length zero or more removed from the beginning and the end of $S$, respectively (except for all the characters of $S$ that have been removed). For example, the string abc has six consecutive substrings: a, ab, abc, b, bc, c. Given a strin...
[ { "submission_id": "aoj_0443_10906687", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint main(){\n\tint N;cin >> N;\n\tstring S;cin >> S;\n\tint mn = 28;\n\tfor (int i = 0;i < N;i++) mn = min(mn, S[i]-'a');\n\tint it = 0;\n\tint mx = 0;\n\tchar mm = 'a';\n\tmm +=...
aoj_0447_cpp
Broken Exit The popular game "Broken Exits" is a puzzle game where the goal is to escape from a maze with the least number of moves. The maze consists of $N \times M$ squares and each square is assigned a row number and a column number. A square with row number $r$ and column number $c$ is denoted by ($r, c$). The top ...
[ { "submission_id": "aoj_0447_11014002", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\nstruct dat{\n\tint r,c,cost;\n\tint root;\n};\nint main(){\n\tint N,M;\n\tcin>>N>>M;\n\tauto get_place=[&](int a,int b){\n\t\tint res=0;\n\t\tres+=M*(a-1);\n\t\tres+=b;\n\t\treturn re...
aoj_0448_cpp
Robot Arm PCK Industry is developing a new robot arm. The task of this robot arm is to sort $N$ parts assigned numbers from 1 to $N$ in a single row, in order of decreasing number. The robot arm can select three parts in one operation (they do not have to be next to each other) and perform the following exchange operat...
[ { "submission_id": "aoj_0448_9612568", "code_snippet": "#include <bits/stdc++.h>\n#define ll long long\nusing namespace std;\n\nclass DSU\n{\n\tvector<int> parent, sz;\n\npublic:\n\tDSU(const int size) : parent(size, -1),sz(size,1) {};\n\tint find(const int a)\n\t{\n\t\treturn parent[a] < 0 ? a : parent[a] ...
aoj_0450_cpp
Reorganization of Highway Network The highway network in the country of Zuia consists of cities (points) and the roads that connect them. This highway network has been constructed to meet the following conditions: There are $N$ cities (points) assigned the numbers 1 to $N$. The roads are one-way, and there are only two...
[ { "submission_id": "aoj_0450_11031860", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define rng(i,l,r) for(int i=(l);i<(r);i++)\n#define rrep(i,n) for(int i=(n)-1;i>=0;i--)\n#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)\...
aoj_0451_cpp
Swap and Inversion Number The inversion number of a sequence of length $N$ $\{a_1, a_2,.... . a_N\}$ is the total number of pairs ($a_i, a_j$) of elements satisfying $1 \leq i < j \leq N$ and $a_i > a_j$. The inversion number of a sequence is also known as the number of exchanges in the elementary alignment algorithm, ...
[ { "submission_id": "aoj_0451_10205602", "code_snippet": "// AOJ #451\n// Swap and Inversion Number 2025.2.9\n \n#include <bits/stdc++.h>\nusing namespace std;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() { // 整数の入力\n\tint n = 0, c = gc();\n\tif (c == '-') {\tc = gc();\...
aoj_0452_cpp
Stamp Rally You are in charge of $N$ lodges and the road that connects each lodge. Each lodge has a number from 1 to $N$. There are $N-1$ paths in total. All paths can be traveled in both directions. Also, from any lodge, you can reach other lodges by taking some of the paths. You decide to start a stamp rally by placi...
[ { "submission_id": "aoj_0452_10397825", "code_snippet": "// AOJ #0452 Stamp Rally\n// 2025.4.19\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int MOD = 998244353, G = 3;\nconst ll MERGE_THRESHOLD = 1000000LL;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocke...
aoj_0468_cpp
Sort Riddles A sort riddle is a game in which you guess the original English word from a string of letters in an English word, rearranged in alphabetical order. For example, if you are given the string aet , you can guess that the original English word was eat , ate , and so on. To play this game, PCK, who is not good ...
[ { "submission_id": "aoj_0468_10709130", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nint main(void){\n\tint cnt=0;\n\tstring str;\n\tmap<string,int> mp;\n\tcin>>str;\n\tdo{\n\t\tif(mp[str]==0){\n\t\t\tcnt++;\n\t\t\tmp[str]=1;\n\t\t}\n\t}while(next_permutation(str.begin(),str.end()));\n\t...
aoj_0463_cpp
Fishermen Following the Rules Kenjiro is a fisherman who collects fish from the lake. The entire lake is rectangular in shape. The lake is lined with a grid of square-shaped administrative blocks. On the map, the coordinates of the upper-left control area of the lake are (1,1), and the coordinates of the i-th control a...
[ { "submission_id": "aoj_0463_11009998", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)\n\ntemplate<typename T>\nstruct FenwickTree {\n\tvector<T> data;\n\tFenwickTree(int size) : data(size + 1, 0) {}\n\t\...
aoj_0464_cpp
Rotating Mass Game A special feature of the Idua High School Sports Festival is the rotating mass game. In this game, the students rotate and turn their bodies in response to the teacher's command. The students move in unison, which is very cool. The $N$ students participating in the mass game are numbered from 1 to $N...
[ { "submission_id": "aoj_0464_11031261", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)\n\ntemplate<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id>\nstruct LazySegTree {\n...
aoj_0465_cpp
Commuting Route In the town of Aizu, where PCK lives, there are N points and $N-1$ roads connecting each point. Each point is numbered from $1$ to $N$, and all roads can be traveled in both directions. Also, from any point, you can reach other points by taking some paths. PCK, the CEO of IZUA Corporation, decides to ch...
[ { "submission_id": "aoj_0465_10844716", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n// #include<atcoder/all>\n// using mint = atcoder::modint998244353;\nusing ld = long double;\n#define fi first\n#define se second\n#define all(x) x.begin(),x.end()\n#define rep(i,n) for(int i=0;i<(int)(n...
aoj_0460_cpp
Fundraising Street Mr. Tokuichi has come up with the idea of making a Buddha statue for the people of the Isua region and has decided to raise funds for the project. He plans to travel along a road known as the "fundraising road," a road that is said to collect donations well when traveled. A fund-raising highway is a ...
[ { "submission_id": "aoj_0460_10875372", "code_snippet": "#include<bits/stdc++.h>\n#include <climits>\nusing namespace std;\n#define ll long long \n#define ld long double\n#define rep(i,N) for(int i=0;i<(int)N;i++)\n#define all(x) x.begin(),x.end()\n#define fi first\n#define se second\n#define pb push_back\n...
aoj_0469_cpp
Disaster Response Simulation PCK is participating in the World Robot Challenge in the Disaster Response Simulation category. The mission of this category is to rescue people who are stranded in a building. The interior of the building is represented by a plane divided into $H$ rows and $W$ columns, where each square is...
[ { "submission_id": "aoj_0469_11031116", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0};\n\nint main(){\n\tint h, w, n;\n\tcin >> h >> w >> n;\n\tvector<string> S(h);\n\tfor(auto &i : S) cin >> i;\n\tvector<array<int, 2>> A(n);\n\tfor(auto &i...
aoj_0472_cpp
Placement Games PCK bought a new game to accompany his long autumn nights. The game board is rectangular in shape, divided into equal-sized square sections of $H$ in vertical direction and $W$ in horizontal direction. The player places one rectangular piece on the board that uses $R$ of vertical space and $C$ of horizo...
[ { "submission_id": "aoj_0472_11027000", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define rng(i,l,r) for(int i=(l);i<(r);i++)\n#define rrep(i,n) for(int i=(n)-1;i>=0;i--)\n#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)\n#define int long long\...
aoj_0477_cpp
Square Factors In the ancient nation of Iwashiro, there was little rain this year, and the people were in trouble. That's why you, a new priest, have decided to perform a rain-making ceremony at Ryugasawa. In the rain-making ceremony, you chant the prayer incantation written in the prayer book for the Dragon God to mak...
[ { "submission_id": "aoj_0477_11015697", "code_snippet": "#pragma GCC target(\"avx2\")\n#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\nint N;\nint A[100100], I2[100100], I2_[100100];\nint R1[100100], R2[100100];\nint bs = 27;\nint mod2 = 998244853;\nint pw(int a, int p, int mod){\n ...
aoj_0471_cpp
Whispering Game PCK is planning a message game as entertainment for his friend's birthday party. Five party participants line up in a horizontal line and challenge each other in a message game. If the message is correctly conveyed to the person on the right, the challenge is successful and prizes are given to the five ...
[ { "submission_id": "aoj_0471_11026889", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define rng(i,l,r) for(int i=(l);i<(r);i++)\n#define rrep(i,n) for(int i=(n)-1;i>=0;i--)\n#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)\n#define int long long\...
aoj_0474_cpp
Moving Mass Game Students at Idua High School are practicing the moving mass game in preparation for next year's sports festival. In this mass game, the students move and turn their bodies in accordance with the teacher's commands. In the moving mass game, the teacher gives instructions to the students in the compartme...
[ { "submission_id": "aoj_0474_11027147", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define rng(i,l,r) for(int i=(l);i<(r);i++)\n#define rrep(i,n) for(int i=(n)-1;i>=0;i--)\n#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)\n#define int long long\...
aoj_0475_cpp
School Road In the town of Aizu, where PCK lives, there are $N$ points and $M$ roads connecting each point. Each point is numbered from $1$ to $N$, and all roads can be traveled in both directions. You can also reach other points from any point by taking some of the paths. PCK's house is at point 1 and his school is at...
[ { "submission_id": "aoj_0475_11027034", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define rng(i,l,r) for(int i=(l);i<(r);i++)\n#define rrep(i,n) for(int i=(n)-1;i>=0;i--)\n#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)\n//#define int long lon...
aoj_0476_cpp
Monster Koshien You are trying to get your monsters to participate in the upcoming Monster Koshien. In the Monster Koshien, there will be several opposing monsters, and you will play against them one-on-one in turn. Whether you win or not, you can move on to the next match. In a match, the three values of speed, streng...
[ { "submission_id": "aoj_0476_11027056", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define rng(i,l,r) for(int i=(l);i<(r);i++)\n#define rrep(i,n) for(int i=(n)-1;i>=0;i--)\n#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)\n#define int long long\...
aoj_0478_cpp
Tree Keyboard Dr. PCK has developed a revolutionary input device for computers, the Tree Keyboard. This keyboard has $N$ keys, each numbered $1$ to $N$, and they are wired with $N-1$ wires. You can also reach other keys by following some wires from any key. As a keyboard setting, each key can be assigned a single chara...
[ { "submission_id": "aoj_0478_11031388", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntemplate<typename S, S(*op)(S, S), S(*e)()>\nstruct segtree {\n\tint siz;\n\tvector<S> node;\n\t\n\tsegtree() = default;\n\tsegtree(int n){\n\t\tsiz = 1;\n\t\twhile(siz < n) siz *= 2;\n\t\tnode.assign(...
aoj_0488_cpp
テレポート移動網 人類は研究の末、ついにテレポート装置を利用した移動網を構築できるようになった。テレポート装置が設置できるのは$1$から$N$までの番号が付いた地点だけで、全部で$M$台のテレポート装置が設置されている。$i$番目のテレポート装置は地点$a_i$に設置されており、移動先$b_i$と使用コスト$f_i$が設定されている。地点$a_i$にいる利用者は使用コスト$f_i$を支払うと地点$b_i$に移動できる。 テレポート装置の利用者は事前に申請をすれば、装置を他の地点に移設できる。装置1台を1つ離れた番号の地点に移設するごとに申請が1回必要で、1回当たり申請コスト$C$がかかる。申請には以下のルールがある。 1回の申請では...
[ { "submission_id": "aoj_0488_10875092", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconstexpr int BIG_INT = 1'000'000'100;\nconstexpr long BIG_LONG = 1'000'000'000'000'000'100;\n\ntemplate <typename T>\nusing rev_pq = priority_queue<T, vector<T>, greater<T>>;\n\nint main() {\n ios:...
aoj_0485_cpp
税の徴収 イヅア村には$1$から$N$までの番号が付いた$N$軒の家がある。この村では、$M$人の徴税官が税を徴収する。徴税官は家を訪れて税金を徴収する。1軒の家で徴収する金額は、徴税官ごとに決まっている。 はじめに、徴税官はそれぞれ異なる家に派遣され、そこで税金を徴収する。 次に、徴税官がいる家のうち番号が一番小さい家にいる徴税官が、それよりも大きい番号の家のうち、まだ徴税が済んでいない最も番号が小さい家に移動し、そこで税金を徴収する。これを繰り返し、どの徴税官も税金を徴収できなくなったら徴収を終える。 家の軒数と徴税官の人数、各徴税官が徴収する金額と最初に派遣される家の番号が与えられたとき、イヅア村から徴収できる税金の総額を求め...
[ { "submission_id": "aoj_0485_10875659", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\nusing ul=unsigned long long;\nint dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};\nint dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};\nusing Graph=vector<vector<int>>;\nll op(ll a,ll b){return max(a,b);}\...
aoj_0486_cpp
一方通行迷路ゲーム あなたは一方通行迷路ゲームというコンピュータゲームで遊んでいる。このゲームでは、H行W列のマスで区切られた長方形が画面上に表示される。各マスは壁、道、スタート、ゴールのいずれかで、スタートとゴールはそれぞれ一つだけである。道のマスとスタートのマスでは、上下左右に隣接する道のマスかゴールのマスだけに進むことができる。ただし、道のマスのうちいくつかは一方通行のマスであり、上下左右のうち一つの方向にしか出られない。 1回のゲームでは、スタートから出発して道を通ってゴールを目指す。ゴールにたどりつければゲームクリア、たどりつけないことがわかった時点でゲームオーバーである。スタートからゴールまでの移動回数が少ないほど、ラン...
[ { "submission_id": "aoj_0486_10875761", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\nusing ul=unsigned long long;\nint dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};\nint dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};\nusing Graph=vector<vector<int>>;\nll op(ll a,ll b){return max(a,b);}\...
aoj_0487_cpp
パスワードをお忘れですか? 二郎君は数式を用いたセキュリティシステムを開発した。システムにはa、b、c、dを変数とする数式が設定されており、それぞれに0から9までの整数を入力すると計算が行われる。その計算結果が正の整数$N$と一致したとき、ロックが解除される。ロックを解除できる4つの整数をa,b,c,dの順に並べた4桁の数字の列がパスワードになる。 二郎君はこのシステムで彼が使っているパスワードを忘れてしまった。幸い、二郎君はシステムに設定されている数式と、$N$の値は覚えていたので、それを使ってパスワードを特定しようと考えた。 システムに設定されている数式と正の整数Nが与えられたとき、パスワードの候補の数を求めるプログラムを作成せ...
[ { "submission_id": "aoj_0487_10876904", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nsigned main(){\n string s,t=\"+-*()\"; int m; cin >> s >> m; int n = s.size();\n sort(t.begin(),t.end());\n vector<string> S; stack<char> O;\n auto popop = [&](string u){\n ...
aoj_0489_cpp
農地開発 イヅア国では国内にある広大な土地を利用して、複数の農園を開拓することになった。 イヅア国ではすでに$N$箇所の農園が開拓されており、農園には$1$から$N$までの番号がついている。農園の間にはそれらを直接つなぐ道が、全部で$N-1$本ある。どの道も同じ長さで、どちらの方向にも通ることができる。また、どの農園からでも、いくつかの道を通っていくことで他のどの農園にも到達できる。また、それぞれの農園では、その農園の収支を記録している。 あなたは新しい任務としてイヅア国の農園の拡張と管理を任される予定である。上司から、以下の2種類の作業をいくつか組み合わせた指示を受け取ることになった。 作業1:農園を新たに開拓し、すでにある農園と...
[ { "submission_id": "aoj_0489_10871725", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)\n#define ll long long\nconst long long mod=998244353;\nconst long long hmod=46216567629137;\nstruct S{\n int pos;\n int d;\n};\nS e(){\n S res=...
aoj_0503_cpp
大きさが異なる n 個のコップと 3 つのトレイ(お盆)A,B,C があり,それらのコップは 3 つのトレイの上にそれぞれ何個かずつ一山に重ねて置かれている.ただし,どのトレイにおいても,そのトレイの中で一番小さいコップが一番下に, 2 番目に小さいコップがその上に, 3 番目に小さいコップがその上にと,小さい順に伏せて重ねてある.例えば,下図の右側は, n = 5 個のコップがトレイ A,B,C にそれぞれ 2 個,0 個,3 個重ねて置かれている状態を示している. このように,コップの初期状態が与えられたとき,次の規則 1 〜 3 を守りながら,すべてのコップを A または C のどちらかのトレイに移動させるには何回移動を行えば...
[ { "submission_id": "aoj_0503_11055447", "code_snippet": "//\n// main.cpp\n// kyopro\n//\n// Created by nandk on 2025/07/26.\n//\n#include <algorithm>\n#include <cmath>\n#include <iostream>\n#include <limits>\n#include <map>\n#include <queue>\n#include <set>\n#include <string>\n#include <vector>\nusing na...
aoj_0501_cpp
与えられた変換表にもとづき,データを変換するプログラムを作成しなさい. データに使われている文字は英字か数字で,英字は大文字と小文字を区別する.変換表に現れる文字の順序に規則性はない. 変換表は空白をはさんで前と後ろの 2 つの文字がある(文字列ではない).変換方法は,変換表のある行の前の文字がデータに現れたら,そのたびにその文字を後ろの文字に変換し出力する.変換は 1 度だけで,変換した文字がまた変換対象の文字になっても変換しない.変換表に現れない文字は変換せず,そのまま出力する. 入力ファイルには,変換表(最初の n + 1 行)に続き変換するデータ(n + 2 行目以降)が書いてある. 1 行目に変換表の行数 n,続く n 行...
[ { "submission_id": "aoj_0501_9590453", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n int n;\n while (cin >> n) {\n if (n == 0) break;\n map<char, char> mp;\n for (int i = 0; i < n; i++) {\n char a, b;\n cin >> a >> b;\n ...
aoj_0504_cpp
次のようなゲームを考える. 1 から n までの数が 1 つずつ書かれた n 枚のカードが k 組ある.これら kn 枚のカードをよくシャッフル(よく切ること)して, k 枚ずつの山を作り横一列に並べる.このようにしてできる n 個の山の左から i 番目の(k 枚のカードの)山を「山 i 」と呼ぶことにする. ゲームは山 1 から始める.山の一番上のカード 1 枚を引き(引いたカードは元の山に戻さない),そのカードに書かれていた数が i だった場合には山 i の一番上のカード 1 枚を引く.このようにして,引いたカードに書かれていた数を番号とする山の一番上のカード 1 枚を引くことを繰り返し,すべての山にカードが無くなれば成功である...
[ { "submission_id": "aoj_0504_7974112", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n\nmt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());\nll myRand(ll B) {\n return (u...
aoj_0506_cpp
0 から 9 までの数字だけで構成された文字列が与えられたとき,その文字列から次の規則に従って新しい文字列を作る操作を考える.与えられた文字列を左端から1文字ずつ順に読んで行き,同じ数字 a が r 個続いていた場合,個数 r と数字 a を空白で区切らずにこの順で書き出す.与えられた文字列の右端まで読み,最後の書き出しが終わったところまでを途中何回書き出しがあったとしても全部まとめて操作1回とカウントする.2回目以降の操作は前回の操作により書き出された文字列を与えられた文字列として同様の操作を実施する.例えば “ 122244 ” という文字列が与えられた場合には左端から順に1個の1, 3個の2,2個の4なのでこの操作1回で得られ...
[ { "submission_id": "aoj_0506_4874185", "code_snippet": "#include <iostream>\n#include<string>\nusing namespace std;\n\nint main() {\n int n ;\n string str;\n\n while (true) {\n cin >> n;\n\n if (n == 0) {\n break;\n }\n str = \"\";\n cin >> str;\n\n ...
aoj_0505_cpp
ある学校で修学旅行へ行く計画がある.そのためにアンケート調査を行った. 生徒は 1 から n までの生徒番号を持ち,旅行候補の場所を 1 から m までの番号で表し,行きたい場所に ○,行きたくない場所に×の印をつけて提出している. このとき, 行きたい場所の人数が多い順に,場所の番号を出力するプログラムを作成せよ.人数が同じときは,場所の番号順とする. 入力データ の 1 行目は生徒の人数 n と旅行候補の場所の数 m が空白で区切られ, i + 1 行に生徒 i のアンケート結果を ○ は 1 で×は 0 で表し,空白で区切られた m 個の数字が並んでいる.1 ≤ n ≤ 1000, 1 ≤ m ≤ 100 とする. 入力例1 ...
[ { "submission_id": "aoj_0505_8133272", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing vll = vector<ll>;\nusing vvll = vector<vll>;\n#define all(A) A.begin(),A.end()\n#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)\n\nint main() {\n \n ll N,M;\n whi...
aoj_0514_cpp
品質検査 問題 あなたはある機械の製造工場で品質管理の責任者をしている. この機械には, 部品として電源とモーターとケーブルが必要である. 製造工場には電源が a 個, モーターが b 個, ケーブルが c 個あり, それぞれ 1 から a まで, a+1 から a+b まで, a+b+1 から a+b+c までの番号が付いている. 困ったことに, 部品の中に故障しているものがあるかもしれない. 工場ではどの部品が故障していてどの部品が正常であるかを知りたい. そこで, 工場では次の方法で部品を検査した. 電源とモーターとケーブルを1つずつ持ってきてつなぎ, 動作させてみる. このとき, 3つの部品がすべて正常であるときは正しく動作...
[ { "submission_id": "aoj_0514_3038716", "code_snippet": "#include <bits/stdc++.h>\n#define FOR(I,X,Y) for(long int I=X;I<Y;I++)\n#define REP(I,X) for(long int I=X;I>=0;I--)\n#define INF 1e9+7\nusing namespace std;\n\nint main(){\n int a,b,c;\n vector<int> ans;\n while(1){\n cin >> a >> b >> c;\n if(...
aoj_0508_cpp
両端にリングのついた紐を考える.リングは正整数が付いていて,紐を区別する.紐の両端のリングには異なる数 a , b が付けられる.これを,[ a , b ] と記述する.複数の紐があり,一方の紐と他方の紐のリングに付いている数が同じ場合,そのリングのところで,これらの紐をつなげることができて,つなげてできたものを鎖と呼ぶことにする.例えば,[1, 3] と [3, 4] という紐からは [1, 3, 4] という鎖ができる.紐と鎖や鎖同志も同じ整数が付いているリングのところでつなげることができるものとする. 例えば,鎖 [1, 3, 4] と紐 [5, 1] からは [5, 1, 3, 4] ができ,鎖 [1, 3, 4] と鎖 [...
[ { "submission_id": "aoj_0508_10540827", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\nstatic constexpr int MAXV = 100;\nvector<int> adj[MAXV+1];\nbool used[MAXV+1];\nint bestLen;\n\n// 深さ優先探索で「単純パス」の最大辺数を更新\nvoid dfs(int u, int depth) {\n bestLen...
aoj_0509_cpp
平面に長方形のシートが何枚か置かれている. これらのシートで覆われている部分の面積や周長を求めるプログラムを作成せよ. ただし, 平面を座標平面とみなしたとき, シートの配置は次の条件 (1), (2) を満たすものとする. (1) 各シートの長方形の 4 頂点の x , y 座標は全て 0 以上 10000 以下の整数であり, 長方形の各辺は x 軸, または y 軸に平行である. (2) シートの枚数は高々 10000 枚以下である. 入力データ の 1 行目に長方形の個数 n と問題の種類を表す整数 r が空白で区切って書かれている. 2 行目以降の各行には, 各シートの左下頂点座標 ( x 1 , y 1 ) と右上頂点座標...
[ { "submission_id": "aoj_0509_10851147", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing P = pair<int, int>;\n\nconstexpr int MAX_Y = 10003;\nconstexpr int MAX_X = 10003;\n\nint main() {\n int n, r;\n while(cin >> n >> r, n) {\n vector<vector<P>> v(MAX_Y);\n for(i...
aoj_0520_cpp
最軽量のモビール 問題 モビールは動く芸術品として広く親しまれている.IOI 日本委員会では,JOI を広報するためにモビールを作成することになった.JOI 広報用モビールは,棒,紐(ひも),錘(おもり)の 3 種類の要素を用いて,次のように構成される. 棒の一方の端は青に,もう一方の端は赤に塗られている. 棒は両端以外の 1 箇所を支点として紐でつるされる. 支点から赤の端までの長さも支点から青の端までの長さも正整数である. 棒の両端には,紐で錘か他の棒をつるす. 錘は紐を用いてどれかの棒の一端につるされる. 錘には何もつるさない. 錘の重さは正整数である. 紐のうち 1 本だけは,片方の端をある棒をつるすためにその棒の支点に結ば...
[ { "submission_id": "aoj_0520_1758993", "code_snippet": "#include <bits/stdc++.h>\n \nusing namespace std;\n \n#define MAX_N 100\n \nvector<int> p, q, r, b;\n\nbool dfs(int v, int val)\n{\n int l = p[v] + q[v];\n if (val % l != 0) {\n return 0;\n }\n bool can = 1;\n if (r[v] >= 0) {\n ...
aoj_0507_cpp
同じ大きさの正方形の紙が n 枚ある.これらの紙の下部を水平に揃えて何列かに並べる.ただし,隣り合う列は左側が右側より低くならないように並べなければならない.例えば, n = 5 のときは,次のような 7 通りの並べ方が可能である. これらを,各列に並んだ正方形の個数の列で表すことにする.例えば, n = 5 の ときは,それぞれ, (5) (4, 1) (3, 2) (3, 1, 1) (2, 2, 1) (2, 1, 1, 1) (1, 1, 1, 1, 1) と表わされる. n を入力したとき, 辞書式順序で全て出力するプログラムを作成せよ. n ≤30 とする.ただし, 辞書式順序とは2つの並べ方 ( a 1 , a 2 ,...
[ { "submission_id": "aoj_0507_6744529", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nusing VI = vector<int>;\nusing VVI = vector<VI>;\n\nvoid solve(int n, VI ret, VVI& v) {\n if (n == 0) {\n v.push_back(ret);\n } else {\n for (int i = n; i >= 1; --i) {\n ...
aoj_0515_cpp
通学経路 問題 太郎君の住んでいるJOI市は,南北方向にまっすぐに伸びる a 本の道路と,東西方向にまっすぐに伸びる b 本の道路により,碁盤の目の形に区分けされている. 南北方向の a 本の道路には,西から順に 1, 2, ... , a の番号が付けられている.また,東西方向の b 本の道路には,南から順に 1, 2, ... , b の番号が付けられている.西から i 番目の南北方向の道路と,南から j 番目の東西方向の道路が交わる交差点を (i, j) で表す. 太郎君は,交差点 (1, 1) の近くに住んでおり,交差点 (a, b) の近くのJOI高校に自転車で通っている.自転車は道路に沿ってのみ移動することができる.太郎...
[ { "submission_id": "aoj_0515_10331962", "code_snippet": "#include <iostream>\n#include <set>\n#include <vector>\n#include <stack>\n#include <queue>\n#include <unordered_map>\n#include <algorithm>\n#include <numeric>\nusing namespace std;\n#define rep(i, n) for (int i = 0; i < (int)(n); ++i)\n\nint a,b,n,cnt...
aoj_0516_cpp
最大の和 問題 n 個の整数からなる数列 a 1 , a 2 , ..., a n と正整数 k (1 ≤ k ≤ n ) が与えられる.このとき, 連続して並ぶ k 個の整数の和 S i = a i + a i+1 + ... + a i + k -1 (1 ≤ i ≤ n - k + 1) の最大値を出力するプログラムを作りなさい. 入力 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる.入力は2つのゼロを含む行で終了する. 1 行目には正整数 n (1 ≤ n ≤ 100000) と正整数 k (1 ≤ k ≤ n ) がこの順に空白で 区切られて書かれている.2 行目以降の第 1 + i 行目 (1...
[ { "submission_id": "aoj_0516_11001633", "code_snippet": "#include <iostream>\n#include <math.h>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nusing ll = long long;\nint main(){\n while(true){\n int N,K;\n cin >> N >> K;\n if(N == 0 and K == 0) break;\n vector<int> v(N,0);\n ...
aoj_0517_cpp
最長の階段 問題 1 から n までの整数がそれぞれ 1 つずつ書かれた n 枚のカードと,1 枚の白紙の カードがある.これら n + 1 枚のカードの内, k 枚のカードが与えられる.ただし, 1 ≤ k ≤ n である.白紙のカードには 1 から n までの整数を 1 つ書くことができ る.与えられたカードだけで,できるだけ長い連続した整数列を作りたい. 与えられるカードが入力されたときに, 与えられたカードから作ることができる連 続した整数列の最大長を出力するプログラムを作成せよ. 例1 n = 7, k = 5 とする.6, 2, 4, 7, 1 のカードが与えられたとき,このカードを使っ て作れる連続した整数列のうち最長...
[ { "submission_id": "aoj_0517_11046220", "code_snippet": "#include <iostream>\n#include <math.h>\n#include <vector>\n#include <algorithm>\n#include <set>\nusing namespace std;\nusing ll = long long;\nint main(){\n while(true){\n int N,K;\n cin >> N >> K;\n if(N == 0 and K == 0) break;...
aoj_0518_cpp
最古の遺跡 問題 昔, そこには集落があり, 多くの人が暮らしていた. 人々は形も大きさも様々な建物を建てた. だが, それらの建造物は既に失われ, 文献と, 遺跡から見つかった柱だけが建造物の位置を知る手がかりだった. 文献には神殿の記述がある. 神殿は上から見ると正確に正方形になっており, その四隅には柱があった. 神殿がどの向きを向いていたかはわからない. また, 辺上や内部に柱があったかどうかもわからない. 考古学者たちは, 遺跡から見つかった柱の中で, 正方形になっているもののうち, 面積が最大のものが神殿に違いないと考えた. 柱の位置の座標が与えられるので, 4 本の柱でできる正方形のうち面積が最大のものを探し, その面...
[ { "submission_id": "aoj_0518_11046473", "code_snippet": "#include <iostream>\n#include <math.h>\n#include <vector>\n#include <algorithm>\n#include <set>\nusing namespace std;\nusing ll = long long;\nint main(){\n while(true){\n int N;\n cin >> N;\n if(N == 0) break;\n vector<i...
aoj_0526_cpp
船旅 問題 JOI国には,n 島の島があり,各島には 1 から n までの番号が付けられている.現在,JOI国では各島の間を結ぶ航路網の整備が進んでいる. あなたは,船舶の切符を扱っているチケットセンターに勤務している.JOI国には船舶を使って,できる限り安価に,島と島の間を旅行したいと考えている人が沢山おり,彼らは,出発地と目的地を注文票に記入して,あなたのところに送ってくる. あなたの仕事は,客から注文票を受け取ったらすぐに,いくつかの船舶を乗り継いで,出発地と目的地を結ぶ航路の中で,もっとも安価な運賃を計算し,客に伝えることである. ただし,旅程によっては,船舶を使って旅行することが出来ない場合もある.そのときは『船舶を使って...
[ { "submission_id": "aoj_0526_10851566", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconstexpr int INF = 1e9;\n\nint main() {\n int n, k;\n while(cin >> n >> k, n) {\n vector<vector<int>> d(n, vector<int>(n, INF));\n for(int i=0; i<n; ++i) {\n d[i][i] = 0...
aoj_0519_cpp
最悪の記者 問題 あなたは JOI 新聞社の記者であり,スポーツ記事を担当している. 昨日までに,クロアチアでは,n 個のサッカーチームによる総当りのリーグ戦が行われた.大会実行委員会は,試合結果と規定に基づき各チームに 1 位から n 位までの順位をつけたようである.あなたには,一部の試合の勝敗とともに,次の情報が伝えられた. 情報 1 引き分けの試合はなかった. 情報 2 全てのチームに異なる順位がついた. 情報 3 全ての 1 ≤ a < b ≤ n に対し,a 位のチームと b 位のチームの試合において,必ず a 位のチームが勝利した. あなたは記事を作成するために,一部の試合の勝敗と,伝えられた情報 1 3 をもとに,順位...
[ { "submission_id": "aoj_0519_10850480", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nvoid visit(vector<vector<int>> const& g, int v, vector<bool>& used, vector<int>& res) {\n if(!used[v]) {\n used[v] = true;\n for(auto& to : g[v]) {\n visit(g, to, used, res)...
aoj_0524_cpp
星座探し 問題 あなたは星空の写真の中から星座を探している.写真には必ず,探したい星座と同じ形・向き・大きさの図形がちょうど一つ含まれている.ただし,写真の中には星座を構成する星以外に余分な星が写っている可能性がある. 例えば,図 1 の星座は図 2 の写真に含まれている(丸で囲んで示した).与えられた星座の星の座標を x 方向に 2, y 方向に −3 だけ平行移動すると写真の中の位置になる. 探したい星座の形と写真に写っている星の位置が与えられたとき,星座の座標を写真の中の座標に変換するために平行移動するべき量を答えるプログラムを書け. 図 1: 探したい星座 図 2: 星空の写真 入力 入力は複数のデータセットからなる.各デー...
[ { "submission_id": "aoj_0524_6791636", "code_snippet": "#pragma GCC target(\"avx2\")\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\n#include <bits/stdc++.h>\n// #include <atcoder/modint>\n// #include <atcoder/fenwicktree>\n// #include <atcoder/segtree>\n// #include <atcoder/scc>\n\n#...
aoj_0527_cpp
碁石ならべ 問題 白と黒の碁石をテーブルの上にならべて遊ぶ.まずテーブルの左端に碁石を置く.次に左から 2 番目の場所に碁石を置く.これを n 回繰り返して n 個の碁石を横一列にならべる.ただし,新しく i 番目の碁石を置く際には,次のルールに従ってテーブル上の碁石を置き換える. i が奇数の場合: テーブルに置いてあった碁石は置き換えず,新しい碁石を左 から i 番目に置く. i が偶数の場合: 新しく左から i 番目に置く碁石の色とテーブル上の右端の碁 石の色が同じ場合は,テーブル上の碁石は置き換えず,新しい碁石を左から i 番目に置く.そうでない場合,すなわち,新しく左から i 番目に置く碁石の色 ...
[ { "submission_id": "aoj_0527_10371238", "code_snippet": "#include<stdio.h>\n\nint main(){\n\nint n[100001];\nint N;\nwhile(1){\nscanf(\"%d\",&N);\nif(N==0)break;\nfor(int i=0;i<N;i++)\nscanf(\"%d\",&n[i]);\n\nfor(int i=0;i<N;i++)\nif(i%2==1){\nfor(int j=i-1;j>=0;j--)\nif(n[j]!=n[i])n[j]=n[i];\nelse if(n[j]=...
aoj_0528_cpp
共通部分文字列 問題 2 個の文字列が与えられたとき, 両方の文字列に含まれる文字列のうち最も長いものを探し, その長さを答えるプログラムを作成せよ. ここで, 文字列 s が文字列 t に含まれるとは, t の中に s が連続して現れることをいう. 空文字列, すなわち長さ 0 の文字列は, どんな文字列にも含まれる. 例えば, 文字列 ABRACADABRA には次の文字列が含まれる: ABRA, RAC, D, ACADABRA, ABRACADABRA,空文字列など. 一方, 文字列 ABRACADABRA には次の文字列は含まれない: ABRC, RAA,BA, K など. 例 例 1: 文字列として ABRACADABR...
[ { "submission_id": "aoj_0528_10848158", "code_snippet": "#include<iostream>\n#include<vector>\n#include<algorithm>\n#include<string>\nusing namespace std;\nstring S, T, U;\nint solve(string U1, string U2) {\n\tint t = 0, maxn = 0;\n\tfor (int i = 0; i < min(U1.size(), U2.size()); i++) {\n\t\tif (U1[i] == U2...
aoj_0529_cpp
ダーツ 問題 あなたは以下のルールでダーツゲームをすることになった. あなたは,矢を的(まと)に向かって 4 本まで投げることができる.必ずしも 4 本全てを投げる必要はなく,1 本も投げなくてもかまわない.的は N 個の部分に区切られていて,各々の部分に点数 P 1 ,..., P N が書か れている.矢が刺さった場所の点数の合計 S があなたの得点の基礎となる.S があらかじめ決められたある点数 M 以下の場合は S がそのままあなたの得点となる.しかし,S が M を超えた場合はあなたの得点は 0 点となる. 的に書かれている点数と M の値が与えられたとき,あなたが得ることのできる点数の最大値を求めるプログラムを作成せ...
[ { "submission_id": "aoj_0529_11008304", "code_snippet": "#define _GLGBCXX_DEBUG\n#include <bits/stdc++.h>\nusing namespace std;\n\nint main()\n{\n while (true) {\n int N, M, answer = 0;\n cin >> N >> M;\n\n if (N == 0 && M == 0)\n break;\n \n vector<int> P(N + 1)...
aoj_0530_cpp
ぴょんぴょん川渡り 問題 ある川で,一方の岸から石の上を次々と飛び移って反対側の岸まで行くという少々危険なゲームがはやっている. 今,図 4-1 のように,石はマス目の上に存在すると考える.行の数は n である. 図 4-1 では n = 5 である. このゲームでは,一方の岸から始めて,通常のジャンプまたは m 回以下の一行飛ばしのジャンプをして反対側の岸まで渡る.通常のジャンプとは,今いる行の一つ先の行の岸または石のどれかに飛び移ることであり,一行飛ばしのジャンプとは,今いる行の二つ先の行の岸または石のどれかに飛び移ることである.始める岸の一つ先の行は 1 行目,二つ先の行は 2 行目であり,n − 1 行目の二つ先の行,及び ...
[ { "submission_id": "aoj_0530_10852905", "code_snippet": "#include<iostream>\n#include<vector>\n#include<algorithm>\n#include<queue>\n#include<tuple>\n#include<functional>\nusing namespace std;\nint n, m, a, b, c, dist[4000][100]; vector<tuple<int, int, int>>p; vector<tuple<int, int, int>>K[4000][100];\nint ...
aoj_0525_cpp
おせんべい 問題 IOI製菓では,創業以来の伝統の製法で煎餅(せんべい)を焼いている.この伝統の製法は,炭火で一定時間表側を焼き,表側が焼けると裏返して,炭火で一定時間裏側を焼くというものである.この伝統を守りつつ,煎餅を機械で焼いている.この機械は縦 R (1 ≤ R ≤ 10) 行, 横 C (1 ≤ C ≤ 10000) 列の長方形状に煎餅を並べて焼く.通常は自動運転で,表側が焼けたら一斉に煎餅を裏返し裏側を焼く. ある日,煎餅を焼いていると,煎餅を裏返す直前に地震が起こり何枚かの煎餅が裏返ってしまった.幸いなことに炭火の状態は適切なままであったが,これ以上表側を焼くと創業以来の伝統で定められている焼き時間を超えてしまい,煎餅...
[ { "submission_id": "aoj_0525_11014462", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <cstring>\nusing namespace std;\nint ans;\nint ones[10001]={0};//全局变量一定要及时清理!!!,不然下次循环又累加了\nint m,n;\nint a[11][10001];\nvoid solve(){\n memset(ones,0,sizeof(ones));//不只是赋值,更是清空\n ans=0;\n f...
aoj_0534_cpp
連鎖 問題 次のようなゲームがある. あるキャラクターが縦 1 列に N 個並んでいる.これらのキャラクターの色は赤,青,黄のいずれかであり,初期状態で同じ色のキャラクターが4つ以上連続して並んでいることはない.プレーヤーは,ある位置のキャラクターを選び他の色に変更することができる.この操作により同じ色のキャラクターが4つ以上連続して並ぶとそれらのキャラクターは消滅する.キャラクターが消滅することにより新たに同じ色のキャラクターが4つ以上連続して並ぶとそれらのキャラクターも消滅し,同じ色のキャラクターが4つ以上連続して並んでいる箇所がなくなるまでこの連鎖は続く.このゲームの目的は,消滅しないで残っているキャラクター数をなるべく少なく...
[ { "submission_id": "aoj_0534_10576688", "code_snippet": "// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/0534\n#include <algorithm>\n#include <iostream>\n#include <vector>\n#include <iterator>\n#include <type_traits>\n#include <utility>\n/// @brief ランレングス圧縮\ntemplate <class Contai...
aoj_0535_cpp
薄氷渡り 問題 冬の寒いある日,JOI太郎君は広場にはった薄氷を割って遊ぶことにした.広場は長方形で,東西方向に m 個,南北方向に n 個,つまり, m × n の区画に区切られている.また,薄氷が有る区画と無い区画がある. JOI太郎君は,次のルールにしたがって,薄氷を割りながら区画を移動することにした. 薄氷があるどの区画からも薄氷を割り始めることができる. 東西南北のいずれかの方向に隣接し, まだ割られていない薄氷のある区画に移動できる. 移動した先の区画の薄氷をかならず割る. JOI太郎君が薄氷を割りながら移動できる区画数の最大値を求めるプログラムを作成せよ.ただし, 1 ≤ m ≤ 90,1 ≤ n ≤ 90 である.与...
[ { "submission_id": "aoj_0535_10863977", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nconst int dx[4] = {0, 0, -1, 1};\nconst int dy[4] = {-1, 1, 0, 0};\nint m, n;\nint max_length;\n\nvoid dfs(int y, int x, const vector<vector<int>>& grid, vector<vect...
aoj_0531_cpp
ペンキの色 問題 情報オリンピックの宣伝のために,長方形のベニヤ板にペンキを塗り看板を制作したい.ベニヤ板には色を塗りたくないところにあらかじめ何枚かの長方形のマスキングテープが貼られている.そこでマスキングテープで区切られた領域ごとに別々の色を使いペンキを塗ることにした.例えば,図 5-1 の場合は 5 色のペンキを使う. 入力としてマスキングテープを貼る位置が与えられた時,使うペンキの色の数を求めるプログラムを作成せよ.ただし,ベニヤ板全体がマスキングテープで覆われることはなく,全てのマスキングテープの辺はベニヤ板のいずれかの辺に平行である. 入力 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. 1 ...
[ { "submission_id": "aoj_0531_10539526", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n// 整数ペアを表すエイリアス\nusing pii = pair<int,int>;\n\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n while(true){\n int W, H;\n cin >> W >> H;\n if(!W) break;...
aoj_0536_cpp
Description fetch failed. Please view: https://onlinejudge.u-aizu.ac.jp/problems/0536
[ { "submission_id": "aoj_0536_10319009", "code_snippet": "#include <algorithm>\n#include <array>\n#include <bitset>\n#include <cassert>\n#include <climits>\n#include <cmath>\n#include <functional>\n#include <iomanip>\n#include <iostream>\n#include <map>\n#include <memory>\n#include <numeric>\n#include <optio...
aoj_0537_cpp
ビンゴ 問題 あるプログラミングコンテストでは,競技後の懇親会でビンゴゲームをする習わしがある.しかし,このビンゴゲームで使うビンゴカードは少々特殊で,以下の条件に従って作成される. ビンゴカードは N 行 N 列のマス目に区切られており,各マス目には正整数が1つずつ書かれている.それらの整数は全て異なる. マス目に書かれている整数は 1 以上 M 以下である. ビンゴカードに書かれているN×N個の整数の合計は S である. どの列を見たときも,上から下に向かって整数は昇順に並んでいる. どのマス目の整数も,そのマス目より左の列のどの整数よりも大きい. 以下は, N = 5, M = 50, S = 685 のときのビンゴカードの例...
[ { "submission_id": "aoj_0537_9596124", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\nconst ll mod=100000;\nint main(){\n ll N,M,S;\n while(cin>>N>>M>>S,N+M+S!=0){ vector<vector<ll>> DP(N*N+1,vector<ll>(S+1,0));\n DP[0][0]=1;\n for(int m=1;m<=M;m++){\n ...
aoj_0540_cpp
あみだくじ 問題 あなたは J 君と一緒にあみだくじを使って遊んでいる.あみだくじは n 本の縦棒と m 本の横棒からなる.縦棒には左から順に 1 から n の番号がついており,縦棒 i の下端には正整数 s i が書かれている. 図 3-1 あみだくじの例( n = 4, m = 5, s 1 = 20, s 2 = 80, s 3 = 100, s 4 = 50) 縦棒 i の一番上から順に道をたどっていき到達した下端に書かれている整数が, 縦 棒 i を選んだ場合の得点である.例えば,図 3-1 では,縦棒 1 を選ぶと得点は 80 点 であり,縦棒 2 を選ぶと得点は 100 点である. 図 3-2 道のたどり方の例 J 君...
[ { "submission_id": "aoj_0540_10848631", "code_snippet": "/* ---------- STL Libraries ---------- */\n// IO library\n#include <cstdio>\n\n#include <fstream>\n#include <iomanip>\n#include <ios>\n#include <iostream>\n\n// algorithm library\n#include <algorithm>\n\n#include <cmath>\n#include <numeric>\n#include ...
aoj_0538_cpp
IOIOI 問題 整数 n (1 ≤ n ) に対し, n + 1 個の I と n 個の O を I から始めて交互に並べてできる文字列を P n とする.ここで I と O はそれぞれ英大文字のアイとオーである. P 1 IOI P 2 IOIOI P 3 IOIOIOI . . . P n IOIOIO ... OI ( O が n 個) 図 1-1 本問で考える文字列 P n 整数 n と, I と O のみからなる文字列 s が与えられた時, s の中に P n が何ヶ所含まれているかを出力するプログラムを作成せよ. 例 n が 1, s が OOIOIOIOIIOII の場合, P 1 は IOI であり,下図 1-2 ...
[ { "submission_id": "aoj_0538_10864946", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include<utility>\n#include<set>\n#include<deque>\n#include <unordered_map>\n#include<string>\n#include<cmath>\n\nusing namespace std;\n\n\nint main() {\n\twhile (true) {\n\t\tint m, n;\n\t...
aoj_0545_cpp
パーティー 問題 あなたはクリスマスパーティーに学校内の自分の友達と,自分の友達の友達を招待することにした. あなたの通う学校の生徒数は n 人であり,それぞれの生徒には 1 から n までの番号が割り振られている. あなたの番号は 1 である. あなたの手元には,誰と誰が友達であるかを記したリストがある. このリストをもとに, あなたがクリスマスパーティーに招待する生徒数を求めるプログラムを作成せよ. 入力 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. データセットの1 行目には学校の生徒数 n (2 ≤ n ≤ 500)が, 2 行目にはリストの長さ m (1 ≤ m ≤ 10000)が書かれている...
[ { "submission_id": "aoj_0545_3395409", "code_snippet": "#include <bits/stdc++.h>\n\n// #include <boost/multiprecision/cpp_int.hpp>\n #define int long long\n #define inf 1000000007\n #define pa pair<int,int>\n #define ll long long\n #define pal pair<double,double>\n #define ppap pair<pa,int>\n// #define...
aoj_0542_cpp
認証レベル 問題 あなたは Just Odd Inventions 社を知っているだろうか? この会社の業務は「ただ奇妙な発明 (just odd inventions)」をすることである.ここでは略して JOI 社と呼ぶ. JOI 社には 2 つの事務所があり,それぞれ同じ大きさの正方形の部屋がマス目状に並んでできている.辺で接しているすべての部屋の間に,身分証による認証機能の付いた扉がある.JOI 社では様々なレベルの機密情報を扱っているため,部屋ごとに機密レベルという正の整数が設定されており,身分証の事務所ごとに定められた非負整数の認証レベルが,機密レベル以上でないとその部屋に入室することができない.各事務所の出入り口は唯一あ...
[ { "submission_id": "aoj_0542_10854022", "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_0547_cpp
通勤経路 問題 JOIさんが住むカナダのある都市は,南北方向にまっすぐに伸びる w 本の道路と,東西方向にまっすぐに伸びる h 本の道路により,碁盤の目の形に区分けされている. 南北方向の w 本の道路には,西から順に 1, 2, ... , w の番号が付けられている.また,東西方向の h 本の道路には,南から順に 1, 2, ... , h の番号が付けられている.西から i 番目の南北方向の道路と,南から j 番目の東西方向の道路が交わる交差点を (i, j) で表す. JOIさんは,交差点 (1, 1) の近くに住んでおり,交差点 (w, h) の近くの会社に車で通っている.車は道路に沿ってのみ移動することができる.JOIさ...
[ { "submission_id": "aoj_0547_3813319", "code_snippet": "#include <bits/stdc++.h>\n#define loop(n) for (int ngtkana_is_geneous = 0; ngtkana_is_geneous < n; ngtkana_is_geneous++)\n#define rep(i, begin, end) for(int i = begin; i < end; i++)\n\n#define LOCAL\nusing std::to_string;\nauto to_string(std::string s)...
aoj_0539_cpp
ピザ 問題 JOI ピザでは,市の中心部を通る全長 d メートルの環状線の沿線上でピザの宅配販 売を行っている. JOI ピザは,環状線上に n 個の店舗 S 1 , ... , S n を持つ.本店は S 1 である. S 1 から S i まで,時計回りに環状線を移動したときの道のりを d i メートルとおく. d 2 , ... , d n は 1 以上 d - 1 以下の整数である. d 2 , ... , d n は全て異なる. ピザの注文を受けると, ピザが冷めないように, 宅配先までの移動距離がもっとも短い店舗でピザを焼き宅配する. 宅配先の位置は 0 以上 d - 1 以下の整数 k で表される.これは, 本店 S ...
[ { "submission_id": "aoj_0539_10890669", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include<utility>\n#include<set>\n#include<deque>\n#include <unordered_map>\n#include<string>\n#include<map>\n#include<cmath>\n#include <unordered_set>\n\nusing namespace std;\n\nint main()...
aoj_0546_cpp
カード並べ 問題 花子さんは n 枚(4 ≤ n ≤ 10)のカードを並べて遊んでいる. それぞれのカードには 1 以上 99 以下の整数が 1 つずつ書かれている. 花子さんは,これらのカードの中から k 枚(2 ≤ k ≤ 4)を選び, 横一列に並べて整数を作ることにした. 花子さんは全部で何種類の整数を作ることができるだろうか. 例えば,1, 2, 3, 13, 21 の 5 枚のカードが与えられ,そこから 3 枚を選び整数を作ることを考える. 2, 1, 13 をこの順に並べると,整数 2113 を作ることができる. また,21, 1, 3 をこの順に並べても,同じ整数 2113 を作ることができる. このように,異なるカー...
[ { "submission_id": "aoj_0546_10865043", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include<utility>\n#include<set>\n#include<deque>\n#include <unordered_map>\n#include<string>\n#include<cmath>\n\nusing namespace std;\n\n\nint main() {\n\twhile (true) {\n\t\tint N;\n\t\ts...
aoj_0548_cpp
方向音痴のトナカイ 問題 今年も JOI 町にサンタクロースが空からやってきた.JOI 町にある全ての家には子供がいるので,このサンタクロースは JOI 町の全ての家にプレゼントを配ってまわらなければならない.しかし,今年は連れているトナカイが少々方向音痴であり,また建物の上以外に降りることができないため,全ての家にプレゼントを配るためには少々道順を工夫しなければならないようだ. JOI 町は東西南北に区画整理されており,各区画は家,教会,空き地のいずれかである.JOI 町には 1 つだけ教会がある.次のルールに従い,サンタクロースとトナカイは教会から出発し,全ての家に 1 回ずつプレゼントを配った後,教会に戻る. 今年のトナカイは...
[ { "submission_id": "aoj_0548_9553935", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n\nint main() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n while(1){\n ll N, M;\n cin >> M >> N;\n if(N+M==0)return 0;\n vector<pair<ll, ll>> P;\n ...
aoj_0541_cpp
散歩 問題 JOI 町に住む太郎君は, ある日,健康増進のために散歩を日課にしようと思い立った. 太郎君の住む JOI 町には,図のように,東西方向に走る ( H + 1) 本の道路と,南北 方向に走る ( W + 1) 本の道路が碁盤目状に通っている.太郎君の家はもっとも北西の 交差点にあり,ここから散歩を開始する. 以降,北から a 番目,西から b 番目の交差点を ( a , b ) で表す.たとえば,太郎君の家がある交差点は (1, 1) である. 図: JOI 町の図 ( H = 3, W = 4 の場合).図の上が北,左が西に対応する. 太郎君は,散歩のルートが日々違ったほうが面白いと考えたので,(1, 1) から (...
[ { "submission_id": "aoj_0541_10525122", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n\n while (true) {\n int h, w, n;\n cin >> h >> w >> n;\n if (!h && !w && !n) break; // 終了条件\n\n // ...
aoj_0550_cpp
お菓子の分割 問題 長さ N ミリメートルの棒状のお菓子が 1 本ある(ここで N は偶数). 2 人の JOI 関係者が,このお菓子を複数本に切断して,合計 N/2 ミリメートルずつに分けること にした. 理由は不明であるが,このお菓子は場所によって切断のしやすさが異なっている. 2 人は,お菓子を左から 1 ミリメートルごとに調べ,各場所で切断に何秒かかるか を割り出した.2 人がお菓子を分けるための切断にかかる秒数の最小値を求めるプ ログラムを作成せよ. 入力 入力の 1 行目には,棒の長さ N(2 ≤ N ≤ 10000 ,ただし N は偶数) が書かれてい る.入力の i + 1 行目 (1 ≤ i ≤ N − 1) には...
[ { "submission_id": "aoj_0550_10854045", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<vector>\nusing namespace std;\nint n, a[100000], dp[5005][2];\nint main() {\n\tcin >> n; for (int i = 0; i < n - 1; i++)cin >> a[i];\n\tfor (int i = 0; i < 5005; i++) { dp[i][0] = 999999999; dp[i][1] =...
aoj_0549_cpp
旅人 問題 あなたは JOI 街道を旅する旅人である.JOI 街道は東西にまっすぐに延びた道路で,JOI 街道上には n 個の宿場町がある.宿場町には西から東の順に 1 から n までの番号が付けられている.JOI 街道上の最も西の宿場町が宿場町 1 であり,最も東の宿場町が宿場町 n である. あなたは,宿場町 1 から出発して m 日間の旅に出ることになった.あなたの旅程は数列 a1 , a2 , . . . , am に従い,次のように決められている.ai は i 日目の移動方法を表す 0 ではない整数である.i 日目にあなたが出発する宿場町を宿場町 k とおくと,i 日目にあなたは宿場町 k から宿場町 k + ai までま...
[ { "submission_id": "aoj_0549_10865330", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include<utility>\n#include<set>\n#include<deque>\n#include <unordered_map>\n#include<string>\n#include<cmath>\n\nusing namespace std;\n\nconst int MOD = 100000;\nint main() {\n\tint m, n;\...
aoj_0552_cpp
博覧会 問題 JOI 市では,とある大規模な博覧会を開催することになった. 今回の博覧会には 2 つのテーマがあり,JOI 市にある N 個の展示施設でそれぞれ, 2 つのテーマのうちどちらか一方に沿った展示を行う予定である. 施設の位置は平面座標 (x, y) で表される.位置 (x, y) にある施設から (x′ , y′) にある施設まで移動するためには, |x − x′| + |y − y′| だけの時間がかかる (整数 a に対して, |a| で a の絶対値を表す).同一テーマ内での統一感を出すため,および一方のテーマのみに関心を持つ人に不便を感じさせないために,同一のテーマで展示を行っている 2 つの施設の間の移動時間...
[ { "submission_id": "aoj_0552_10852741", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<vector>\nusing namespace std;\nint x[100000], y[100000], n, mx, my; bool unused[100000];\nint solve(int lx, int ly, int rx, int ry) {\n\tfor (int i = 0; i < n; i++)unused[i] = false;\n\tfor (int i = 0;...
aoj_0551_cpp
つらら 問題 カナダに住む JOI 君の家の軒下には,立派なつららが出来ている.せっかくなので,JOI 君はつららについて調べてみることにした. JOI 君の家の軒下には N 本(2 ≤ N ≤ 100000 = 10 5 )のつららが出来ている.これらのつららは一直線上に並んでおり,軒下の左端から i cm(1 ≤ i ≤ N )の位置に i 本目のつららが出来ている.i 本目のつららの長さは最初 ai cm(ai は 1 以上の整数)である.これらのつららは,次のような規則によって伸びていく: i 本目のつららは,i − 1 本目のつららと i + 1 本目のつららの両方よりも長い場合にのみ,1 時間につき 1 cm ずつ伸びる...
[ { "submission_id": "aoj_0551_10946339", "code_snippet": "#include<iostream>\n#include<algorithm>\n#include<vector>\n#include<queue>\n#include<functional>\nusing namespace std;\npriority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>>Q;\nlong long dist[200000], a[2000...
aoj_0556_cpp
タイル (Tile) 問題 JOI 高校では, 1 × 1 の正方形のタイルを使って N × N の正方形の壁画を作り,文化祭で展示することになった.タイルの色は,赤,青,黄の 3 種類である.壁画のデザインは次の通りである.まず,最も外側の周に赤のタイルを貼り,その内側の周に青のタイルを貼る.さらにその内側の周に黄色のタイルを貼る.これを N × N の正方形が埋め尽くされるまで繰り返す.用いるタイルの色は,一番外側の周から順番に赤,青,黄,赤,青,黄,…である. 文化祭が近づいてきたある日,壁画のうち K 枚のタイルがはがれていることが判明した.そこで,新しいタイルを購入して,はがれた箇所に新しいタイルを貼ることにした. 入力と...
[ { "submission_id": "aoj_0556_2940233", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n#define rep(i,n) for(int i=0; i<n; i++)\nint main(){\n int n;\n cin >> n;\n int t[n][n]={};\n int a,b,h=0,w=0;\n int cnt=1;\n while(1){\n for(int i=h; i<n-h; i++){\n for(int j=w; j<n-w; j++){...
aoj_0553_cpp
ダンジョン 問題 あなたはあるダンジョンの地下 N 階にある財宝を手に入れたいと思っている.最初,あなたは地下 1 階におり,あなたの体力は H(H は正整数) である.下の階に降りるときに,体力が消費される.あらかじめ各階における下の階に降りるときに消費される体力が分かっている.一方,各階には 1 つの回復の泉があり,泉を 1 回使うごとに回復できる体力がそれぞれ定まっている.体力が 0 以下になるとあなたは死んでしまう.また,体力が H よりも高くなることはない.回復の泉は何回でも使うことができるが,回復には時間がかかるので,あなたは泉の使用回数をできるだけ少なくしたいと考えている. N ,H ,各階の下の階に降りるときに消費さ...
[ { "submission_id": "aoj_0553_10399785", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nlong long N, H, a[100009], b[100009], s[100009], sum, G, sx = 1, cx = 1;\n\nint main() {\n\tcin >> N >> H;\n\tfor (int i = 1; i <= N - 1; i++) cin >> a[i] >> b[i];\n\ts[1] = H; for (int i = 2; i <= N; ...
aoj_0561_cpp
古本屋(Books) あなたの町にはJOI 古本店という老舗の古本屋があり,あなたはJOI 古本店をよく利用している.それぞれの本には基準価格が定まっており,JOI 古本店に行けばその価格で買い取ってもらえる. JOI 古本店では,本を小説,漫画,雑誌など10 種類のジャンルに分類して扱っている.ジャンルには1から10 までの番号が付けられている.JOI 古本店には,同じジャンルの本をまとめて買い取ってもらうと高値で買い取ってくれるというサービスがある.具体的には,同じジャンルの本をまとめてT 冊買い取ってもらう場合,そのジャンルの本の一冊あたりの買取価格が基準価格よりT - 1 円高くなる.例えば,同じジャンルで基準価格100 円...
[ { "submission_id": "aoj_0561_8115415", "code_snippet": "#include <algorithm>\n#include <cstring>\n#include <iostream>\n#include <map>\n#include <set>\n#include <sstream>\n#include <string>\n#include <vector>\n#define REP(i, k, n) for (int i = k; i < n; i++)\n#define rep(i, n) for (int i = 0; i < n; i++)\n#d...
aoj_0562_cpp
JOI 国の買い物事情(Shopping in JOI Kingdom) JOI 国には N 個の町があり,それらの間は M 本の双方向に通行可能な道路で結ばれている. K 個の町にはショッピングモールがあり,国民は道路を通ってそれらの町のいずれかに行き買い物をする. 家の場所によっては,買い物に行くために長い距離を移動する必要があり,それは非常に不便である.国王はこの実情を把握するため,ショッピングモールのある町までの最短距離が家の場所によってどれだけ長くなりうるのかを調べることにした.家は道路の途中に建てられることもあるので(入力例1 の説明を参照),この調査は非常に大変である.そこで国王は,優秀なプログラマーであるあなたに,調...
[ { "submission_id": "aoj_0562_10851481", "code_snippet": "#include<iostream>\n#include<functional>\n#include<algorithm>\n#include<vector>\n#include<queue>\n#include<cmath>\nusing namespace std;\npriority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>Q;\nint n, m, k, a[100000], b[10000...
aoj_0568_cpp
パスタ (Pasta) 問題 あなたはパスタが大好物であり,毎日,晩御飯にパスタを作って食べている.あなたはトマトソース,クリームソース,バジルソースの 3 種類のパスタを作ることができる. N 日間の晩御飯の予定を考えることにした.それぞれの日に 3 種類のパスタから 1 種類を選ぶ.ただし,同じパスタが続くと飽きてしまうので,3 日以上連続して同じパスタを選んではいけない.また,N 日のうちの K 日分のパスタはすでに決めてある. 入力として N の値と,K 日分のパスタの情報が与えられたとき,条件をみたす予定が何通りあるかを 10000 で割った余りを求めるプログラムを作成せよ. 入力 入力は K + 1 行からなる. 1 行...
[ { "submission_id": "aoj_0568_2091162", "code_snippet": "#include <stdio.h>\n#include <algorithm>\n#include <string.h>\n#define DAY_MAX\t123\n#define PASTA_MAX\t5\n#define ONAZI_MAX\t123\n\nint max;\n\n\nint set_pasta[DAY_MAX];\nint memo[DAY_MAX][PASTA_MAX][ONAZI_MAX];\n\nint dp(int day, int pasta, int onazi...
aoj_0560_cpp
惑星探査(Planetary Exploration) あなたを乗せた超時空移民船は長旅の末,ついに居住可能と思われる惑星を発見した.JOI 星と名付けられたその惑星は,その名の通り「ジャングル(Jungle)」,「海(Ocean)」,「氷(Ice)」の3 種類の地形が入り組んだ過酷な惑星である.簡単な調査により,居住予定地近辺の地図が作成された.居住予定地は南北 M km, 東西 N km の長方形の形をしており, 1 km 四方の正方形の区画に分けられている.区画は全部で MN 個あり,北から p 行目,西から q 列目の区画を( p , q ) で表す.北西の角の区画が(1, 1) であり,南東の角の区画が( M , N ) ...
[ { "submission_id": "aoj_0560_10867525", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include<utility>\n#include<set>\n#include<deque>\n#include <unordered_map>\n#include<string>\n#include<cmath>\n\nusing namespace std;\n\nconst int MOD = 100000;\nint main() {\n\tint M, N,K...