group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_2439_cpp
問題名 箱根駅伝 日本のお正月の風物詩に箱根駅伝があります。箱根駅伝は、各チーム 10 人の走者が中継所ごとに襷をつなぎながらゴールを目指すというものです。テレビの放送では中継所で各チームの通過順位と共に前の中継所からの順位変動が表示されます。そこで、それを見て前の中継所の各チームの通過順として考えられるものが何通りあるか答えてください。ありえた通過順の数は非常に大きくなりうるので、1,000,000,007 で割った余りで答えて下さい。 Input 入力は以下の形で与えられます n c 1 c 2 ... c n 1行目にはチーム数を表す数字 n ( 1 ≤ n ≤ 200 ) が、続く n 行には 1 位から順に前の中継所からの...
[ { "submission_id": "aoj_2439_10502398", "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)\n\nusing ll = long long;\nconst ll mod = 1000000007;\n\nll mu...
aoj_2433_cpp
最終防衛線 たびたび未確認生物に侵略されるようになった某国では重要施設を新型防衛兵器で保護することにした。 この兵器は多角形の領域に特殊なガスを充満させることで未確認生物にダメージを与えることができる。未確認生物が侵攻する途中でガスの濃度が変わると、濃度の差の絶対値のダメージを与える。ガスの濃度が同じ領域を動いているときはダメージは一切発生しない。 現在の技術ではガスの濃度は一定にしかできないので、某国は新型防衛兵器を複数投入することにした。全ての兵器でガスの濃度は同じであり、複数の兵器の領域に含まれる部分は濃度が足し合わされる。 未確認生物の出現地点と重要施設の位置を元に、未確認生物が重要施設まで侵攻する時に受けるダメージの最小値...
[ { "submission_id": "aoj_2433_8216564", "code_snippet": "#include <algorithm>\n#include <assert.h>\n#include <bitset>\n#include <climits>\n#include <cmath>\n#include <complex>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <ctime>\n#include <deque>\n#include <iomanip>\n#include <iostrea...
aoj_2445_cpp
MinimumCostPath NxNの方眼がある。 (N=3の場合の図) 隣接するマス目に移動するにはコストが1かかる。ただし、斜めに移動することは出来ない。 また障害物があるマス目がM個あり、そのマスに入ることは許されない。 マス(1, 1)からマス(N, N)に最小のコストで移動する方法は何通りあるか。 答えは大きくなることがありうるので、1000000009(=10 9 +9)でMODを取って出力せよ。 Input 入力は以下の形式で与えられる N M X 1 Y 1 X 2 Y 2 …… X M Y M X i , Y i は(X i , Y i )に障害物があることを表す Constraints 2 ≤ N ≤ 10 6...
[ { "submission_id": "aoj_2445_8337009", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define rep(i, n) for (int i = 0; i < (n); i++)\n#define per(i, n) for (int i = (n)-1; i >= 0; i--)\n#define rep2(i, l, r) for (int i = (l); i < (r); i++)\n#define per2(i, l, r) for (int i = (r)-1; i >=...
aoj_2446_cpp
Enumeration n個の整数a 1 , a 2 , …, a n とn個の整数p 1 , p 2 , …, p n 、整数mが与えられる。k番目の整数a k をp k [%]の確率で選ぶ、という操作を各k(1 ≤ k ≤ n)について行い、0個以上n個以下の整数を選び出す。1以上m以下の整数の中で、選ばれた整数の少なくとも1つで割り切れるものの個数の期待値を求めよ。 Input 入力は以下の形式で与えられる。 n m a 1 a 2 … a n p 1 p 2 … p n Constraints 1 ≤ n ≤ 20 1 ≤ m ≤ 10 18 1 ≤ a k ≤ 10 18 (1 ≤ k ≤ n) 1 ≤ p k ≤ 99 ...
[ { "submission_id": "aoj_2446_9915371", "code_snippet": "#include <iostream>\nusing namespace std;\nusing ll = long long;\n#define rep(i, n) for(int i=0; i<(n); i++)\n\nconst ll MAX = 1LL<<60;\n\nll get_gcd(ll a, ll b){\n if(b == 0) return a;\n return get_gcd(b, a%b);\n}\n\nll get_lcm(ll a, ll b){\n ...
aoj_2444_cpp
Substring 長さnの文字列s=s 1 ,s 2 ,…,s n およびm個のクエリが与えられる。 各クエリq k (1 ≤ k ≤ m)は、"L++", "L--", "R++", "R--"の4種類のいずれかであり、 k番目のクエリq k に対してl[k]とr[k]を以下で定義する。 L++:l[k]=l[k-1]+1,r[k]=r[k-1] L--:l[k]=l[k-1]-1,r[k]=r[k-1] R++:l[k]=l[k-1],r[k]=r[k-1]+1 R--:l[k]=l[k-1],r[k]=r[k-1]-1 但し、l[0]=r[0]=1である。 この時、m個の部分文字列 s l[k] , s l[k]+1 , …...
[ { "submission_id": "aoj_2444_10899223", "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_2442_cpp
Convex-Cut N個の頂点からなる凸多角形が与えられる。各頂点の座標は反時計周りに(X 1 , Y 1 ), (X 2 ,Y 2 ), ……, (X N , Y N )で表わされる。 点Pを通るどのような直線で凸多角形を切断しても、切断後に得られる2つの凸多角形の面積が等しいような点Pの座標を求めよ。 Input 入力は以下の形式で与えられる。 N X 1 Y 1 X 2 Y 2 …… X N Y N Constraints 入力は全て整数である 3 ≤ N ≤ 50 0 ≤ |X i |, |Y i | ≤ 1000000 入力の多角形は単純な凸多角形である。 出力は、出力座標を(X, Y)、厳密解を(cX, cY)とした時...
[ { "submission_id": "aoj_2442_4888668", "code_snippet": "#include <stdio.h>\n#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i,n) for (int i = 0; i < (n); ++i)\n#define Inf 1000000300\n\nconst double eps = 1e-10;\n\ntemplate <typename T>\nstruct vector_2d{\n\tT x,y,rad,dir;\n\t\n\tvector_2d(T a=0...
aoj_2443_cpp
Reverse Sort 1 ∼ NまでのN個の数字の順列A 1 , A 2 , ……, A N が与えられる。 この順列に対して区間[i, j](1 ≤ i ≤ j ≤ N)の数字の順序を逆順にする操作reverse(i, j)を行うことが出来る。 例えば、[1, 2, 3, 4, 5]に対してreverse(2, 4)を適用すると[1, 4, 3, 2, 5]となる。 最小で何回の操作を行えば順列を昇順にソートされた状態にすることが出来るか計算せよ。 Input 入力は以下の形式で与えられる。 N A 1 A 2 …… A N Constraints Nは整数である 2 ≤ N ≤ 10 Output 問題の解を1行に出力せよ。...
[ { "submission_id": "aoj_2443_10851181", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nvoid bfs(vector<int> v, map<vector<int>, int>& m) {\n const int N = v.size();\n queue<vector<int>> que;\n que.push(v);\n m[v] = 0;\n while(!que.empty()) {\n auto now = que.front()...
aoj_2447_cpp
A Two Floors Dungeon It was the last day of the summer camp you strayed into the labyrinth on the way to Komaba Campus, the University of Tokyo. The contest has just begun. Your teammates must impatiently wait for you. So you have to escape from this labyrinth as soon as possible. The labyrinth is represented by a gr...
[ { "submission_id": "aoj_2447_10865803", "code_snippet": "/*\n * main.cpp\n *\n * Created on: 2014年7月8日\n * Author: whd\n */\n\n#include <cstdio>\n#include <cstring>\n#include <iostream>\n\n#define mp make_pair\n#define pb push_back\n\nusing namespace std;\ntypedef long long big;\n\nconst int dx[] = { ...
aoj_2449_cpp
Connect You are playing a solitaire puzzle called "Connect", which uses several letter tiles. There are R × C empty cells. For each i (1 ≤ i ≤ R) , you must put a string s i (1 ≤ |s i | ≤ C) in the i -th row of the table, without changing the letter order. In other words, you choose an integer sequence {a j } such tha...
[ { "submission_id": "aoj_2449_10867639", "code_snippet": "#include<iostream>\n#include<stdio.h>\n#include<algorithm>\n#include<string.h>\nusing namespace std;\nconst int N = 1<<17;\nint opt[2][N][17],bn[N][17],rbn[N][17],r,c,len[150];\nchar s[150][20];\ninline int reset(int state,int i){\n return state-(s...
aoj_2448_cpp
Area Folding You are given one polygonal line, which is a collection of line segments. Your task is to calculate the sum of areas enclosed by the polygonal line. A point is defined to be "enclosed" if and only if the point is unreachable without crossing at least one line segment from the point at infinity. Input The ...
[ { "submission_id": "aoj_2448_9834346", "code_snippet": "#define _CRT_SECURE_NO_WARNINGS\n#include <iostream>\n#include <algorithm>\n#include <cmath>\n#include <cstring>\n#include <cstdio>\n#include <cassert>\n#include <vector>\n#include <queue>\n#include <deque>\n#include <map>\n#include <set>\ntypedef long...
aoj_2450_cpp
Do use segment tree Given a tree with n (1 ≤ n ≤ 200,000) nodes and a list of q (1 ≤ q ≤ 100,000) queries, process the queries in order and output a value for each output query. The given tree is connected and each node on the tree has a weight w i (-10,000 ≤ w i ≤ 10,000) . Each query consists of a number t i (t i = 1...
[ { "submission_id": "aoj_2450_10907288", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntemplate<typename T>\nT bit_ceil(T x){\n T a = 1;\n while(a < x) a <<= 1;\n return a;\n}\ntemplate<typename T>\nint countr_zero(T x){\n if(x == 0) return 32;\n if constexpr(sizeof(T) == ...
aoj_2454_cpp
Repairing In the International City of Pipe Construction, it is planned to repair the water pipe at a certain point in the water pipe network. The network consists of water pipe segments, stop valves and source point. A water pipe is represented by a segment on a 2D-plane and intersected pair of water pipe segments are...
[ { "submission_id": "aoj_2454_10848661", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int N = 222222;\nconst long double eps = 1e-8;\n\nint sign(const long double &x) {\n\treturn x < -eps ? -1 : x > eps;\n}\n\nstruct Point {\n\tlong double x, y;\n\tPoint() {}\n\tPoint(long doubl...
aoj_2456_cpp
Usoperanto Usoperanto is an artificial spoken language designed and regulated by Usoperanto Academy. The academy is now in study to establish Strict Usoperanto, a variation of the language intended for formal documents. In Usoperanto, each word can modify at most one other word, and modifiers are always put before modi...
[ { "submission_id": "aoj_2456_10853947", "code_snippet": "/*\n * main.cpp\n *\n * Created on: 2014年7月8日\n * Author: whd\n */\n\n#include <algorithm>\n#include <cstdio>\n#include <iostream>\n#include <vector>\n#include <cstring>\n\n#define mp make_pair\n#define pb push_back\n\nusing namespace std;\ntype...
aoj_2457_cpp
Problem A: Adhoc Translation One day, during daily web surfing, you encountered a web page which was written in a language you've never seen. The character set of the language was the same as your native language; moreover, the grammar and words seemed almost the same. Excitedly, you started to "decipher" the web page....
[ { "submission_id": "aoj_2457_10853165", "code_snippet": "#include<cstdio>\n#include<algorithm>\n#include<iostream>\n#include<cstring>\n#include<cmath>\n#include<vector>\n#include<queue>\n#include<map>\nusing namespace std;\n#define mod 1000000007\n#define maxn 100005\n#define INF 0x3f3f3f3f\nint a[405][405]...
aoj_2453_cpp
Presentation You are a researcher investigating algorithms on binary trees. Binary tree is a data structure composed of branch nodes and leaf nodes. Every branch nodes have left child and right child, and each child is either a branch node or a leaf node. The root of a binary tree is the branch node which has no pare...
[ { "submission_id": "aoj_2453_10851219", "code_snippet": "#include <bits/stdc++.h>\n\nchar s[1000005];\nint len;\n\nint n;\nint ch[400005][2], fa[400005], sz[400005], spec[400005];\n\nint dp[400005];\n\nvoid build() {\n\tint now = 1, tot = 1;\n\tfor (int i = 2; i <= len - 1; ++i) {\n\t\tif (s[i] == ')') {\n\...
aoj_2455_cpp
Sun and Moon In the year 20XX, mankind is hit by an unprecedented crisis. The power balance between the sun and the moon was broken by the total eclipse of the sun, and the end is looming! To save the world, the secret society called "Sun and Moon" decided to perform the ritual to balance the power of the sun and the...
[ { "submission_id": "aoj_2455_10248058", "code_snippet": "#include <iostream>\n#include <vector>\n#include <map>\n#include <algorithm>\n#include <cstdlib>\n#include <ctime>\n#include <numeric>\nusing namespace std;\n\ntypedef long long ll;\ntypedef unsigned long long ull;\n\nint main(){\n ios::sync_with_s...
aoj_2452_cpp
Pipeline Plans There are twelve types of tiles in Fig. 1. You were asked to fill a table with R × C cells with these tiles. R is the number of rows and C is the number of columns. How many arrangements in the table meet the following constraints? Each cell has one tile. the center of the upper left cell (1,1) and the ...
[ { "submission_id": "aoj_2452_10867800", "code_snippet": "#include <iostream>\n#include <cstring>\n\n#pragma GCC optimize(2)\n\nusing namespace std;\n\nusing i64 = long long;\n\nconst int N = 1000000, M = 9979; \nconst int offset = 3, mask = 7;\n\nint num[8], a[8], bk[8];\nint n, m, c[15];\nint s1, f;\ni64 s...
aoj_2451_cpp
Move On Dice There is a cube on a rectangle map with H -rows and W -columns grid. Two special squares a start and a goal are marked on the map. Initially, the cube is on the start square. Let's repeat to roll it and take it to the goal square. Rolling the cube means to select one of four edges which touch the map, an...
[ { "submission_id": "aoj_2451_3702630", "code_snippet": "#include<bits/stdc++.h>\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define BIG_NUM 2000000000\n#define HUGE_NUM 99999999999999999\n#define MOD 1000000007\n#define EPS 0.000000001\nusing namespace std;\n\n\n\n#define SIZE 15\n#defi...
aoj_2462_cpp
Problem F: Exciting Bicycle You happened to get a special bicycle. You can run with it incredibly fast because it has a turbo engine. You can't wait to try it off road to enjoy the power. You planned to go straight. The ground is very rough with ups and downs, and can be seen as a series of slopes (line segments) when ...
[ { "submission_id": "aoj_2462_9671648", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n\n\nconst double eps = 1e-9;\n\nvoid solve() {\n int n, v;\n cin >> n >> v;\n\n vector<pair<int, int>> p(n);\n double ans = 0;\n for (int i = 0; i < n; i++) {\n cin >> p[i].first >...
aoj_2466_cpp
Problem J: Substring Expression Trees are sometimes represented in the form of strings. Here is one of the most popular ways to represent unlabeled trees: Leaves are represented by " () ". Other nodes (i.e. internal nodes) are represented by " ( S 1 S 2 ... S n ) ", where S i is the string representing the i -th subnod...
[ { "submission_id": "aoj_2466_870511", "code_snippet": "#include<iostream>\n#include<unordered_map>\n\nint main(){\n std::unordered_map<long long,long long> counter;\n std::string line;\n int tmp = 0;\n getline(std::cin,line);\n for(int i=0;i<(int)line.size();i++){\n tmp += ((line[i]=='(')?+1:-1);\n ...
aoj_2465_cpp
Problem I: Sort by Hand It's time to arrange the books on your bookshelf. There are n books in the shelf and each book has a unique number; you want to sort the books according to the numbers. You know that the quick sort and the merge sort are fast sorting methods, but it is too hard for you to simulate them by hand -...
[ { "submission_id": "aoj_2465_947549", "code_snippet": "#include <bits/stdc++.h>\n#define REP(i,n) for(int i=0; i<(int)(n); ++i)\n\nusing namespace std;\n\nint greedy1(vector<int> v) {\n int res = 0;\n for(int i = 0; i < v.size(); i++) {\n int e = i;\n while(v[e] != i) e++;\n if(e ...
aoj_2460_cpp
Problem D: Dial Key You are a secret agent from the Intelligence Center of Peacemaking Committee. You've just sneaked into a secret laboratory of an evil company, Automated Crime Machines. Your mission is to get a confidential document kept in the laboratory. To reach the document, you need to unlock the door to the sa...
[ { "submission_id": "aoj_2460_10858290", "code_snippet": "#include <cstdlib>\n#include <cctype>\n#include <cstring>\n#include <cstdio>\n#include <cmath>\n#include <algorithm>\n#include <vector>\n#include <string>\n#include <iostream>\n#include <sstream>\n#include <map>\n#include <set>\n#include <queue>\n#inc...
aoj_2464_cpp
Problem H: Magic Walls You are a magician and have a large farm to grow magical fruits. One day, you saw a horde of monsters, approaching your farm. They would ruin your magical farm once they reached your farm. Unfortunately, you are not strong enough to fight against those monsters. To protect your farm against them,...
[ { "submission_id": "aoj_2464_8306317", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long LL;\nconst int N = 1505;\n\nstruct Point {\n LL x, y;\n Point(LL _x = 0, LL _y = 0): x(_x), y(_y) {}\n Point operator + (const Point &rhs) const {\n return Point(x + rhs....
aoj_2478_cpp
Problem K: Trading Ship You are on board a trading ship as a crew. The ship is now going to pass through a strait notorious for many pirates often robbing ships. The Maritime Police has attempted to expel those pirates many times, but failed their attempts as the pirates are fairly strong. For this reason, every ship p...
[ { "submission_id": "aoj_2478_10853097", "code_snippet": "#include<iostream>\n#include<cstdlib>\n#include<cstring>\n#include<cstdio>\n#include<cmath>\n#include<ctime>\n#include<algorithm>\n#include<list>\n#include<queue>\n#include<stack>\n#include<vector>\n#include<set>\n#include<map>\n#include<bitset>\n#inc...
aoj_2480_cpp
Problem B: Blame Game Alice and Bob are in a factional dispute. Recently a big serious problem arised in a project both Alice and Bob had been working for. This problem was caused by lots of faults of Alice's and Bob's sides; those faults are closely related. Alice and Bob started to blame each other. First, Alice clai...
[ { "submission_id": "aoj_2480_10852753", "code_snippet": "#include <cstdlib>\n#include <cstdio>\n#include <cstring>\n#include <algorithm>\n#include <iostream>\n#include <map>\n#include <stack>\n#define ll long long\nusing namespace std;\n\n\nconst int maxm = 550 * 550;\nconst int maxn = 1100;\nstruct EE\n{\n...
aoj_2482_cpp
Problem D: Exportation in Space In an era of space travelling, Mr. Jonathan A. Goldmine exports a special material named "Interstellar Condensed Powered Copper". A piece of it consists of several spheres floating in the air. There is strange force affecting between the spheres so that their relative positions of them a...
[ { "submission_id": "aoj_2482_3122546", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <cstring>\n#include <complex>\nusing namespace std;\nconst double EPS = 1e-10;\nconst double INF = 1e12;\n#define EQ(n,m) (abs((n)-(m)) < EPS)\...
aoj_2479_cpp
Problem A: Approximate Circle Consider a set of n points ( x 1 , y 1 ), ..., ( x n , y n ) on a Cartesian space. Your task is to write a program for regression to a circle x 2 + y 2 + a x + b y + c = 0. In other words, your program should find a circle that minimizes the error. Here the error is measured by the sum ove...
[ { "submission_id": "aoj_2479_2184088", "code_snippet": "#include <cstdio>\n#pragma warning(disable : 4996)\nint n, x[40009], y[40009]; long double p1, p2, p3, mat[4][4], vec[4];\nlong double solve(long double a, long double b, long double c) {\n\tvec[0] = 1;\n\tvec[1] = a;\n\tvec[2] = b;\n\tvec[3] = c;\n\tl...
aoj_2475_cpp
Problem H: Round Table You are the owner of a restaurant, and you are serving for N customers seating in a round table. You will distribute M menus to them. Each customer receiving a menu will make the order of plates, and then pass the menu to the customer on the right unless he or she has not make the order. The cust...
[ { "submission_id": "aoj_2475_10853026", "code_snippet": "#include<iostream>\n#include<cstdlib>\n#include<cstring>\n#include<cstdio>\n#include<cmath>\n#include<ctime>\n#include<algorithm>\n#include<list>\n#include<queue>\n#include<stack>\n#include<vector>\n#include<set>\n#include<map>\n#include<bitset>\n#inc...
aoj_2483_cpp
Problem E: Laser Puzzle An explorer John is now at a crisis! He is entrapped in a W times H rectangular room with a embrasure of laser beam. The embrasure is shooting a deadly dangerous laser beam so that he cannot cross or touch the laser beam. On the wall of this room, there are statues and a locked door. The door lo...
[ { "submission_id": "aoj_2483_1032961", "code_snippet": "#include<bits/stdc++.h>\n\n#define REP(i,s,n) for(int i=s;i<n;i++)\n#define rep(i,n) REP(i,0,n)\n\nusing namespace std;\n\ntypedef pair<int,int> ii;\n\nint H,W,LP,LP_dir;\nbool polluted_room[9][9];\nbool visited[9][9];\nchar room[9][9];\nint dx8[] = {+...
aoj_2468_cpp
Problem A: Cache Control Mr. Haskins is working on tuning a database system. The database is a simple associative storage that contains key-value pairs. In this database, a key is a distinct identification (ID) number and a value is an object of any type. In order to boost the performance, the database system has a cac...
[ { "submission_id": "aoj_2468_10851217", "code_snippet": "#include<cstdio>\n#include<algorithm>\n#include<queue>\n#include<set>\n#include<stack>\nusing namespace std;\n\nconst int maxn=1e5+100;\nint a[maxn];\nset<int> s;\nint main()\n{\n int n,m,t,temp,i;\n scanf(\"%d%d\",&n,&m);\n\tfor(i=0;i<n;++i)\n\...
aoj_2469_cpp
Problem B: Cover Time Let G be a connected undirected graph where N vertices of G are labeled by numbers from 1 to N . G is simple, i.e. G has no self loops or parallel edges. Let P be a particle walking on vertices of G . At the beginning, P is on the vertex 1. In each step, P moves to one of the adjacent vertices. Wh...
[ { "submission_id": "aoj_2469_10702991", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint n , m , ed;\ndouble dp[10][1 << 10][1705];\nvector < int > E[15];\n\ninline void updata(double & x , double v){\n\tx += v;\n}\n\nint main(int argc , char *argv[]){\n\tscanf(\"%d%d\",&n,&m);ed = 1 ...
aoj_2485_cpp
Problem G: Nezumi's Treasure There were a mouse and a cat living in a field. The mouse stole a dried fish the cat had loved. The theft was found soon later. The mouse started running as chased by the cat for the dried fish. There were a number of rectangular obstacles in the field. The mouse always went straight ahead ...
[ { "submission_id": "aoj_2485_3182792", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <utility>\n#include <map>\n#include <set>\nusing namespace std;\ntypedef pair<int, int> pii;\n#define X first\n#define Y second\n\n//AOJ0333の改造\nstruct segmentTree...
aoj_2472_cpp
Problem E: Mickle's Beam Major Mickle is commanded to protect a secret base which is being attacked by N tanks. Mickle has an ultimate laser rifle called Mickle's beam . Any object shot by this beam will be immediately destroyed, and there is no way for protection. Furthermore, the beam keeps going through even after d...
[ { "submission_id": "aoj_2472_10852892", "code_snippet": "#include<iostream>\n#include<cstdlib>\n#include<cstring>\n#include<cstdio>\n#include<cmath>\n#include<ctime>\n#include<algorithm>\n#include<list>\n#include<queue>\n#include<stack>\n#include<vector>\n#include<set>\n#include<map>\n#include<bitset>\n#inc...
aoj_2492_cpp
goto busters Problem Statement あなたは謎のプログラムのソースコードを見つけた. さっそくコンパイルして実行してみたが,いつまで待っても処理が終わらない. どうやら,プログラムが無限ループしてしまっているようである. ソースコードを詳しく見てみたところ,以下のようなことがわかった. ソースコードは N 行からなり,各行はラベル文か goto 文のいずれかである. ラベル文と goto 文はそれぞれ次のようなフォーマットに従っている. LABEL: goto LABEL; ここで,LABEL はラベルを表す文字列である. プログラムは先頭の行から順番に 1 行ずつ処理される. ラベル文と goto 文を処...
[ { "submission_id": "aoj_2492_718762", "code_snippet": "#include<iostream>\n#include<string>\n#include<vector>\n#include<algorithm>\n#include<functional>\n#include<map>\n#include<sstream>\n#define pb push_back\n#define rep(i,n) for(int i=0;i<n;i++)\nusing namespace std;\ntypedef pair<int,int> P;\nmap<int,int...
aoj_2484_cpp
Problem F: Magnum Tornado We have a toy that consists of a small racing circuit and a tiny car. For simplicity you can regard the circuit as a 2-dimensional closed loop, made of line segments and circular arcs. The circuit has no branchings. All segments and arcs are connected smoothly, i.e. there are no sharp corners....
[ { "submission_id": "aoj_2484_1149669", "code_snippet": "#include <cstdio>\n#include <cmath>\n#include <cstring>\n#include <cstdlib>\n#include <climits>\n#include <ctime>\n#include <queue>\n#include <stack>\n#include <algorithm>\n#include <list>\n#include <vector>\n#include <set>\n#include <map>\n#include <i...
aoj_2490_cpp
() Problem Statement 文字列 S がある.はじめ, S は空文字列である. 以下の処理を n 個順番に行う. S の末尾に p_i (="("または")")を x_i 個追加する. 処理を施した後, S がバランスのとれた文字列であるかどうか判定せよ. 「文字列のバランスが取れている」とは,次のように定義される. 空文字列はバランスが取れている. バランスの取れている文字列 a と b に対して, a + b (+は文字列の連結を表す)はバランスが取れている. バランスの取れている文字列 a に対して,"(" + a + ")"はバランスが取れている. Input 入力は以下の形式に従う.与えられる数は全て整数で...
[ { "submission_id": "aoj_2490_5366880", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i, n) for (int i = 0; i < (n); i++)\n#define rep2(i, a, b) for (int i = (a); i < (b); ++i)\n#define all(a) (a).begin(), (a).end()\n\nusing namespace std;\nusing ll = long long int;\nusing P = pair<int, int>;\n\ncon...
aoj_2489_cpp
回文数 Problem Statement 整数 n に最も近い回文数を求めよ. なお,非負整数 x が回文数であるとは, x を十進法で表現した文字列とそれを反転させた文字列が等しいことをいう. 例えば0,7,33,10301などは回文数であり,32,90,1010などは回文数でない. Input 入力は以下の形式に従う.与えられる数は全て整数である. n Constraints 1≦n≦10^4 Output n に最も近い回文数を出力せよ. そのような数が複数ある場合は最も小さいものを出力せよ. Sample Input 1 13 Output for the Sample Input 1 11 13に最も近い回文数は11であ...
[ { "submission_id": "aoj_2489_10570366", "code_snippet": "#include \"bits/stdc++.h\"\n\nusing namespace std;\n\n#define ll long long\n#define REP(i, n) for(int i = 0;i < n; i ++)\n#define REPR(i, n) for(int i = n;i >= 0; i--)\nint main(){\n ll n, ans, dif = 100000000;\n cin >> n;\n REP(i, 1000000){\...
aoj_2488_cpp
Problem J: Tree Construction Consider a two-dimensional space with a set of points ( x i , y i ) that satisfy x i < x j and y i > y j for all i < j . We want to have them all connected by a directed tree whose edges go toward either right ( x positive) or upward ( y positive). The figure below shows an example tree. Fi...
[ { "submission_id": "aoj_2488_10687774", "code_snippet": "#include<cstdio>\n#include<algorithm>\nusing namespace std;\nint x[1024],y[1024],dp[1024][1024];\nint main()\n{\n int n,minx=1e9,miny=1e9,ans;\n scanf(\"%d\",&n);\n for(int i=1; i<=n; i++)\n scanf(\"%d%d\",&x[i],&y[i]);\n for(int i=...
aoj_2495_cpp
魔法陣 Problem Statement 〜魔法陣の描き方〜 十分広くて真っ白な床を用意します. 床の座標 (0,0) の点を中心にして,半径 1, 2, ..., R の円を描きます. 半径 1 の円と半径 2 の円の間,半径 3 の円と半径 4 の円の間, ... を青色で塗ります.なお,半径 R の円の外には色を塗ってはいけません. 床に頂点数 N の多角形を一つ描きます. 多角形の内部の白色の領域を青色で,青色の領域を白色で塗りなおします. 魔法陣の力は,魔法陣に青色が多く含まれるほど強くなるという. そこであなたには,魔法陣に含まれる青い領域の面積を求めてほしい. 次の図はこの手順で描くことのできる魔法陣の一例である. ...
[ { "submission_id": "aoj_2495_3114581", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <complex>\n#include <vector>\n#include <algorithm>\n#include <cmath>\n#include <array>\nusing namespace std;\nconst double EPS = 1e-10;\nconst double INF = 1e12;\nconst double PI = acos(-1);\n#define EQ...
aoj_2491_cpp
さんぽ Problem Statement ねこのそらは散歩が大好きだ.道を歩くと新しい発見がある. そらの住む町は N 個の広場と N-1 本の道からなる. 道はちょうど二つの広場をつないでおり,枝分かれしたり道どうしが交わったりしない. 道には,歩くのにかかる時間 t ,得られる発見の個数の上限 m ,および,発見一つあたりの価値 v が指定されている. 道を一方の端からもう一方の端まで歩いたとき, m 回目までの通行では価値 v の発見が一つ得られるが, m+1 回目以降は発見が得られない. 今日もそらは,町内の散歩に出かけるようだ. そらの散歩は広場 1 から始まり,いくつかの道 ( 0 本かもしれない ) を通って,最後に...
[ { "submission_id": "aoj_2491_9762704", "code_snippet": "#include<stdio.h>\n#include<iostream>\n#include<vector>\n#include<map>\n#include<queue>\n#include<string.h>\n#include<algorithm>\nstruct Way{\n\tint to;\n\tlong long int t,m,v;\n};\nstruct S{\n\tlong long int v,t;\n\tbool operator<(const S& s)const{\n\...
aoj_2493_cpp
replace Problem Statement 文字列 S が与えられる. 以下の処理を Q 個順番に行う. S に含まれる文字 c_i を全て同時に文字列 p_i で置き換える. 最後に文字列 S の A 文字目から B 文字目まで(1-indexed)を出力せよ. Input 入力は以下の形式に従う.与えられる数は全て整数である. S Q A B c_1 p_1 ... c_Q p_Q Constraints 1≦Q≦3 \times 10^5 1≦A≦B≦10^{18} B-A≦10^5 1≦|S|≦10 1≦|p_i|≦10 S は小文字のアルファベットからなる文字列である. c_i は小文字のアルファベット1文字である...
[ { "submission_id": "aoj_2493_1125326", "code_snippet": "#include <iostream>\n#include <vector>\n#include <map>\nusing namespace std;\n\nstruct NODE{\n\tchar var;\n\tvector<NODE*> ch;\n};\n\nNODE *nowTarget[128];\nNODE id[400000*10];\n\nint pool = 0;\nNODE* next(char c){\n\tid[pool].var = c;\n\treturn &id[po...
aoj_2504_cpp
D: Statement Coverage / 命令網羅 「うわっ!なんてひどいコードだ!」 古いソースコードを開きながら先輩が叫んでいる. また面倒な仕事が押し付けられそうだ……. ソースコードにはめまいがしそうなほどたくさんの if 文が並んでいる. if 条件文 1; 命令 1 if 条件文 2; 命令 2 if 条件文 3; 命令 3 ... どうやら制御の構造はそれほど複雑ではないらしい. 1 つの条件文には,変数と NOT 演算子 "~" ,そして AND "&" / OR "|" の 2 項演算子が現れる. 変数は真または偽を表し,変数名は1文字以上のアルファベットで表される. 演算の順序は NOT 演算子が優先だが,...
[ { "submission_id": "aoj_2504_718303", "code_snippet": "#include <cassert>\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <cstdio>\n#include <cmath>\n#include <cstring>\n#include <cstdlib>\n#include <set>\n#include <map>\n#include <queue>\n#include <stack>\n#include <string>\n#includ...
aoj_2494_cpp
Sliding GCD Problem Statement 自然数の集合 S に対して,集合 \{ GCD(T) | T ⊆ S, T は空でない \} の要素数を f(S) とおく. ここで, GCD(T) は T に含まれるすべての数を割り切るような最大の整数である. 特に, T が一つの整数 a のみからなるときは GCD(\{a\}) = a であることに注意せよ. i = 1, 2, . . ., N - W+1 に対して f(\{i, i+1, . . ., i+W - 1\}) を求めよ. Input 入力は以下の形式に従う.与えられる数は全て整数である. N W Constraints 1 ≦ W ≦ N ≦ 10^...
[ { "submission_id": "aoj_2494_8306788", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll =long long;\nusing vll=vector<ll>;\nusing vvll=vector<vll>;\n#define rep(i,n) for(ll i=0;i<n;i++)\n\nbool E(ll L,ll R,ll N){\n if(L<=N&&N<=R)return 1;\n if((R/N)-(L-1)/N>=2)return 1;\n e...
aoj_2497_cpp
One Problem Statement 電車の窓から美しい山並みが見える. 窓は,左下隅の座標が (0, 0) ,右上隅の座標が (W, H) の長方形である. 窓からは N つの山が見えており, i 番目の山は上に凸な放物線 y = a_i (x-p_i)^2 + q_i の形をしている. 山と空との境界線の長さを求めよ. 次の三つの図は Sample Input に対応している.太線で示されている部分が山と空との境界線である. Input 入力は以下の形式に従う.与えられる数は全て整数である. W H N a_1 p_1 q_1 ... a_N p_N q_N Constraints 1 ≦ W, H ≦ 100 1 ≦ N...
[ { "submission_id": "aoj_2497_8750197", "code_snippet": "#include <iostream>\n#include <vector>\n#include <utility>\n#include <algorithm>\n#include <cmath>\n#include <iomanip>\nusing namespace std;\n\nint main() {\n int W, H, N;\n cin >> W >> H >> N;\n vector<double> a(N), p(N), q(N);\n for (int ...
aoj_2503_cpp
C: Project Management / プロジェクト管理 あなたは凄腕のプロジェクトマネージャである. 今回は超大規模なプロジェクトのマネジメントを請け負った. 図1: アローダイアグラム これまでの勘と経験からなんとか 図1 のようなアローダイアグラムを作成した. 各ノードは作業の結合点を表している. また,Sはプロジェクトの開始状態,Tはプロジェクトの終了状態を表す結合点である. 例えば結合点P3において,作業Gは作業Cと作業Eが終了しなければ開始できない. プロジェクトの計画は完璧であり,全ての結合点は,そこから出て再びその結合点に戻る作業経路を持たない. また,全ての作業は前後に結合点を持っており, 開始状態と終了状...
[ { "submission_id": "aoj_2503_3677763", "code_snippet": "#include<iostream>\n#include<algorithm>\nusing namespace std;\nint main() {\n\tint data[400][400], n, m, a, b, c;\n\tcin >> n >> m;\n\tfor (int i = 0; i < n; ++i)\n\t\tfor (int j = 0; j < n; ++j) data[i][j] = -10000000;\n\tfor (int i = 0; i < m; ++i) {...
aoj_2502_cpp
B: VOCAL ANDROID ボーカルアンドロイド (VOCAL ANDROID) とは,メロディと歌詞を入力して音声を合成する作曲ツールである. 2013年3月9日に和歌山県で開催された,ボーカルアンドロイドのライブに行ったあなたは,音楽の素晴らしさに感動した. そこで,あなたは新作ボーカルアンドロイド「立音リプロ (CV.立命太郎)」を購入し,作曲を始めることにした. ところが,メロディは完成したものの作詞で詰まってしまった. 使いたいフレーズはいくつか断片的に用意しており,それらを組み合わせて各メロディにあてはめる. 各メロディは,長さが決まっており,必ずこの長さぴったりになるようにフレーズをあてはめる必要がある. また,...
[ { "submission_id": "aoj_2502_11003781", "code_snippet": "#define _CRT_SECURE_NO_WARNINGS\n#include <cstdio>\n#include <iostream>\n#include <stack>\n#include <queue>\n#include <algorithm>\n#include <functional>\n#include <set>\n#include <map>\n#include <string>\n#include <vector>\n#include <cmath>\n#include<...
aoj_2505_cpp
E: Twins Idol / ツインズアイドル アイドル事務所841プロダクションには,多くの個性的なアイドル達が所属している. 双子のアイドルであるアキ&マキは,841プロに所属するアイドルであり,2人ともとてもゲーム好きである. ある日2人は,次のようなゲームを自分達で自作して楽しむことにした. このゲームは,2人で協力するタイプのゲームであるため,双子の息の合ったプレイが期待される. まず,ゲームを始める前に,2人が別々に自分の好きなようにフィールドを床に描く. フィールドは,アルファベットの1文字が書かれたいくつかのボードと,ボード間をつなぐルートで構成される. 彼女らは,このルート上を辿ることで,ボード間を移動できる. ...
[ { "submission_id": "aoj_2505_10268441", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n// Структуры для хранения графа одного поля:\nstruct Graph {\n int N, M;\n vector<char> letter; // буква на каждой доске (1..N)\n vector<vector<int>> adj; // список смежности (направле...
aoj_2507_cpp
G: Computer Onesan / コンピュータおねえさん ある日,おねえさんは,子供たちに組合せの数え方について教えてあげることになりました. そこで,おねえさんは,次のような問題を解いてみることにしました. 縦幅 1 ,横幅 1 の正方形を縦幅 N ,横幅 M の長方形に敷き詰めたときに,長方形の左上の頂点から右下の頂点への通り方が何通りあるかを数える 敷き詰めた正方形の辺の上しか通れない それぞれの通り方は,同じ場所を1度しか通らない 図1に, N = 2, M = 2 の場合の全ての通り方を示します. 図1では,全部で12通りの通り方を示しており,その経路は赤い太線で表しています. 図1: N = 2, M = 2 の...
[ { "submission_id": "aoj_2507_3677883", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define int long long\n\nint n,m;\nint dp1[111][111][3];\nint dp2[111][111][111][3];\n\nint dfs1(int A,int B,int d){\n if(n<A || n<B)return 0;\n if(B==n)return 1;\n if(dp1[A][B][d]!=-1)return dp1[A...
aoj_2500_cpp
社員旅行 Problem Statement あなたの会社には n 人の社員が存在する. m 個の社員 (a_i,b_i) の組について, a_i は b_i の上司である. 社員 x が社員 y の実質的な上司であるとは,次のうち少なくとも一方が成り立つことをいう. x が y の上司である. y の実質的な上司である社員 z が存在して, x は z の上司である. あなたの会社で,自分自身が自分の実質的な上司であるような社員は存在しない. あなたの会社では社員が全員参加する社員旅行が計画されている.全社員の要求により,旅館での部屋割りは「よい部屋割り」でなければならない. ある部屋割りが「よい部屋割り」であるとは以下の両方が満...
[ { "submission_id": "aoj_2500_10435908", "code_snippet": "// AOJ #2500 Company Trip\n// // 2025.4.30\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; int c = gc();\n\tif (c == '-') {\tc = gc();\n\t\tdo n = 10*...
aoj_2506_cpp
F: Opeartion training for BYDOL / BYDOLの操作訓練 u'sというスクールアイドルを結成した私達は,さらなる高みを目指すため,部室にあったDVDで憧れの841プロダクションに所属するアイドル達を見ていた. このアイドル達は今でこそ輝くステージの上で活躍しているが,以前はBYDOLと呼ばれるロボットに乗り込み,隕石の撤去作業をしていたらしい. そこで,トップアイドルになるために,BYDOLの操縦技術が必要であることを知った私達は,急遽BYDOLを入手し,他校のスクールアイドルとBYDOLを用いた模擬戦をすることにした. この模擬戦では,白の軍と赤の軍に分かれ,BYDOLに積まれている弾により撃ち合い...
[ { "submission_id": "aoj_2506_892080", "code_snippet": "#include <bits/stdc++.h>\n#define REP(i,n) for(int i=0; i<(int)(n); ++i)\n\nusing namespace std;\n\n// --- min_cost_flow --- \nstruct MinCostFlow{\n typedef pair<int, int> P; // (最短距離, 頂点の番号)\n static const int INF = 100000000; // infinity\n\n ...
aoj_2510_cpp
双子の読書感想文 双子のアミとマミが通う学校では早くも夏休みに突入し,今年もおびただしい量の宿題が出された. しかし,遊び盛りの2人は今日も宿題には一切手をつけずに外へ遊びに行こうとしていた. このままでは夏休み最終日に泣きを見るのは明らかなので,保護者役のあなたは,心を鬼にして今日は読書感想文の宿題が終わるまで2人を家から出さないことにした. 準備の良いあなたは既に図書館から全ての課題図書を借りてある. ただし,図書館の規則により各本は1冊ずつしか借りられていない. さて,教育上の理由から2人には互いに協力することなく,それぞれ全ての本を読み,感想を書いてもらう事にした. 加えて,本の返却期限が近いため,まずはなるべく早くすべての...
[ { "submission_id": "aoj_2510_10559312", "code_snippet": "#include<bits/stdc++.h>\n//#include <atcoder/all>\nusing namespace std;\n//using namespace atcoder;\n\n#define all(v) v.begin(),v.end()\nusing ll = long long;\nusing ull = unsigned long long;\nusing lll = __int128;\nusing vll=vector<ll>;\nusing vvll =...
aoj_2512_cpp
小野小町の編集合戦 近所に住む秋田博士は在野の歴史研究家であり, 最近小野小町に関する新たな古文書を発見したそうだ. 小野小町が交際を望む深草少将に100夜欠かさず通い続けることを条件に出したという伝説は広く知られているが, 彼の主張によると, この発見により新たに, 2人は毎晩とあるゲームをしていたことがわかったという. そのルールは以下の通りである. 最初に召使が編集回数と有効な数式を決める 深草少将, 小野小町, 深草少将, 小野小町,... という順に交互に数式を編集する 深草少将と小野小町が合わせて召使が決めた回数の編集を行うとゲームは終了する 1回の数式の編集において, 数式に 1 文字追加, または数式から 1 文字削...
[ { "submission_id": "aoj_2512_10853841", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconstexpr int INF = 1e9;\n\nint expr(string const& s, int& p);\nint Or(string const& s, int& p);\nint Xor(string const& s, int& p);\nint And(string const& s, int& p);\nint Plus(string const& s, int& p)...
aoj_2511_cpp
Description fetch failed. Please view: https://onlinejudge.u-aizu.ac.jp/problems/2511
[ { "submission_id": "aoj_2511_10852913", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing pii = pair<int, int>;\n\nstruct edge {\n int from, to, cost;\n bool operator<(edge const& es) const {\n return cost < es.cost;\n }\n};\n\nusing edges = vector<edge>;\nusing graph ...
aoj_2513_cpp
テトラ姫のパズル パレス王国のテトラ姫は無類のパズル好きとして知られており,最近は自身が考案した「テトラパズル」に熱中している. これは,正三角形のマスを敷き詰めたボードと,テトラブロックと呼ばれる 4 枚の正三角形のパネルからなる正四面体のブロックを使ったパズルである. パズルの目的は,ボード上のすべてのテトラブロックを以下の条件をみたすように展開することである. 展開されたテトラブロックが,置かれていたマスおよび,それぞれに指定された異なる 2 つのマスを覆っている どのマスも,2 つ以上のパネルで覆われていない 図F-1はテトラパズルの問題例および,その解答例である. ★のマスと●のマスにテトラブロックが置かれており,それぞれ...
[ { "submission_id": "aoj_2513_8310771", "code_snippet": "#include <iostream>\n#include <cmath>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n#pragma warning (disable: 4996)\n\nconst vector<vector<pair<int, int>>> Orientation = {\n\tvector<pair<int, int>> { make_pair(0, 0), make_pair(1, 0)...
aoj_2516_cpp
Problem B: あみだくじ Problem Statement 会津合宿に参加予定の高槻さんは、家が貧乏であり、いつも紙をなるべく節約して使うようにしている。彼女は、会津合宿のチーム決めのために、他の参加者の人達とあみだくじをすることになった。 この合宿のあみだくじの作り方は次のようなものである。まず、紙にN本の縦棒を平行に書く。そして、M本の横棒を上から順番に、縦棒と垂直になるように、かつ横棒の高さが全て異なるように書いていく。例えば、Sample Input 1のあみだは、図1のようになる。 ここで、高槻さん、ちょっと不満げな表情。こんなに縦長にあみだくじを書いていると紙がもったいない。もっと、高さを圧縮できるはず。という...
[ { "submission_id": "aoj_2516_3579941", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\nconst int INF = 1e9;\nint N, M;\nvector<int> res;\n\nvector<int> simu(const vector<vector<bool>> &A){\n vector<int> ret(N+1);\n for(int i = 0; i < N+1; ++i) ret[i] = ...
aoj_2526_cpp
Problem E: Pie Chart is as easy as pie. ICPC World Finals 3日目 この日、ティー氏はチーム内の言語使用割合を調べていた。 珍しいことに、我々のチームは使用言語を統一していない。 調査の結果、2人がC++、1人がJavaを使っていることが分かった。 さて、これをパイチャート(円グラフ)にしてみよう。 おや、Javaの使用割合が少ないように見えるな。 どう考えてもこんなはずはないので少々手を加えよう。 これは最近流行りのテクニックであり、 「パイチャートの中心座標をずらす」というものだ。 (皆さんはマネしてはいけません。) うむ、これでバランスがとれた。 ところで面積はどのように...
[ { "submission_id": "aoj_2526_1127153", "code_snippet": "#include<stdio.h>\n#include<math.h>\n#include<algorithm>\nusing namespace std;\nint b[12];\ndouble p[12];\ndouble q[12];\ndouble PI=acos(-1.0);\nint main(){\n\tint x,y;\n\tint a;\n\tscanf(\"%d%d%d\",&a,&x,&y);\n\tscanf(\"%d\",&a);\n\tfor(int i=0;i<a;i+...
aoj_2517_cpp
Problem C: ホテル探し Problem Statement 会津合宿に参加予定の高槻さんは、家が貧乏であまりお金を持っていない。彼女は、合宿のためにホテルを探しているが、なるべくお金を節約できるプランにするために、悩み中である。宿泊の合計金額が安くなるホテルの泊まり方を求めて、彼女に教えてあげよう。 宿泊するホテルの候補数は、N個であり、各ホテルをホテル1、ホテル2、...、ホテルNと呼ぶこととする。彼女は、これからD泊分の予約をこれらのホテルから選ぶことにしている。候補のホテルは全て、1泊ごとに宿泊料金が変動することがあるため、入力では各ホテルごとにD泊分の宿泊費が与えられる。 D泊分の宿泊費の合計が最小になるような、ホ...
[ { "submission_id": "aoj_2517_5294060", "code_snippet": "#include <iostream>\n#include <iomanip>\n#include <vector>\n#include <algorithm>\n#include <string>\n#include <cmath>\n#include <queue>\n\nusing namespace std;\n\nusing ll = long long;\n\n//const ll INF = 1LL << 60;\n//const ll MINUS_INF = -INF;\n\ncon...
aoj_2528_cpp
Problem G: Get Lost ICPC World Finals 5日目 ティー氏はR国の街で迷ってしまった。 困ったことに、街並みが似ているため、自分が今どこにいるかが全く分からない。 R国は「おそろしあ」であるから、敵に襲撃される前にホテルへ戻らねばならない。 幸い、どのように曲がって来たかだけは覚えているので、 行き当たりばったりに進んでみよう。 問題 \( w \times h \)マスの二次元格子状のマップがある。 左上のマスの座標を\( (1, 1) \)、右下のマスの座標を\( (w, h) \)とする。 マップの周りは壁で囲まれており、 \(n\)個の障害物が座標\( (x_{i}, y_{i}) (1 \...
[ { "submission_id": "aoj_2528_10827749", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <vector>\n#include <string>\n\nusing namespace std;\n\nusing lli = long long;\nusing P = pair<lli, lli>;\n\nconstexpr lli MAX = 100000;\n\nlli w, h, gx, gy, n;\nvector<P> input;\nvector<lli> vec[4][M...
aoj_2519_cpp
Problem E: 英語の勉強 Problem Statement 会津合宿に参加予定の高槻さんは勉強熱心で、最近は英語の勉強をがんばっている。彼女は、携帯を使って次のようなゲームをプレイすることで、少しでも多く英単語を覚えようとしている。彼女が持っている携帯は、指で画面を操作するタッチパネル式である。 携帯の画面には、4 * 4のマス目が描かれており、各マスにはアルファベット大文字が書かれている。このゲームは、制限時間T秒の間に、マス目の中に隠されている英単語をたくさん見つけ、発見できた英単語の種類により点数を競うものである。 1つの単語を見つける手順は、次のようになる。まず、単語の1文字目に対応する開始マスを決めて、そこに指を...
[ { "submission_id": "aoj_2519_4124883", "code_snippet": "#include <iostream>\n#include <vector>\n#include <array>\n#include <list>\n#include <string>\n#include <stack>\n#include <queue>\n#include <deque>\n#include <unordered_map>\n#include <unordered_set>\n#include <tuple>\n#include <memory>\n#include <cmath...
aoj_2521_cpp
Problem G: 穴掘って埋まってます Problem Statement 魔法使いの萩原さんは、非常にネガティブな性格である。彼女は、何か落ち込むようなことがあると、穴掘りの魔法を使って穴を作り、泣きながら埋まってしまう。穴掘りの魔法とは、次のようなものである。 彼女は、まずN本の線分を地面に描く。そして、彼女が呪文を唱えると、線で囲まれた範囲に穴が出来上がる。交差・内包の関係にある2つの穴は、1つの穴として数える。ただし、頂点のみで接している2つの穴は、別々の穴として数える。 図1と図2に、Sample Input 1と2の図を示す。まず、図1において、Aの三角形とBの三角形は、頂点のみで接しているため、別々の穴と数える。B...
[ { "submission_id": "aoj_2521_3616318", "code_snippet": "#include<iostream>\n#include<string>\n#include<algorithm>\n#include<vector>\n#include<iomanip>\n#include<math.h>\n#include<complex>\n#include<queue>\n#include<deque>\n#include<stack>\n#include<map>\n#include<set>\n#include<bitset>\n#include<functional>...
aoj_2514_cpp
鏡の迷路 誇り高き勇者であるあなたは、ついに魔王の元へ辿り着こうとしていた。しかし、魔王がいる玉座の間に辿り着くためには、魔王が用意した最終マップをクリアしなければならない。 このマップにおいては、全てのものが、上空から見た二次元平面図のように変化してしまう。人間は、このマップにおいては、ただの点に変形してしまう。マップは、1本の直線によって、2つの区域に区切られている。そして、ある一方の区域に人がいるとき、もう一方の区域の、直線に対して線対称となる位置に、人の鏡像が映し出される。 2つの区域それぞれには、複数の建物が存在する。建物と言っても、このマップでは、いくつかの点を繋いで出来上がる多角形であり、辺で囲まれた内側、および辺上が...
[ { "submission_id": "aoj_2514_6145213", "code_snippet": "#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\n#include<iostream>\n#include<string>\n#include<cstdio>\n#include<vector>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<iomanip>\n#include<queue>\n#include<cis...
aoj_2527_cpp
Problem F: MLE ICPC World Finals 4日目 暗い嵐の夜だった。 夢の中でティー氏はタイムスリップしていた。 ICPCの会場のようだが何かおかしい…。 もしや…これは、N年前(Nは自然数)のICPCなのか…? 混乱の内に競技は開始してしまった。 だが慌てる必要はない。 きっと問題も簡単に違いない。 例えばこれなどはソートするだけで解けてしまうはずではないか。 冷静にコードを書き上げ、速やかにSubmit。 しかしその結果は…Memory Limit Exceeded…?! 問題 C++言語については以下のコード long long int a[n]; unsigned long long int x = ...
[ { "submission_id": "aoj_2527_10827745", "code_snippet": "// C++20\n#include <bits/stdc++.h>\nusing namespace std;\n\nusing u64 = unsigned long long;\nusing u32 = unsigned int;\n\nstatic inline u64 next_xorshift(u64 &x) {\n x ^= x << 13;\n x ^= x >> 7;\n x ^= x << 17;\n return x;\n}\n\nint main()...
aoj_2509_cpp
どうぶつの盛り2013 Sim Forest 2013というゲームがある。このゲームでは、プレイヤーは森の神様となって森林の動物を育成することができる。 動物は卵から孵化し、繁殖する。卵は特定の条件を満たすと、一定の確率で突然変異し新しい種族の動物が生まれる。 このゲームには動物事典というものが存在し、新しい種類の動物を入手すると動物辞典に記録されていく。 盛さんは Sim Forest 2013の熱狂的なプレイヤーである。彼の動物辞典は残り1種族を埋めると完成となる。 盛さんはこの残りの1種族を、卵からの突然変異により入手することにした。 ゲーム進行は以下のとおりである。 ステージ開始時に n個 の卵が出現する。 ステージ開始から...
[ { "submission_id": "aoj_2509_10569054", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nvoid solve() {\n const vector<string> DOW_STR = {\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"};\n const int CHUNK_MINS = 6 * 60;\n\n int s, n, t, p, m;\n string weekday_s...
aoj_2532_cpp
Problem K: Collector ※この物語はフィクションであり、実在の人物、団体などとは一切関係がありません。 最近ソーシャルゲームがとても人気で、 たくさんの会社がソーシャルゲームを開発しています。 あなたは競合しているソーシャルゲーム開発会社の一つにスパイとして潜入しています。 問題 あなたの務めている会社では、ソーシャルゲームを開発している。 開発しているゲームは、カードを集めて戦うゲームであり、 1回300円 の有料”ガチャガチャ”を収益の柱にしている。 このゲームのカードには、”ノーマル”、”レア”、”Sレア”の3種類がある。”Sレア”カードはN種類存在する。 有料”ガチャガチャ”では、1回行うごとに97%の確率...
[ { "submission_id": "aoj_2532_2765855", "code_snippet": "#include <cmath>\n#include <iomanip>\n#include <iostream>\nusing namespace std;\nconst double lim = 0.0001;\nint n; double p[309], sq[309], a[309];\nint main() {\n\tcin >> n;\n\tfor (int i = 0; i < n; i++) cin >> p[i], sq[i] = sqrt(p[i]), a[i] = 0.03 /...
aoj_2520_cpp
Problem F: 自転車 Problem Statement 菊地君は、大の自転車好きである。今日も彼は、お気に入りの自転車に乗ってサイクリングロードへと走り出そうとしている。 彼が住む地域には、N個の町が存在する。各町を町1、町2...、町Nと呼ぶこととする。彼が住む町は、町1である。この地域には、サイクリングを趣味としている人が多く、最近では頻繁に町と町を結ぶサイクリングロードが作られている。サイクリングロードを使うと、2つの町を双方向に移動できる。入力では、どの町とどの町が新しくサイクリングロードで繋がれたかが時系列順に入力される。 菊地君は、新しいサイクリングロードが1つ完成したときに、次に示す条件を満たすときだけサイク...
[ { "submission_id": "aoj_2520_4777844", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define rep(i, n) for(int i = 0; i < n; i++)\n#define rep2(i, x, n) for(int i = x; i <= n; i++)\n#define rep3(i, x, n) for(int i = x; i >= n; i--)\n#define elif else if\n#define sp(x) fixed << setprecisio...
aoj_2537_cpp
Problem Statement You have a billiard table. The playing area of the table is rectangular. This billiard table is special as it has no pockets, and the playing area is completely surrounded with a cushion. You succeeded in producing a ultra-precision billiards playing robot. When you put some balls on the table, the ma...
[ { "submission_id": "aoj_2537_4809052", "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; } return...
aoj_2531_cpp
Problem J: Avant-garde Art ICPC World Finals 6日目 ロシア構成主義とは、1910年代半ばに始まったソ連における芸術運動である。 R国に長く滞在していたティー氏は、 そのようなものに感化され、 ICPC World Finalsのリハーサル中にも関わらず、 クールなデザインを作ることにした。 ティー氏は語る: 「記号は円と線分だけで充分だ。 線分をいかに美しく交差させるかが重要である。」 問題 円周に\(n\)個の座標\( 1, 2, …, n \)を等間隔に割り当てる。 各座標からはちょうど1本の線分が出ており、 座標\( i \)の線分は異なる座標\( a_{i} \)に結ばれている。...
[ { "submission_id": "aoj_2531_10827763", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long;\nusing ull = unsigned long long;\n\n#define chmin(x,y) x = min(x,y)\n#define chmax(x,y) x = max(x,y)\n\nconstexpr int BIG_NUM = 2000000000;\nconstexpr ll HUGE_NUM = 40000000000...
aoj_2534_cpp
Problem Statement We found a dictionary of the Ancient Civilization Mayo (ACM) during excavation of the ruins. After analysis of the dictionary, we revealed they used a language that had not more than 26 letters. So one of us mapped each letter to a different English alphabet and typed all the words in the dictionary i...
[ { "submission_id": "aoj_2534_10499700", "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_2535_cpp
Problem Statement Texas hold 'em is one of the standard poker games, originated in Texas, United States. It is played with a standard deck of 52 cards, which has 4 suits (spades, hearts, diamonds and clubs) and 13 ranks (A, K, Q, J and 10-2), without jokers. With betting aside, a game goes as described below. At the be...
[ { "submission_id": "aoj_2535_10853000", "code_snippet": "#include<set>\n#include<cmath>\n#include<stack>\n#include<cstdio>\n#include<cstring>\n#include<iostream>\n#include<algorithm>\n#include<cstdlib>\n#include<numeric>\n#include<vector>\n#include<ctime>\n#include<queue>\n#include<list>\n#include<map>\n#de...
aoj_2538_cpp
Problem Statement There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H) . You are now at the cell (1, 1) and have to go to the cell (W, H) . However, you can only move to the right adjacent cell or to the lower adjacent cell. The fol...
[ { "submission_id": "aoj_2538_10852888", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define N 55\n\nconst int INF = (int)1e9;\n\nbool adj[N][N][N][N];\nint f[N][N][N][N];\nchar mat[N][N];\nint n, m;\nvector<pair<int, int> > vec[26];\n\nbool ok(int x, int y) {\n\treturn x >= 0 && x <...
aoj_2540_cpp
Problem Statement One day in a forest, Alice found an old monolith. She investigated the monolith, and found this was a sentence written in an old language. A sentence consists of glyphs and rectangles which surrounds them. For the above example, there are following glyphs. Notice that some glyphs are flipped horizont...
[ { "submission_id": "aoj_2540_10852935", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\ntypedef pair<int, int> HA;\nconst int N = 105, M = 1005, MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;\nchar s[N][M];\nHA calc_HA(int x1, int y1, int x2, int y2) {\n\tint a1 = 0, a2 = 0;\n\tfor (int i = x1; i <= x2; +...
aoj_2536_cpp
Problem Statement You are given a connected undirected graph which has even numbers of nodes. A connected graph is a graph in which all nodes are connected directly or indirectly by edges. Your task is to find a spanning tree whose median value of edges' costs is minimum. A spanning tree of a graph means that a tree ...
[ { "submission_id": "aoj_2536_10853203", "code_snippet": "/*\nAuthor: 1412kid1412@UESTC\n*/\n\n#include <stdexcept>\n#include <cstdarg>\n#include <iostream>\n#include <fstream>\n#include <exception>\n#include <memory>\n#include <locale>\n#include <sstream>\n#include <set>\n#include <list>\n#include <bitset>\...
aoj_2530_cpp
Problem I: Reverse Game あるところにオセロが趣味な女の子がいました。時間があるときに家族とオセロを楽しんでいます。 ある日、女の子はいつものようにオセロで遊ぼうとしました。ところが、みんな忙しくて誰も遊んでくれませんでした。 そこでオセロのボードとこまを使って1人で遊べるゲームを考え出しました。 問題 縦\( R \)マス、横\( C \)マスのマス目全てにオセロの駒が上面が黒あるいは白になるように配置されている。 以下の図のように「あるマスを選んで、その上下左右斜め方向にある駒を全て裏返す」という操作を繰り返し行うことを考える。 全ての駒の上面を白にするような操作の仕方の個数を求めよ。 ただし、以下の条件を...
[ { "submission_id": "aoj_2530_10827760", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing wolf = unsigned long long;\nconstexpr int MOD = 1'000'000'009;\nconstexpr int MAXA = 110;\nconstexpr int MAXB = 110;\nconstexpr int MAXV = 2600; // a*b の最大\nconstexpr int WORDS = 42; // 2600 / 6...
aoj_2542_cpp
Problem Statement Chelsea is a modern artist. She decided to make her next work with ladders. She wants to combine some ladders and paint some beautiful pattern. A ladder can be considered as a graph called hashigo . There are n hashigos numbered from 0 to n-1 . Hashigo i of length l_i has 2 l_{i} + 6 vertices v_{i, 0}...
[ { "submission_id": "aoj_2542_2921911", "code_snippet": "// implement 140min\n// implement2 75min\n// debug1 10min\n// debug2 30min\n#include <stdio.h>\n#include <string.h>\n#include <algorithm>\n#include <iostream>\n#include <math.h>\n#include <assert.h>\n#include <vector>\n#include <queue>\n#in...
aoj_2546_cpp
C - チョコレート 目の前に M \times N 個のピースでできた板チョコがある. ピースには甘いピースと辛いピースの2種類があり,できるだけ多くの甘いピースを食べたい. しかし,板チョコの食べ方にはルールがあり,以下のルールを守らなければならない. あるピースを食べるためには,そのピースの真上に隣接するピースが存在せず,加えてそのピースの少なくとも左右どちらかにはピースが存在しない必要がある. 例えば,図のような形のチョコレートでは,赤く色付けされたピースを次に食べることができる. また奇妙なことに,あるピースを食べるとそのピースの上下左右に隣接していてかつまだ食べられていないピースの味が変化する. (甘いピースは辛...
[ { "submission_id": "aoj_2546_2180900", "code_snippet": "#include <iostream>\nusing namespace std;\nint dir[] = { 0, 1, 0, -1 };\nint H, W, a[109][109];\nint main() {\n\tcin >> H >> W;\n\tfor (int i = 0; i < H; i++) {\n\t\tfor (int j = 0; j < W; j++) {\n\t\t\tcin >> a[i][j];\n\t\t}\n\t}\n\tint ret = 0;\n\tfo...
aoj_2541_cpp
Problem Statement A magician lives in a country which consists of N islands and M bridges. Some of the bridges are magical bridges, which are created by the magician. Her magic can change all the lengths of the magical bridges to the same non-negative integer simultaneously. This country has a famous 2-player race gam...
[ { "submission_id": "aoj_2541_10851249", "code_snippet": "#include<cstdio>\n#include<iostream>\n#define ll long long\n#define abs(x) (x > 0 ? x : -(x))\n#define F(a,b,c) ((a) + (b) * (c))\nusing namespace std;\n\nconst int maxn = 1200;\nconst int maxm = 2200;\nconst ll inf1 = 1000000000ll * 1100;\nconst ll i...
aoj_2545_cpp
B - ライオン あなたは動物園に来てライオンを見ている。 この動物園には n 個のライオンのオリがある。 あなたはライオンが全部で何頭いるのか知りたくなったのだが、 一人で数えるのは大変だ。 そこで近くにいた動物園の来園者 m 人に協力してもらうことにした。 ライオンのオリは、それぞれ 1 番から n 番までの数字がついており、 順番に並んでいる。 一つのオリには 0 頭以上 x 頭以下のライオンがいる。 m 人の来園者で i 番目の人 (1 ≤ i ≤ m) には l_i 番から r_i 番までの 両端を含むすべてのオリのライオンの数の総和を数えてもらった。 この情報を元に、 1 から n 各オリの中のライオンの数を求めることに...
[ { "submission_id": "aoj_2545_10557021", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nvoid dfs(vector<int> v, vector<int> &L, vector<int> &R, vector<int> &S, int N,\n int M, int X, int &ans, vector<int> &ansvec) {\n if (v.size() == N) {\n vector<int> s(N + 10);\n ...
aoj_2539_cpp
Problem Statement Let b_i(x) be the i -th least significant bit of x , i.e. the i -th least significant digit of x in base 2 ( i \geq 1 ). For example, since 6 = (110)_2 , b_1(6) = 0 , b_2(6) = 1 , b_3(6) = 1 , b_4(6) = 0 , b_5(6) = 0 , and so on. Let A and B be integers that satisfy 1 \leq A \leq B \leq 10^{18} , and ...
[ { "submission_id": "aoj_2539_10853136", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <algorithm>\n\nusing namespace std;\n\nconst unsigned long long inf=(unsigned long long)1e18;\n\nint n,num;\nunsigned long long f[100],l,r,x,p,s[100],t[100];\n\nvoid get(unsigned long...
aoj_2548_cpp
E - すごろく 友達のいないきつねのボブは,今日は一人ですごろく遊びをして過ごすことにした. 各面に整数 a_1,a_2,a_3,a_4,a_5,a_6 が書かれた6面ダイスと,駒と,直線上にM個のマスがあり 左から順に 1 から M までの番号が割り当てられたすごろく盤を用いることにした. すごろく盤の各マスには指示が数字で書かれており, i 番目のマスには数字 N_i が書かれている. これは,その値が正なら右,負なら左に,その絶対値だけ駒を移動せよという意味である. すなわち, i+N_i 番目のマスに駒を移動せよという意味である. ボブは,以下のようにしてすごろく遊びをする.まず駒をスタート地点に置く. 次にサイコロを振り...
[ { "submission_id": "aoj_2548_8860944", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\nconst int MAX_T = 3000, MAX_M = 300;\nint M, start, goal, dice[6];\nvector<int> N, path(MAX_M, MAX_T + 1), visit(MAX_M, false);\nbool isPositionValid(int p) { return 0 <= p && p < M; }\nvoid...
aoj_2549_cpp
F - 7歳教 7歳の誕生日に"彼"は父から告げられた. 「お前が7歳になったということは,私はもう引退だ.今日からお前が7歳教の長だ. 7歳教の戒律により,7歳教の長が7歳の間だけ布教活動を行うことが認められている. この宇宙船を使って,よりたくさんの人々に7歳教の素晴らしさを広めてきなさい.」 7歳教をよりたくさんの人に広めるために"彼"は,自分の周りの星についての情報を集めた. "彼"の星の周りには, n 個の惑星があり,惑星は 1, ... , n で番号付けされていることがわかった. 惑星 i から 惑星 j の間を移動するには, w_i_j (年)の時間がかかることもわかった. そして,それぞれの星で彼が7歳でいられる時...
[ { "submission_id": "aoj_2549_9212076", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=int64_t;\n\nint main(){\n int n,s;\n cin >> n >> s;\n s--;\n \n vector<pair<ll,ll>> lr(n);\n vector w(n,vector<ll>(n,0));\n ll l,r;\n for(int i=0;i<n;i++){\n cin >> l >> r;\n lr[i]=...
aoj_2543_cpp
Problem Statement You bought 3 ancient scrolls from a magician. These scrolls have a long string, and the lengths of the strings are the same. He said that these scrolls are copies of the key string to enter a dungeon with a secret treasure. However, he also said, they were copied so many times by hand, so the string w...
[ { "submission_id": "aoj_2543_10852592", "code_snippet": "#include <iostream>\n#include<cstdio>\n#include<cstring>\n#include<algorithm>\n#include<vector>\nusing namespace std;\nconst int maxn=100010;\nchar A[maxn],B[maxn],C[maxn],ans[maxn],temp[4];\nint t[maxn],can[3],n,d,type[5];\nbool check()\n{\n int n...
aoj_2547_cpp
D - カーペット 総合研究7号館の引越しに伴い,研究室にカーペットを敷くことになった. この問題では研究室を上から見たときの床を,二次元平面上の多角形とみなす. 床の形状を表す要素数 N の数列 \{a_i\} が与えられる. R_i を,左下の座標が (i,0) で右上の座標が (i+1,a_i) である各辺がx軸またはy軸に平行な長方形の境界及び内部領域とする. このとき,床を表す多角形は R_1 ∪ R_2 ∪ R_3 ∪ … ∪ R_N によって表される. カーペットは長方形であればどんな大きさのものを何枚でも用意することができる. 以下の条件を満たすようにカーペットを配置...
[ { "submission_id": "aoj_2547_9180691", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=int64_t;\n\nint main(){\n int n;\n cin >> n;\n if(n==1){\n cout << 1 << endl;\n return 0;\n }\n int cnt=0;\n int a,ca=0;\n stack<int> sk;\n for(int i=0;i<=n;i++){\n if(i<n) cin >...
aoj_2554_cpp
K - encode/decode 以下の2条件を全て満たす文字列Tの事を「良い」文字列と呼ぶことにする TはABCDEFGHIの9種類の文字列からなる T上の連続する2文字は次のグラフ上でも隣接している 「良い」文字列の例 BEB ABCDCBEFGHI 「良い」文字列ではない例 AC(AとCは隣接していない) AABCD(同じ文字はグラフ上では隣接していないとみなす) 以下の条件を満たすような2つの関数,encodeとdecodeを実装せよ. 任意の01列Sに対し,encode(S)は「良い」文字列である 任意の01列Sに対し,decode(encode(S))=Sを満たす 入出力形式 この問題にはencodeフェーズとdeco...
[ { "submission_id": "aoj_2554_9910749", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n map<string, pair<string, string>> edges = {\n {\"A1\", {\"B1\", \"B2\"}},\n {\"A2\", {\"B3\", \"B4\"}},\n {\"A3\", {\"B5\", \"B6\"}},\n\n {\"B1\", {\"A1\", \"A2\"}},\n {\"...
aoj_2557_cpp
C - Iyasugigappa Problem Statement Three animals Frog, Kappa (Water Imp) and Weasel are playing a card game. In this game, players make use of three kinds of items: a guillotine, twelve noble cards and six action cards. Some integer value is written on the face of each noble card and each action card. Before stating th...
[ { "submission_id": "aoj_2557_6021654", "code_snippet": "//#pragma GCC optimize(\"O3\")\n//#pragma GCC optimize(\"unroll-loops\")\n#include<iostream>\n#include<string>\n#include<cstdio>\n#include<vector>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<iomanip>\n#include<queue>\n#include...
aoj_2551_cpp
H - N and K 1以上 N 以下の整数からなる狭義単調増加数列で,数列の要素からどの2つの異なる数を取ってきても 他方が一方を割り切ることがないようなものを考える. そのような数列のうち,とりうる最大の長さを L として,そのような数列 (a_1,a_2,...,a_L) を考える. この数列の K 番目の要素 a_K を求めよ.ただし,そのような数列 (a_1...a_L) が複数個存在する場合は, a_K の値としてとりうる最小の値を出力せよ. また, K > L のときは-1を出力せよ. 入力形式 入力は複数の入力からなる.入力の数は C セットあり, i 番目の入力は N_i, K_i...
[ { "submission_id": "aoj_2551_3999815", "code_snippet": "#include <iostream>\n#include <vector>\n#include <array>\n#include <list>\n#include <string>\n#include <stack>\n#include <queue>\n#include <deque>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <tuple>\n#i...
aoj_2562_cpp
H - Rings Problem Statement There are two circles with radius 1 in 3D space. Please check two circles are connected as chained rings. Input The input is formatted as follows. {c_x}_1 {c_y}_1 {c_z}_1 {v_x}_{1,1} {v_y}_{1,1} {v_z}_{1,1} {v_x}_{1,2} {v_y}_{1,2} {v_z}_{1,2} {c_x}_2 {c_y}_2 {c_z}_2 {v_x}_{2,1} {v_y}_{2,1} {...
[ { "submission_id": "aoj_2562_7140176", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\n\nconst double eps = 1e-5;\nint sgn(double a){return a<-eps?-1:a>eps?1:0;}\nstruct point{\n double x,y,z;\n point() {}\n point(double x...
aoj_2555_cpp
A - Everlasting Zero Problem Statement You are very absorbed in a famous role-playing game (RPG), "Everlasting -Zero-". An RPG is a game in which players assume the roles of characters in a fictional setting. While you play the game, you can forget your "real life" and become a different person. To play the game more e...
[ { "submission_id": "aoj_2555_10052798", "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 all(A) A.begin(),A.end()\nconst ll mod = 1e9 + 7;\n\n\n\nint main() {\n\n cin.tie(nullptr);\n ios::sync_with_stdio(false);\n\n ...
aoj_2561_cpp
G - Revenge of Minimum Cost Flow Problem Statement Flora is a freelance carrier pigeon. Since she is an excellent pigeon, there are too much task requests to her. It is impossible to do all tasks, so she decided to outsource some tasks to Industrial Carrier Pigeon Company. There are N cities numbered from 0 to N-1 . Th...
[ { "submission_id": "aoj_2561_6167887", "code_snippet": "#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\n#include<iostream>\n#include<string>\n#include<cstdio>\n#include<vector>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<iomanip>\n#include<queue>\n#include<cis...
aoj_2556_cpp
B - Integer in Integer Problem Statement Given an integer interval \[A, B\] and an integer C , your job is to calculate the number of occurrences of C as string in the interval. For example, 33 appears in 333 twice, and appears in 334 once. Thus the number of occurrences of 33 in \[333, 334\] is 3 . Input The test case...
[ { "submission_id": "aoj_2556_10848373", "code_snippet": "#include <cstdio>\n#include <iostream>\n#include <cstring>\n#include <cstdlib>\n#include <algorithm>\n#include <vector>\n#include <set>\nusing namespace std;\n#define MOD 1000000007\n\nchar A[23333],B[23333],C[23333];\nint _10[23333];\n\nint cmp(char ...
aoj_2558_cpp
D - Medical Inspection Problem Statement The government has declared a state of emergency due to the MOFU syndrome epidemic in your country. Persons in the country suffer from MOFU syndrome and cannot get out of bed in the morning. You are a programmer working for the Department of Health. You have to take prompt meas...
[ { "submission_id": "aoj_2558_10867779", "code_snippet": "#include <map>\n#include <set>\n#include <cmath>\n#include <stack>\n#include <queue>\n#include <string>\n#include <vector>\n#include <bitset>\n#include <fstream>\n#include <sstream>\n#include <stdio.h>\n#include <ctype.h>\n#include <string.h>\n#includ...
aoj_2559_cpp
E - Minimum Spanning Tree Problem Statement You are given an undirected weighted graph G with n nodes and m edges. Each edge is numbered from 1 to m . Let G_i be an graph that is made by erasing i -th edge from G . Your task is to compute the cost of minimum spanning tree in G_i for each i . Input The dataset is format...
[ { "submission_id": "aoj_2559_10860451", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst ll INF = 1e18;\n\nstruct ed {\n ll a, b, w, id;\n};\n\nbool operator<(ed a, ed b) {\n return a.w < b.w;\n}\n\nvector<ll> p;\n\nll get(ll x) {\n if (p[x] == x) {\n ...
aoj_2563_cpp
I - The J-th Number Problem Statement You are given N empty arrays, t_1, ..., t_n . At first, you execute M queries as follows. add a value v to array t_i ( a \leq i \leq b ) Next, you process Q following output queries. output the j -th number of the sequence sorted all values in t_i ( x \leq i \leq y ) Input The data...
[ { "submission_id": "aoj_2563_10910516", "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_2565_cpp
Problem Statement Nathan O. Davis is a student at the department of integrated systems. Today's agenda in the class is audio signal processing. Nathan was given a lot of homework out. One of the homework was to write a program to process an audio signal. He copied the given audio signal to his USB memory and brought it...
[ { "submission_id": "aoj_2565_6065540", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n while(true) {\n int N;\n cin >> N;\n if(N == 0) {\n return 0;\n }\n vector<int>a(N);\n set<int>st1,st2;\n for(int i = 0; i <...
aoj_2564_cpp
J - Tree Reconstruction Problem Statement You have a directed graph. Some non-negative value is assigned on each edge of the graph. You know that the value of the graph satisfies the flow conservation law That is, for every node v , the sum of values on edges incoming to v equals to the sum of values of edges outgoing ...
[ { "submission_id": "aoj_2564_3210233", "code_snippet": "#include <bits/stdc++.h>\n\nconstexpr double eps = 1e-9;\n\nnamespace detail {\n bool is_zero(double x) {\n return std::fabs(x) < eps;\n }\n}\n\ntemplate <typename T>\nclass matrix {\npublic:\n matrix() : matrix(0, 0) {}\n matrix(int...
aoj_2567_cpp
Problem Statement You are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO. Since every SIRO restaurant has its own tasteful ramen, he wants to try them at as many different restaurants as possible in the night. He doesn't have pl...
[ { "submission_id": "aoj_2567_10848369", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cstdlib>\n#include <cmath>\n#include <algorithm>\n#include <queue>\n#include <map>\n#include <set>\n#include <vector>\n#include <string>\n#include <stack>\n#include <bitset>\n#defin...
aoj_2560_cpp
F - Point Distance Problem Statement You work for invention center as a part time programmer. This center researches movement of protein molecules. It needs how molecules make clusters, so it will calculate distance of all pair molecules and will make a histogram. Molecules’ positions are given by a N x N grid map. Val...
[ { "submission_id": "aoj_2560_10853952", "code_snippet": "//sagitta\n#include <bits/stdc++.h>\nusing namespace std;\nconst int N=1<<23,M=1<<10;\nconst double pi=acos(-1);\ntypedef complex <double> E;\nint mp[M][M];\nint n,m,L;\nint R[N];\nlong long cnt[N];\nE a[N],b[N];\nint sum;\ndouble ans;\nvoid fft(E *A,...
aoj_2566_cpp
Problem Statement The Animal School is a primary school for animal children. You are a fox attending this school. One day, you are given a problem called "Arithmetical Restorations" from the rabbit teacher, Hanako. Arithmetical Restorations are the problems like the following: You are given three positive integers, $A$...
[ { "submission_id": "aoj_2566_6553036", "code_snippet": "#include<bits/stdc++.h>\n#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)\n#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);-...
aoj_2569_cpp
Problem Statement Fox Ciel is practicing miniature golf, a golf game played with a putter club only. For improving golf skills, she believes it is important how well she bounces the ball against walls. The field of miniature golf is in a two-dimensional plane and surrounded by $N$ walls forming a convex polygon. At fir...
[ { "submission_id": "aoj_2569_10852740", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cstdlib>\n#include <cmath>\n#include <algorithm>\n#include <queue>\n#include <map>\n#include <set>\n#include <vector>\n#include <string>\n#include <stack>\n#include <bitset>\n#defin...
aoj_2568_cpp
Problem Statement "Everlasting -One-" is an award-winning online game launched this year. This game has rapidly become famous for its large number of characters you can play. In this game, a character is characterized by attributes . There are $N$ attributes in this game, numbered $1$ through $N$. Each attribute takes ...
[ { "submission_id": "aoj_2568_10850485", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstring>\n#include <cstdlib>\n#include <cmath>\n#include <algorithm>\n#include <queue>\n#include <map>\n#include <set>\n#include <vector>\n#include <string>\n#include <stack>\n#include <bitset>\n#defin...
aoj_2570_cpp
Problem Statement Dr. Suposupo developed a programming language called Shipura. Shipura supports only one binary operator ${\tt >>}$ and only one unary function ${\tt S<\ >}$. $x {\tt >>} y$ is evaluated to $\lfloor x / 2^y \rfloor$ (that is, the greatest integer not exceeding $x / 2^y$), and ${\tt S<} x {\tt >}$ is ev...
[ { "submission_id": "aoj_2570_10848954", "code_snippet": "#pragma comment(linker, \"/STACK:1024000000,1024000000\")\n#include <algorithm>\n#include <cstdio>\n#include <cstring>\n#include <cmath>\n#include <cstdlib>\n#include <cctype>\n#include <vector>\n#include <set>\n#include <map>\n#include <queue>\n#incl...