group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_2572_cpp
Problem Statement Alice is a private teacher. One of her job is to prepare the learning materials for her student. Now, as part of the materials, she is drawing a Venn diagram between two sets $A$ and $B$. Venn diagram is a diagram which illustrates the relationships among one or more sets. For example, a Venn diagram ...
[ { "submission_id": "aoj_2572_4132853", "code_snippet": "#include<iostream>\n#include<string>\n#include<cstdio>\n#include<vector>\n#include<cmath>\n#include<algorithm>\n#include<functional>\n#include<iomanip>\n#include<queue>\n#include<ciso646>\n#include<random>\n#include<map>\n#include<set>\n#include<bitset...
aoj_2575_cpp
A - D's Ambition / Dのやぼう Story あいずにゃんは若ヶ松高校のプログラミングコンテスト部、通称ぷろこん部に所属する2年生である。かわいい。Dのひとは天使のごとくかわいいあいずにゃんにぞっこんであり、隙あらばぺろぺろしようと画策する変態である。その愛は猟奇的であり、あいずにゃんを自分色に染めようと、"AIZUNYAN"という文字列を見る度"AIDUNYAN"に書き換えてしまう。さらにあいずにゃんを自分だけのものにするため、他の人に気づかれないようにその文字列をバラバラに並べ替えてしまう。プロコンの名門・律命館大学中等部卒のエリート競技プログラマであり、ぷろこん部の部長であるりっつちゃんは、あいずにゃんをDのひ...
[ { "submission_id": "aoj_2575_1762221", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nint main()\n{\n string D;\n string S = \"AIDUNYAN\";\n string R = \"AIZUNYAN\";\n int len;\n cin >> D;\n len = D.size();\n D += \"*****\";\n sort(S.begin(), S.end());\n string ans = D;\n do{...
aoj_2577_cpp
C - Dowsing Machine / ダウジングマシーン Story 世間ではXだとかYだとかで騒がしいけれど、これからの時代は"D"である。"パクリンモンスターD"は、秘密結社"R団"によって開発された"Dマシン"を使って"Dのひと"が財宝探索を行う大人気ゲームである。 このゲームでは、格子状マップのあるマスにいるDのひとが、隣接する上下左右のマスへの移動を繰り返し、財宝が存在するマスへの到達を目指す。 マップ上には財宝が存在するマスが1つだけある。 財宝が存在するマスは明らかにされていないため、Dマシンを使って存在する財宝のマスを絞り込んでから、財宝が存在するマスへ移動したい。 Dマシンを使うと、財宝が存在するマスを含む複...
[ { "submission_id": "aoj_2577_2427084", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define fr first\n#define sc second\n#define pb push_back\n\ntypedef pair<int, int> Pii;\n\nint h, w, d, n;\nchar mp[51][51];\nint r[11];\nint data[51][51] = {{0}};\nint sx, sy;\nint dx[4] = {0, 1, 0,...
aoj_2571_cpp
Problem Statement You have just arrived in a small country. Unfortunately a huge hurricane swept across the country a few days ago. The country is made up of $n$ islands, numbered $1$ through $n$. Many bridges connected the islands, but all the bridges were washed away by a flood. People in the islands need new bridges...
[ { "submission_id": "aoj_2571_10311406", "code_snippet": "// AOJ #2571 Floating Islands\n// 2025.3.19\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 10000000000000000LL;\nconst int MAXN = 4005;\n\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n\n whi...
aoj_2576_cpp
B - Doctor Course Is Recommended / D進どうですか? Story DのひとはD進を決意したので、博士後期課程入学試験を受けることにした。筆記試験はマークシート形式であった。自身の専門分野の問題ばかりだったので、Dのひとはすぐにすべての正答を導くことができた。しかし、ここで大きな問題に気づいた。Dのひとは宗教上の理由から、解答用紙には'D'としか書くことができなかったのだ。また、'D'と書くためには尋常ではない集中力を使うため,'D'と書くことのできる個数も決まっている。Dのひとが本当にD進することができるか調べるため、解答・配点を踏まえ、上記の条件を満たした上で得られる最大の得点を求めてみよう。 P...
[ { "submission_id": "aoj_2576_3712404", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef pair<int, int> P;\n\nint main(){\n int d; cin>>d;\n int x; cin>>x;\n vector<P> score;\n for(int i=0; i<x; i++){\n char a; cin>>a;\n int p; cin>>p;\n if(a == 'D')...
aoj_2578_cpp
D - Disciple Life is Hard / 弟子はつらいよ Story Dのひとはドーナツを愛してやまない。常にドーナツを欲している。しかし、師匠であるぶなしめじたんに体を鍛えることを命じられたDのひとは、摂取カロリーを制限しなければならない。そこでDのひとは基礎代謝も考慮し、その日トレーニングによって消費したカロリーの分までドーナツを食べてもよいことにした。Dのひとはドーナツを愛してやまないとはいえ、好みはあるので、食べるドーナツによって得られる幸福感は変わる。また、その日の体力によって行えるトレーニングも変わってくるため、トレーニングの種類、ドーナツの種類、体力を考慮し、 D 日間で得られる幸福を最大化することを試み...
[ { "submission_id": "aoj_2578_7836487", "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_2573_cpp
Problem Statement You have a rectangular board with square cells arranged in $H$ rows and $W$ columns. The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right. The cell at the row $i$ and the column $j$ is denoted by $(i, j)$. Each cell on the board is...
[ { "submission_id": "aoj_2573_10848433", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cmath>\n#include<algorithm>\n#include<cstring>\n#include<map>\nusing namespace std;\nconst long double eps=1e-8;\nstruct state\n{\n\tint a[7];\n} ss[10000];\nstruct ones\n{\n\tint a[6][6];\n}Target,ini;\n...
aoj_2574_cpp
Problem Statement You are given a rectangular board divided into square cells. The number of rows and columns in this board are $3$ and $3 M + 1$, respectively, where $M$ is a positive integer. The rows are numbered $1$ through $3$ from top to bottom, and the columns are numbered $1$ through $3 M + 1$ from left to righ...
[ { "submission_id": "aoj_2574_8404412", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint T;\nint N;\nint dp1[1594323];\nint dp2[1594323];\nbool C[26][26][26][8];\nchar E[3][1 << 19];\n\nbool check(int num, int cl, int cr) {\n for (int i = cl; i < cr; i++) {\n for (int j = i; j...
aoj_2581_cpp
G - Derangement / 完全順列 Story Dのひとは順列に関する研究をしている。あるときDのひとは、"完全順列 (Derangement)"という順列のクラスを見つけた。「完全な順列とかなんかかっこいい!!!しかもDからはじまる!!!」と廚二病をこじらせたDのひとは、与えられた順列をすべて完全順列に書き換えてしまおうと考えた。 Problem 長さ n の順列 p = (p_1 p_2 ... p_n) が与えられる。 i 番目の要素と j 番目の要素を入れ替える操作には (p_i+p_j) \times |i-j| のコストを要する。このとき、上記の入れ替え操作のみを用いて p を完全順列にするために必要な最小のコ...
[ { "submission_id": "aoj_2581_10867719", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ll = long long int;\nusing ull = unsigned long long int;\nusing P = pair<int, int>;\nusing P3 = pair<int,P>;\nusing PP = pair<P, P>;\nconstexpr int INF = 1 << 29;\nconstexpr ll MOD = ll(1e9+7);\n...
aoj_2584_cpp
壊れた暗号生成器 JAG (Japanese Alumni Group) は多くのプログラマで構成される謎の組織であり,この組織の本部がある建物に入るためには毎回ある機械によって生成される暗号文を解かなくてはならない. この暗号文は,' + ',' - ',' [ ',' ] ' の記号と大文字のアルファベットからなっており,以下の BNF で定義される <Cipher> によって表される. <Cipher> ::= <String> | <Cipher><String> <String> ::= <Letter> | '['<Cipher>']' <Letter> ::= '+'<Letter> | '-'<Letter> | ...
[ { "submission_id": "aoj_2584_10852671", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define int long long\n\nchar pls(char c) {\n return c == 'Z' ? 'A' : c + 1;\n}\nchar mns(char c) {\n return c == 'A' ? 'Z' : c - 1;\n}\nusing Pt = string::const_iterator;\nstring expr1(string& s, Pt& ...
aoj_2583_cpp
JAG-channel ネイサン・O・デイビスはJAG-channelという電子掲示板を運営している. 彼は現在,スレッドビューという新機能の追加に取り組んでいる. 他の多くの電子掲示板と同じように,JAG-channelはスレッドベースである. ここで,スレッドとは,一連の投稿からなる一つの会話のまとまりを指す. 投稿には,以下の2種類が存在する. 新しいスレッドを作る最初の投稿 すでにあるスレッドの過去の投稿への返信 スレッドビューは,投稿間の返信・被返信関係による論理的な構造を表す,ツリー状のビューである. それぞれの投稿はツリーのノードとなり,その投稿に対する返信を子ノードとして持つ. ある投稿に対する直接・間接の返信が,全...
[ { "submission_id": "aoj_2583_10853886", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main()\n{\n\tint n;\n\twhile (cin >> n, n) {\n\t\tvector<string> s(n), res(n);\n\t\tvector<int> cnt(n);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcin >> s[i];\n\t\t\tfor (auto c : s[i]) {\n\t\t\t\t...
aoj_2580_cpp
F - Dangerous Delivery / 危険な輸送 Story Dのひとは重大な使命を背負っていた。それはDAtaCoDer社長のDhokudai氏へ、次のDAtaCoDer Regular Contest(DARC)のD問題を届けることだ。Dのひとのアジトがある都市 1 からDAtaCoDer本社がある都市 N までは N 個の都市が一直線に並んでいる。この移動の間、不正を企む緑の三角形の集団がD問題を狙っており、その魔の手からD問題を守らねばならない。 幸い、Dのひとは次元(ディメンジョン)の壁を超えて移動する能力を持っているため、簡単に捕まるようなことはない。しかしこの移動法にはいくつかの欠点がある。第一に、移動を開...
[ { "submission_id": "aoj_2580_10848628", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing VS = vector<string>; using LL = long long;\nusing VI = vector<int>; using VVI = vector<VI>;\nusing PII = pair<int, int>; using PLL = pair<LL, LL>;\nusing VL = vector<LL>; using ...
aoj_2585_cpp
一日乗車券 某国に住む大学生D氏は,国民的ギタリストA氏の大ファンで,この夏都心で行われるライブに行こうと考えている. しかし,D氏は辺境の地に住んでいるため,交通費がかかることがとても不安だった. そんなとき彼は,JAGという組織から安価で販売されている「1Dayパスポート」の存在を知った. JAG (Journey Administrative Group) は,D氏が住む国に存在するいくつかの鉄道会社を統括する組織である. JAGは,全国に複数の駅を持ち,それらの間を結ぶ路線を整備している. 各路線は,JAGに所属する会社の内いずれか1社により管理されており,2駅間を途中駅無しで双方向に結んでいる. また各路線には,利用する際...
[ { "submission_id": "aoj_2585_10854055", "code_snippet": "#include <queue>\n#include <vector>\n#include <iostream>\n#include <algorithm>\nusing namespace std;\n#ifdef _WIN32\n#define __builtin_popcount __popcnt\n#endif\n// Time Complexity: O(3^P + 2^P * H * M log N)\nint N, M, H, K, S, T, P, a, b, c, h, r;\n...
aoj_2587_cpp
エレベーターホール・ナンバー JAG (Japanese Alumni Group) は東京都某所のとある高層ビルに本部を置く謎の組織である. このビルでは $N$ 台のエレベーターが動いており,$i$ 台目のエレベーターは $low_i$ 階から $high_i$ 階までの各階に停まる ($1 \le i \le N$). JAG の新スタッフである X 氏は,本部を訪れようとビルのエレベーターホールまで辿り着いた. そこでボタンを押してエレベーターを待っていた X 氏は,エレベーターが現在いる階の表示が少々変わっていることに気づいた. $i$ 台目のエレベーターが $a_i$ 階にいるとき,$a_1, a_2, \ldots, ...
[ { "submission_id": "aoj_2587_8283358", "code_snippet": "#include <iostream>\n#include <map>\n#include <vector>\n#include <string>\n#include <algorithm>\nusing namespace std;\n\nint N;\nint L[10], R[10];\nvector<vector<int>> Data[200009];\nmap<vector<vector<int>>, int> Map;\nint pows[9] = { 1, 10, 100, 1000,...
aoj_2586_cpp
流れ星に願いを 謎の組織 JAG (Japanese Alumni Group) では定期的に会議を開いている.ある日の議題は「近日行われる ICPC (International Collegiate Programming Contest) 国内予選で参加チームが力を発揮できるようにするには」であった.会議の結論として流れ星に各チームの健闘を祈ることになり,彼らは本部を置く建物の屋上に出た. 彼らが屋上に出ると,空には $n$ 個の流れ星が見えていた.流れ星は3次元空間上の球として表され,$1$ から $n$ の番号が割り振られている.星に詳しいメンバーにより,各流れ星は一定の速度で直線的に移動すると同時に,一定の速度で半径が小...
[ { "submission_id": "aoj_2586_10853194", "code_snippet": "#include<iostream>\n#include<vector>\n#include<iomanip>\n#include<cmath>\n#include<algorithm>\n\nusing namespace std;\nusing P = pair<double, pair<int, int> >;\n\ndouble p[200][3];\ndouble v[200][3];\ndouble r[200];\ndouble rv[200];\ndouble life[200];...
aoj_2592_cpp
Problem Statement We have planted $N$ flower seeds, all of which come into different flowers. We want to make all the flowers come out together. Each plant has a value called vitality, which is initially zero. Watering and spreading fertilizers cause changes on it, and the $i$-th plant will come into flower if its vita...
[ { "submission_id": "aoj_2592_10946058", "code_snippet": "#include<iostream>\n#include<stdio.h>\n#include<string.h>\n#include<algorithm>\n#include<math.h>\nusing namespace std;\n#define ll __int64\n#define eps 1e-10\nint sig(double x)\n{\n return (x>eps)-(x<-eps);\n}\nconst int N=1e5+10;\nint pw,vw[N],pf[...
aoj_2590_cpp
Problem Statement In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bu...
[ { "submission_id": "aoj_2590_11023192", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<ll, 2>;\nusing a3 = array<ll, 3>;\n\nbool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }\nbool chmax(auto& a, const auto& b) { return a < b ? a = b...
aoj_2593_cpp
Problem Statement Circles Island is known for its mysterious shape: it is a completely flat island with its shape being a union of circles whose centers are on the $x$-axis and their inside regions. The King of Circles Island plans to build a large square on Circles Island in order to celebrate the fiftieth anniversary...
[ { "submission_id": "aoj_2593_10851582", "code_snippet": "#include<bits/stdc++.h>\n#define N 55555\n#define M 133333\n#define eps 1e-8\nusing namespace std;\nint n,i,ll,rr;double an,l,r,md,xx,yy,X[N],R[N],XX[N],YY[N],V[M];\ndouble sqr(double x){return x*x;}\nvoid bd(int k,int l,int r){\n\tif(l==r){\n\t\tV[k]...
aoj_2597_cpp
Problem Statement You have just transferred to another world, and got a map of this world. There are several countries in this world. Each country has a connected territory, which is drawn on the map as a simple polygon consisting of its border segments in the $2$-dimensional plane. You are strange to this world, so yo...
[ { "submission_id": "aoj_2597_10053672", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing ll=long long;\n#define rep(i,n) for(int i=0;i<n;i++)\n\nstruct point{\n ll x,y;\n};\n\nbool is_adj(point p1,point p2,point p3,point p4){\n if((p2.y-p1.y)*(p4.x-p3.x)!=(p2.x-p1.x)*(p4.y-p3.y)...
aoj_2595_cpp
Problem Statement One day, my grandmas left $N$ cookies. My elder sister and I were going to eat them immediately, but there was the instruction. It said Cookies will go bad; you should eat all of them within $D$ days. Be careful about overeating; you should eat strictly less than $X$ cookies in a day. My sister said "...
[ { "submission_id": "aoj_2595_10849177", "code_snippet": "#include<cstdio>\n#include<iostream>\n#include<cstring>\nusing namespace std;\ntypedef long long ll;\nconst int mod=1e9+7;\nconst int N=2000+100;\nll pow_m(ll n,ll k)\n{\n ll ans=1;\n while(k)\n {\n if(k&1) ans=ans*n%mod;\n n=n*...
aoj_2598_cpp
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move betw...
[ { "submission_id": "aoj_2598_10946056", "code_snippet": "#pragma comment(linker, \"/STACK:102400000,102400000\")\n#include<cstdio>\n#include<ctype.h>\n#include<algorithm>\n#include<iostream>\n#include<cstring>\n#include<vector>\n#include<cstdlib>\n#include<stack>\n#include<queue>\n#include<set>\n#include<ma...
aoj_2594_cpp
Problem Statement JAG Kingdom is a strange kingdom such that its $N$ cities are connected only by one-way roads. The $N$ cities are numbered $1$ through $N$. ICPC (International Characteristic Product Corporation) transports its products from the factory at the city $S$ to the storehouse at the city $T$ in JAG Kingdom ...
[ { "submission_id": "aoj_2594_10848626", "code_snippet": "#include <bits/stdc++.h>\n\n#define fst first\n#define snd second\n#define ALL(a) a.begin(), a.end()\n#define clr(a, x) memset(a, x, sizeof a)\n#define rep(i,x) for(int i=0;i<(int)x;i++)\n#define rep1(i,x,y) for(int i=x;i<=(int)y;i++)\n\nusing namespa...
aoj_2591_cpp
Problem Statement Infinite Chronicle -Princess Castle- is a simple role-playing game. There are $n + 1$ checkpoints, numbered $0$ through $n$, and for each $i = 1, 2, \ldots, n$, there is a unique one-way road running from checkpoint $i - 1$ to $i$. The game starts at checkpoint $0$ and ends at checkpoint $n$. Evil...
[ { "submission_id": "aoj_2591_10852915", "code_snippet": "#include<iostream>\n#include<cstdio>\n#include<cstring>\n#include<algorithm>\nusing namespace std;\nconst int N=100010;\ndouble p[N],dp[N],sum[N];\nint main()\n{\n int n;\n while(scanf(\"%d\",&n)!=EOF&&n)\n {\n for(int i=1;i<=n;i++) {\...
aoj_2599_cpp
Problem Statement Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.) " Filtering " is an operation to determine the color of ...
[ { "submission_id": "aoj_2599_10852900", "code_snippet": "#include <iostream>\n#include<cstring>\n#include<cstdio>\n#include<algorithm>\n#include<vector>\nusing namespace std;\nchar buf[200];\nint Make(int a,int b,int c,int d,int e,int f,int g)\n{\n return g*64+f*32+e*16+d*8+c*4+b*2+a;\n}\nint s[22];\nboo...
aoj_2602_cpp
問題 C : Apples 問題文 あるところに銃の腕に自信をもつ猟師がいました. 猟師はある日,「ウィリアムテルというスイス人が,息子の頭にりんごを乗せて遠くから矢で撃ち落とすパフォーマンスで有名になった」というお話を聞きました. それを聞いて"自分のほうがもっと凄い!!"と思った猟師は動いている人の上にりんごを乗せて撃ちぬくパフォーマンスを考えつきました. 猟師は広場に N 人の人を集め,それぞれの人の上にりんごを乗せました. i 番目の人は時刻 t=0 のとき,座標 (x_i,  y_i) にいます. そこから単位時間あたり速度ベクトル (u_i,  v_i) にしたがって歩きます. すなわち,時刻 t  ≥  0 のとき, ...
[ { "submission_id": "aoj_2602_9096982", "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_2600_cpp
問題 A : Koto Distance 問題文 Koto は言わずと知れた碁盤の目の街である. この街は東西方向に W メートル,南北方向に H メートルに伸びる長方形の領域によってできている. この街の西端から x メートル,南端から y メートルの点は (x,  y) と記される. ここの街に住む人は古くから伝わる独自の文化を重んじており,その一つにKoto距離という変わった距離尺度がある. 2つの点 (x_1, y_1) , (x_2, y_2) の Koto 距離は,min (|x_1 - x_2|,  |y_1 - y_2|) によって定義される. 最近この街全体に Wifi を使えるようにする計画が立ち上がった....
[ { "submission_id": "aoj_2600_11039101", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<ll, 2>;\nusing a3 = array<ll, 3>;\n\nbool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }\nbool chmax(auto& a, const auto& b) { return a < b ? a = b...
aoj_2601_cpp
問題 B : Evacuation Route 問題文 日本では防災研究が盛んに行われており,近年その重要性がますます増している. 避難経路の評価も重要な研究のひとつである. 今回は直線状の通路の安全評価を行う. 通路は W 個のユニットに分けられており,一方の端のユニットからもう一方の端のユニットまで 0,  1,  2,  … ,  W-1 の番号がつけられている. 通路内の各ユニットには,入口の扉,出口の扉,防火扉のいずれか1つが存在する. 入り口の扉,出口の扉,防火扉はそれぞれ通路内に複数個存在しうる. この問題では時刻 t=0 で火災が発生したと想定する. それにより,通路の外部にいて避難しようとしている人々が入口の扉を通...
[ { "submission_id": "aoj_2601_10283386", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)\n#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)\n#define ...
aoj_2603_cpp
問題 D : TiMe Table 問題文 ある学生は朝にいつも乗る通学バスで,あることに気がついた. そのバスの利用者がいつも同じなのだ. 気になってバスに乗っている利用者たちに聞いてみると,毎日決まった時刻にバス停に来ているようである. それなら,乗客にとってもっとよいバスの時間割があるのではないかとその学生は考えた. 学生の乗る通学路には,バスの営業所から終点までに s 個のバス停が一直線に並んでいる.(営業所はバス停には含まれないが,終点はバス停に含まれる.) 各バス停には,営業所から近い方から順に 1 から s までの番号が付けられている. 営業所と i 番目のバス停の距離は x_i である. バスはまず営業所を出発し,そ...
[ { "submission_id": "aoj_2603_9680245", "code_snippet": "// QCFium 法\n#pragma GCC target(\"avx2\")\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\n\n\n#ifndef HIDDEN_IN_VS // 折りたたみ用\n\n// 警告の抑制\n#define _CRT_SECURE_NO_WARNINGS\n\n// ライブラリの読み込み\n#include <bits/stdc++.h>\nusing namespace...
aoj_2605_cpp
問題 F : Social Monsters 問題文 不思議な生き物と人間が互いに助け合って生きている世界. この世界では自分で捕まえたモンスター同士を戦わせる大会が盛んに行われており, 多くの少年少女達が世界一のトレーナーを目指している. バトルでは自分が捕まえたモンスターからパーティを作り,パーティ同士の対戦となる. モンスターのペアには相性があり,相性が非常に悪い場合と普通の場合がある. 相性が非常に悪い場合,そのペアのモンスターを同じパーティに入れることはできない. 相性が普通の場合には, 友情度 という数値で相性の良さが表現される. バトルでは,パーティ全体の友情度の和が勝負の鍵となる. いま N ...
[ { "submission_id": "aoj_2605_10506813", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define all(v) (v).begin(),(v).end()\n#define pb(a) push_back(a)\n#define rep(i, n) for(int i=0;i<n;i++)\n#define foa(e, v) for(auto&& e : v)\nusing ll = long long;\nconst ll MOD7 = 1000000007, MOD998 = ...
aoj_2607_cpp
長年の研究の末、イクタ君は未来予知能力を手に入れた! 彼がこの研究に費やした時間や金銭は莫大なものであったが、ついに報われる時がやってきたのだ。手始めに金銭を取り戻すため、イクタ君は株式投資を始めることにした。 イクタ君は現在株式は全く保有しておらず、 x 円を所持している。彼が投資対象に定めた株式は n 種類で、それらについて今日から d 日分の株価を予知することに成功した。その結果、驚くべきことに今日から d 日間は日中の株価変動が全くないことが判明した。つまり、今日を1日目としたときの i ( 1 ≤ i ≤ d )日目の株式 j ( 1 ≤ j ≤ n )の株価 p i,j 円がわかっている。イクタ君はそれぞれの日に自由に株...
[ { "submission_id": "aoj_2607_9595625", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)...
aoj_2604_cpp
問題 E : Pattern Language 問題文 m 個の相異なるアルファベット var_0,  var_1,   … ,  var_{m-1} がある. 0,   1,   … ,   9,   var_0,   var_1,   … ,   var_{m-1} の 10+m 種類の文字からなる,長さ N の文字列 s_0s_1s_2…s_{N-1} が与えられる. この文字列における各アルファベットを数字で置き換えて回文になるようにしたい.(回文とは,前から読んでも後ろから読んでも同じ文字列をあらわす.) ここで,同じアルファベットは同じ数字で置き換えなければならない.また与えられたすべてのアルファベット var_i は少...
[ { "submission_id": "aoj_2604_10251246", "code_snippet": "// AOJ #2604 Pattern Language\n// 2025.2.27\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll MOD = 1000000007;\n\nstruct UF {\n vector<int> parent;\n vector<int> fixedVal;\n vector<bool> nonzero;\n UF(int ...
aoj_2606_cpp
問題 G : Perm Query 問題文 \{1,  2,  … ,  N\} の順列 (p(1),  p(2),  … ,  p(n)) が与えられる. (l_i,  r_i) からなるクエリが Q 個与えられるので,各クエリに対して以下の擬似コードによる処理結果を出力せよ. ret   :=   0 , (x(1),  x(2),  … ,  x(N))  :=  (1,  2,  … ,  N) とおく. 各 i   ∈ \{1,   2,  … ,   N\} について y(i) := p(x(i)) とする. 各 i   ∈ \{1,   2,  … ,   N\} について x(i)   =  y(i) とする. re...
[ { "submission_id": "aoj_2606_10848569", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing VS = vector<string>; using LL = long long;\nusing VI = vector<int>; using VVI = vector<VI>;\nusing PII = pair<int, int>; using PLL = pair<LL, LL>;\nusing VL = vector<LL>; using ...
aoj_2609_cpp
勇猛果敢なイクタ君はついに悪名高きビッグブリッジ伯爵を追い詰めた! 今やビッグブリッジ伯爵は幅 w メートル、奥行き h メートルの長方形の部屋に閉じ込められており、最期を待つばかりとなっている。 部屋のある角を選び、幅方向を x 軸、奥行き方向を y 軸に、それぞれ部屋の内部が正の方向になるように座標系をとると、ビッグブリッジ伯爵は点 (p, q) にいる。点 (x, y) にイクタ君の最終兵器である衝撃波発射装置があり、ここから秒速 v メートルの衝撃波を全方向に出す。この衝撃波は t 秒間有効であり、部屋の壁面で反射する。 部屋の外にいるイクタ君はビッグブリッジ伯爵がどれだけ苦しむか知りたがっているので、ビッグブリッジ伯爵に衝...
[ { "submission_id": "aoj_2609_9741860", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)...
aoj_2613_cpp
小学生のイクタ君は、ある日おじいさんから数式が書かれた紙をもらった。 どうやらおじいさんは数式の答えの金額だけお小遣いをくれるらしい。 イクタ君はまだ足し算、引き算、掛け算しか習ってなかったので、数式にも足し算と引き算と掛け算しか使われていない。 通常の計算では足し算と引き算より掛け算を先に計算しなければならないのだが、イクタ君は演算子の優先順位についての理解があやふやだったので、とりあえず数式の計算結果が最大になるような都合の良い優先順位を考えることにした。 +−× の3つの二項演算子と括弧を含む数式が与えられる。 3つの演算子の優先順位を任意に変更して、数式を最大化したときの計算結果を答えよ。 ただし、以下の点に注意せよ。 演算...
[ { "submission_id": "aoj_2613_6995882", "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 < (ll) (n); i++)\n\nstring S;\nvector<char> P = { '+','-','*' };\nvector<set<char>> t(3);\nll ...
aoj_2612_cpp
負けず嫌いのイクタ君は、最近囲碁盤を使って遊ぶゲームに熱中している。 しかし、囲碁も五目並べも友人に全く勝てないので、あまり有名でない Phutball というゲームの特訓をすることにした。 このゲームは難しいゲームなので、手始めに自分のターンに勝って終局できるかを判定できるように特訓することにした。 ゲームの勝利条件は以下のようなものである。 白石は黒石の置かれている場所にジャンプすることは出来ない。 碁盤の中央の 19 × 15 の部分を用いる。 勝利条件を判定したい碁盤は白石が1つと黒石がいくつか置かれた状態で与えられる。 ゴール地点というのは碁盤の下端か、その下側を指す。(下図を参照せよ。) ゴール地点に白石を運べば勝利する...
[ { "submission_id": "aoj_2612_4949907", "code_snippet": "#include <algorithm>\n#include <bitset>\n#include <complex>\n#include <deque>\n#include <exception>\n#include <fstream>\n#include <functional>\n#include <iomanip>\n#include <ios>\n#include <iosfwd>\n#include <iostream>\n#include <istream>\n#include <it...
aoj_2608_cpp
イクタ君は、無向グラフについて異常なほどの思い入れを持っている。イクタ君は、無向グラフ G とその 2 点 s,t の組 (G,s,t) のうち、その「うつくしさ」が大きいものが好きである。 組 (G,s,t) の「うつくしさ」とは、辺 e = \{u, v\} ( u と v は G の異なる 2 点) で、 G における s から t への最短路の長さが、 G に e をつけくわえた無向グラフにおける s から t への最短路の長さより 1 だけ大きいものの個数である。 あなたの仕事は、組 (G,s,t) が与えられたとき、その「うつくしさ」を求めるプログラムを書くことである。 Input 入力は以下の形式で与えられる。 N M...
[ { "submission_id": "aoj_2608_10913681", "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_2611_cpp
イクタ君の住む町には N 個の塔がある。 それぞれの塔には0から N−1 までの異なる番号が与えられており、番号 i の塔を塔 i と呼ぶ。 好奇心旺盛なイクタ君は N 個の塔の高さに興味を持ち、それらの大小関係を表す表 T を作ることにした。 T は N × N 個の要素を持ち、各要素 T i, j (0 ≤ i, j ≤ N − 1) は次のように定義される。 T i, j = −1 ⇔ 塔 i の高さが塔 j の高さより小さい T i, j = 0 ⇔ 塔 i の高さと塔 j の高さが等しい T i, j = 1 ⇔ 塔 i の高さが塔 j の高さより大きい イクタ君は表 T を作成するための調査として、2つの塔を選びそれ...
[ { "submission_id": "aoj_2611_10210617", "code_snippet": "// AOJ #2611\n// Ordering 2025.2.11\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst ll MOD = 1000000007;\n \nint N;\nvector<vector<int>> children;\n \nvector<ll> dfsDP(int u, int m) {\n if(children[u].empty()){\n ...
aoj_2615_cpp
プログラミングコンテストの合宿で出す問題のアイディアが出ずに困っていたイクタ君は、ある日友人に相談した。 イクタ君「こういうアルゴリズムを使わないと解けないような問題が出したいんですけど、なにかありませんかね?」 友人「それではこういうものを考えたらいいんじゃないですか」 このようにしてその友人は以下のような問題の原案となるアイデアを考えてくれた。 2進数 A,B が与えられた時、以下の様なクエリを処理せよ。 出力クエリ: max{ x を2進数で表したときの、1の数 | A ≤ x < A+B }を出力 A変更クエリ: A の最下位ビットから i ビット目(0-origin)を反転 B変更クエリ: B の最下位ビットから i ビッ...
[ { "submission_id": "aoj_2615_10760388", "code_snippet": "#include<iostream>\n#include<string>\n#include<algorithm>\nusing namespace std;\n\n#define MAX_N 500000\nstring A, B;\nint n, c, d, e, sum;\nint a[MAX_N], b[MAX_N], ab[MAX_N];\nchar f[MAX_N];\n\nint main() {\n\tcin >> n;\n\tcin >> A >> B;\n\td = max(A...
aoj_2614_cpp
不運なイクタ君は持っていた大事な文字列 T をウィルスによって異なる文字列 T' に書き換えられてしまった。そのウィルスが T の1文字を異なる文字に書き換えてしまったことがわかっている。すなわち T と T' はちょうど1文字のみ異なっている。イクタ君は T を復元するために、 T が出現していると思われる文書 S を用意した。 T を復元するための下準備として S の部分文字列で T と一致している可能性があるものの個数を調べたい。 文字列 T' と文書 S が与えられる。 S = a 1 a 2 a 3 . . . a |S| の長さ |T'| の部分文字列 a k a k+1 . . . a k+|T'|−1 (1 ≤ k ...
[ { "submission_id": "aoj_2614_10852972", "code_snippet": "#include \"bits/stdc++.h\"\nusing namespace std;\n\nusing ll = int;\nusing ha = pair<ll, ll>;\nstruct RollingHash {\n\tstatic const ll mul0 = 10009, mul1 = 10007;\n\tstatic const ll add0 = 1000010007, add1 = 1003333331;\n\tsize_t len;\n\t//vector<ll>...
aoj_2616_cpp
ヘリリンは二次元平面上における長さ 2L の線分の形状をしている。 ヘリリンのまわりには、線分の形状をしたいくつかの障害物が存在している。 ヘリリンは障害物に接すると体力が削られてしまう。 完璧主義のヘリリンは無傷でゴールすることにした。 ヘリリンは以下の行動ができる。 平行移動 ヘリリンを表す線分の中点を中心として、反時計周りにちょうど 180 / r 度だけ回転する ただし、二次元平面は上方向に y 軸をとる。 ヘリリンのまわりに、2 点 S, G がある。 始めはヘリリンの中心は点 S にあって、 x 軸に平行な状態になっている。 ヘリリンは、平行移動するのは得意だが、回転するのは不得意である。 あなたの仕事は、ヘリリンが中心...
[ { "submission_id": "aoj_2616_10329392", "code_snippet": "// AOJ #2616 KuruKuruKururin\n// 2025.3.27\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ld = long double;\n\nconst ld EPS = 1e-8;\nconst ld EPS2 = 1e-5;\nconst ld PI = acos(-1);\n\ninline bool eq(ld a, ld b) {\n return fabs(a - b) < ...
aoj_2617_cpp
20XX年, ICPC (Ikuta's Computer Pollutes Community) 商店街の経営者たちは大気汚染に悩まされていた。かつての活気を取り戻すためにも大気の綺麗さを一定以上にしなければならない。 商店街の店は一列に並んでおり、1から n で番号付けられている。 現在、おのおのの店のまわりの大気の綺麗さは p i である。 あなたは2から n−1 番目の店を選んで、その周辺の大気を循環させることで, その店と周囲の店の大気の綺麗さを変更することができる。 正確にいうと, i ( 2 ≤ i ≤ n−1 )番目を選んだとき、 p i−1 と p i+1 には p i だけ加算され, 逆に p i には 2p i...
[ { "submission_id": "aoj_2617_10851357", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair<ll, ll> P;\n\n#define each(i,a) for (auto&& i : a)\n#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)\n#define RFOR(i,a,b) for (ll i=(b)-1,__last_#...
aoj_2619_cpp
Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of p...
[ { "submission_id": "aoj_2619_9592955", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)...
aoj_2620_cpp
Nathan O. Davis is running a company. His company owns a web service which has a lot of users. So his office is full of servers, routers and messy LAN cables. He is now very puzzling over the messy cables, because they are causing many kinds of problems. For example, staff working at the company often trip over a cable...
[ { "submission_id": "aoj_2620_10210657", "code_snippet": "// AOJ #2620\n// Trodden Cable 2025.2.11\n\n#include <bits/stdc++.h>\nusing namespace std;\n \nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n \n int W, H, N;\n cin >> W >> H >> N;\n \n int sx, sy, tx, ty;\n cin >> sx >...
aoj_2618_cpp
キョウトという街は古い寺社仏閣で有名な観光地である。 イクタ君は数人の友人とキョウト観光に来ていたが、全員が好き勝手に行動した結果、みんな迷子になってしまった。 そこでイクタ君は、なるべく早く全員と合流するためには集合場所をどこにするのがよいか考えることにした。 キョウトの道路は東西と南北に距離10の間隔で無数に走っており、無限に広がる正方格子とみなすことができる。 道路は直線であるとみなし、幅は無いものとする。 また、街の中心を基準として東に距離 x 、北に距離 y 移動した位置を (x,y) という座標で表す。 街の中心である (0,0) では東西の道路と南北の道路が交差している。 下図はキョウトの道路と、いくつかの点の座標を図...
[ { "submission_id": "aoj_2618_10851455", "code_snippet": "#include<algorithm>\n#include<bitset>\n#include<cassert>\n#include<cfloat>\n#include<climits>\n#include<cmath>\n#include<deque>\n#include<functional>\n#include<iomanip>\n#include<iostream>\n#include<map>\n#include<numeric>\n#include<queue>\n#include<s...
aoj_2621_cpp
Ievan Ritola is a researcher of behavioral ecology. Her group visited a forest to analyze an ecological system of some kinds of foxes. The forest can be expressed as a two-dimensional plane. With her previous research, foxes in the forest are known to live at lattice points. Here, lattice points are the points whose x ...
[ { "submission_id": "aoj_2621_11040511", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<ll, 2>;\nusing a3 = array<ll, 3>;\n\nbool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }\nbool chmax(auto& a, const auto& b) { return a < b ? a = b...
aoj_2629_cpp
マンハッタンでは,道路がx 座標またはy 座標が整数のところに通っている.すぬけ君の家とすめけ君の家はどちらも道路上にあり,直線距離(ユークリッド距離) はちょうど d である.すぬけ君の家からすめけ君の家まで道路に沿って移動するときの最短距離として考えられる最大値を求めよ. Constraints 0 < d ≤ 10 d は小数点以下ちょうど三桁まで与えられる Input d Output 答えを一行に出力せよ.絶対誤差または相対誤差が 10 −9 以下のとき正答と判定される. Sample Input 1 1.000 Sample Output 1 2.000000000000 Sample Input 2 2.345 Sam...
[ { "submission_id": "aoj_2629_5993919", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n double d;\n cin >> d;\n long double ans = d;\n for(long double i = 0; i*i <= d*d; i += 0.00001) {\n long double e = sqrt(d*d-i*i);\n if((int)round(i*100000)%1000...
aoj_2622_cpp
Ayimok is a wizard. His daily task is to arrange magical tiles in a line, and then cast a magic spell. Magical tiles and their arrangement follow the rules below: Each magical tile has the shape of a trapezoid with a height of 1. Some magical tiles may overlap with other magical tiles. Magical tiles are arranged on the...
[ { "submission_id": "aoj_2622_10325380", "code_snippet": "// AOJ #2622 Removing Magical Tiles\n// 2025.3.26\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()...
aoj_2628_cpp
You have a board with height two and width W . The board is divided into 1x1 cells. Each row of the board is numbered 1 and 2 from top to bottom and each column is numbered 1 to W from left to right. We denote a cell at the i -th row in the j -th column by (i, j) . Initially, some checkers are placed on some cells of t...
[ { "submission_id": "aoj_2628_10325499", "code_snippet": "// AOJ #2628 Rotation Game\n// 2025.3.26\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\tdo n = 10*n + (c & 0xf), c = gc(); while (c ...
aoj_2623_cpp
Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodes’ values multiplied by -1. Values on leaf nodes are evaluat...
[ { "submission_id": "aoj_2623_10325384", "code_snippet": "// AOJ #2623 Optimal alpha beta pruning\n// 2025.3.26\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\...
aoj_2625_cpp
Ciel, an idol whose appearance and behavior are similar to a fox, is participating in a rehearsal for the live concert which takes place in a few days. To become a top idol, a large amount of effort is required! The live stage can be expressed as a two-dimensional surface. The live stage has N spotlights to illuminate ...
[ { "submission_id": "aoj_2625_7124188", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, n) for (int i = 0; i < (n); ++i)\n#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)\n\n#define all(c) std::begin(c), std::end(c)\n\n#ifdef LOCAL\n#define debug(...) debug_impl(#__VA...
aoj_2624_cpp
You and your grandma are playing with graph automata, which is generalization of cell automata. A graph automaton is expressed by a graph. The vertices of the graph have a time-dependent value, which can be either 0 or 1. There is no more than one edge between any of two vertices, but self-loops might exist. The values...
[ { "submission_id": "aoj_2624_10508954", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define all(v) (v).begin(),(v).end()\n#define pb(a) push_back(a)\n#define rep(i, n) for(int i=0;i<n;i++)\n#define foa(e, v) for(auto&& e : v)\nusing ll = long long;\nconst ll mod = 1000000009;\n\nvector<...
aoj_2630_cpp
すぬけ君の辞書には, n 個の英小文字からなる単語 s 1 , . . ., s n がのっている.これは辞書順で比較したとき s 1 < . . . < s n をみたす.残念ながらいくつかの文字はかすれて読めなくなってしまっている.読めなくなった文字は ? で表される. ? を英小文字で置き換えて辞書を復元する方法は何通りあるか,mod 1,000,000,007 でもとめよ. Constraints 1 ≤ n ≤ 50 1 ≤ |s i | ≤ 20 s i に現れる文字は英小文字または ? である Input n s 1 . . . s n Output 答えを一行に出力せよ. Sample Input 1 2 ?sum...
[ { "submission_id": "aoj_2630_10852594", "code_snippet": "#include <cstdio>\n#include <cstring>\n\n#define S 21\n#define L 28\n#define N 51\n#define M 1000000007\n\nchar s[N][S];\nint f[N][N][S][L], n;\n\nint solve(int l, int r, int p, int c)\n{\n if (~f[l][r][p][c])\n return f[l][r][p][c];\n if...
aoj_2627_cpp
You are a programmer who loves pretty girl games (a sub-genre of dating simulation games). A game, which is titled "Floatable Heart" and was released last Friday, has arrived at your home just now. This game has multiple stories. When you complete all of those stories, you can get a special figure of the main heroine, ...
[ { "submission_id": "aoj_2627_10325472", "code_snippet": "// AOJ #2627 Multi Path Story\n// 2025.3.26\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() {\n\tint n = 0; int c = gc();\n\tdo n = 10*n + (c &...
aoj_2631_cpp
m 頂点の完全グラフがある.最初,完全グラフの辺には色は塗られていない.すぬけ君は,各 i (1 ≤ i ≤ n ) について次の操作を行った: 完全グラフから a i 個の頂点を選び,選ばれた頂点同士を結ぶ辺すべてを色 i でぬる.複数個の色が塗られた辺はなかった. m として考えられる最小値を求めよ. Constraints 1 ≤ n ≤ 5 2 ≤ a i ≤ 10 9 Input n a 1 . . . a n Output m の最小値を一行に出力せよ. Sample Input 1 2 3 3 Sample Output 1 5 たとえば,頂点1, 2, 3, 4, 5 からなるグラフがあった場合,次のように色を塗るこ...
[ { "submission_id": "aoj_2631_10892904", "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_2633_cpp
w を正整数, p を長さ2 2 w +1 の文字列とする. (w, p) - セルオートマトンとは次のようなものである. 0 または 1 の状態をとることのできるセルが無限個一次元に並んでいる. 時刻 0 に,すぬけ君は好きな有限個のマスを選んで状態を 1 にすることができる.残りのセルは 0 である. 時刻 t (> 0) のセル x の状態 f(t, x) は, f(t − 1, x − w), . . . , f(t − 1, x + w) によって以下のように定まる: \begin{eqnarray} f(t, x) = p[ \sum^w_{i=-w}2^{w+i} f(t − 1, x + i)] \;\;\;\;\;...
[ { "submission_id": "aoj_2633_11017480", "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_2635_cpp
すなけ君は,(自己交差を持たない) n 個の頂点からなる折れ線の形をしている.最初に,すなけ君の i 番目の頂点は (x i , y i ) にある.すなけ君は,平行移動や回転をして連続的に移動することはできるが,変形(折れ線の長さや二つの線分のなす角度を変える) することはできない. y = 0 は壁であり,(0, 0) に微小な穴が開いている.すなけ君がこの穴を通って全体が y < 0 をみたすように移動できるかどうか判定せよ. Constraints 2 ≤ n ≤ 1000 0 ≤ x i ≤ 10 9 1 ≤ y i ≤ 10 9 折れ線は自己交差を持たない どの三点も同一直線上にない (x i , y i ) ≠ (x ...
[ { "submission_id": "aoj_2635_9792558", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)...
aoj_2632_cpp
w 本の縦棒からなり,高さ(横棒を追加することのできる段数) が h のあみだくじがある. w は偶数である.このあみだくじの横棒を追加する場所の候補のうち上から a 番目,左から b 番目を (a, b) という.( (a, b) に横棒を追加した場合,上から a 段目で左から b 番目と b+1 番目の縦棒が結ばれる.) このような場所は合計 h(w −1) 箇所(1 ≤ a ≤ h , 1 ≤ b ≤ w − 1) 存在する. すぬけ君は, a ≡ b (mod 2) をみたす場所 (a, b) に全て横棒を追加した.次に,すぬけ君は, (a 1 , b 1 ), . . . , (a n , b n ) の場所の横棒を消した...
[ { "submission_id": "aoj_2632_10176470", "code_snippet": "// AOJ #2632\n// Dense Amidakuji 2025.2.2\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();\n//\t\td...
aoj_2634_cpp
すぬけ君は,初期状態では動くことはできない. i 番目のチケットの値段は p i であり,これを買うと任意の (x, y) と任意の非負実数 t に対し (x, y) から (x + ta i , y + tb i ) に移動することができるようになる.すぬけ君が平面上の任意の二点間を(いくつかのチケットを組み合わせて) 移動できるようになるために買わなければならないチケットの合計金額の最小値を求めよ. Constraints 1 ≤ n ≤ 200000 −10 9 ≤ a i , b i ≤ 10 9 1 ≤ p i ≤ 10 9 入力は全て整数である Input n a 1 b 1 p 1 . . . a n b n p n ...
[ { "submission_id": "aoj_2634_10316777", "code_snippet": "// AOJ #2634 Directions\n// 2025.3.21\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() { // 整数の入力\n\tint n = 0; int c = gc();\n\tif (c == '-') ...
aoj_2636_cpp
n 個の都市と n − 1 本の道路があり,木になっている.都市には 1 から n までの番号がつけられている.都市 1 を根とみたとき,都市 i の親は p i であり, i と p i の距離は d i である.すぬけ君は,1 以上 n 以下の各 k に対し,次の問題を解きたい. ある都市から都市 1, . . . . , k への距離の和の最小値 \begin{eqnarray} min_{1 \leq v \leq n} \{ \sum^k_{i=1} dist(i, v)\} \;\;\;\;\;\;\;\;\;\;\;\;\;\;(2) \end{eqnarray} を求めよ.ただし dist(u, v) は u と...
[ { "submission_id": "aoj_2636_10910512", "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>\n#include <queue>\nusing namespace std;\nusing ll = long long;\nconst ll INF = 1ll << 60;\n#define RE...
aoj_2637_cpp
すぬけ君は," s で t t " というダジャレを思いついたが,忘れてしまった.すぬけ君は以下のことを覚えている. s の長さは N である. t の長さは M である. t は s の部分文字列である.( s の連続する M 文字で t と一致している部分が存在する.) (s, t) として考えられる組み合わせの個数を 1,000,000,007 で割ったあまりを求めよ.ただし,文字は A 種類存在するものとする. Constraints 1 ≤ N ≤ 200 1 ≤ M ≤ 50 M ≤ N 1 ≤ A ≤ 1000 Input N M A Output 条件を満たす文字列の組 (s, t) の個数を 1,000,000,0...
[ { "submission_id": "aoj_2637_10316801", "code_snippet": "// AOJ #2637 Substring Pairs\n// 2025.3.21\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst int NMAX = 5010;\nconst int MOD = 1000000007;\n\nint N, M, A;\nint pw[NMAX], fa[NMAX], w[NMAX], f[NMAX];\n\nint find(int x) {\...
aoj_2638_cpp
すぬけ君は,誕生日プレゼントとして辺の長さが l 1 × . . . × l d の d 次元超直方体をもらった.すぬけ君は,この直方体を i 番目の座標の範囲が 0 以上 l i 以下となるようにおき, x 1 + . . . + x d ≤ s をみたす部分を食べてしまった.ただし x i は i 番目の座標を表す.すぬけ君の食べた部分の体積を V とすると, d!V ( V に d の階乗をかけた値) は整数となることが証明できる. d!V を1,000,000,007 で割ったあまりを求めよ. Constraints 2 ≤ d ≤ 300 1 ≤ l i ≤ 300 0 ≤ s ≤ $\sum l_{i}$ 入力は全て整...
[ { "submission_id": "aoj_2638_10853273", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconst int MAXN = 333;\nconst int MOD = 1e9 + 7;\nconst int MAXS = MAXN * MAXN;\nint n, s, x[MAXN], f[MAXS], g[MAXS];\n\ninline int fpm(int x, int k, int mod) {\n\tint ret = 1;\n\tfor (; k; k >>= 1) {\n...
aoj_2639_cpp
A 君は山手線に乗って目的地にたどり着きたい. A 君は電車に乗ってから a 分起きて b 分寝ることを繰り返す.目的地までは乗車後 c 分であり,このとき起きていれば下車できるが,逆に寝ている途中であれば乗り過ごしてしまう.また,A 君は乗り過ごしてもずっと同じ電車に乗り続け,電車は山手線を一周するのに 60 分かかる.したがって,A 君は目的地に 60t + c ( t は非負整数) 分後に着くことになる. 何分後にA 君は目的地に到着できるか.到着不可能なときは-1 を出力せよ.ただし,目的地に到着した時が寝ている時間と起きている時間の境目だった場合は降りることができるものとする. Input 入力は以下の形式で1 行で与えら...
[ { "submission_id": "aoj_2639_6933126", "code_snippet": "#include <iostream>\n#include<string.h>\n#include <stdio.h>\n#include <cmath>\n#include <algorithm>\n#include <stack>\n#include<math.h>\n\n\nusing namespace std;\n\n\nint main()\n{\n int sleep;\n int wake;\n int stop;\n\n cin >> wake >> sle...
aoj_2640_cpp
A さんと B 君は, N × M の長方形のマス目状の地域に住んでいる.各マス目は道か壁か家のどれかである.この地域は,道が複雑で入り組んでいるので痴漢被害がよく起こることで有名であるため,この地域と外部との境界は全て壁で囲まれており,隔離されている. B 君はなんとなく気が向いたので,A さんの家を眺めに行くことにした.しかし,不幸なことにB 君は明らかに怪しい顔をしているので,A さんの家に行く途中に少しでも痴漢の疑いがあるような行動を取ったらすぐに捕まってしまうだろう.特に,右手を壁から離して歩くことは絶対にやってはならない.B 君は,一瞬たりとも右手を離すことなく,A さんの家に辿り着くことが出来るだろうか? B 君はつね...
[ { "submission_id": "aoj_2640_9349881", "code_snippet": "#include <bits/stdc++.h>\n\n\n\n\nnamespace zawa {\n\nusing i16 = std::int16_t;\nusing i32 = std::int32_t;\nusing i64 = std::int64_t;\nusing i128 = __int128_t;\n\nusing u8 = std::uint8_t;\nusing u16 = std::uint16_t;\nusing u32 = std::uint32_t;\nusing u...
aoj_2641_cpp
西暦20XX 年,学校対抗魔法競技大会が開かれていた.大会もいよいよ,最終競技を残すのみとなった.あなたはその競技の選手の1 人である. あなたが出場する競技は,空間内に配置された青いオブジェをすべて破壊するまでの時間を競うというものである.選手は競技用の銃の持込が許可されている.空間内には複数の青いオブジェと同じ数の赤いオブジェ,そして複数の障害物が配置されている.青いオブジェと赤いオブジェは1 対1 に対応しており,赤いオブジェが配置されている座標から青いオブジェに弾を撃つことで青いオブジェを破壊しなければならない.空間内に配置されている障害物は球状であり,少しずつ組成が異なっているが,通常の弾であれば障害物に触れると弾はその場...
[ { "submission_id": "aoj_2641_9066926", "code_snippet": "// (⁠◕⁠ᴗ⁠◕⁠✿⁠)\n\n// #pragma GCC target(\"avx2\")\n// #pragma GCC optimize(\"O3\")\n// #pragma GCC optimize(\"unroll-loops\")\n#include <bits/stdc++.h>\n#define rep(i, n) for (ll i = 0; i < (n); i++)\n#define srep(i, s, n) for (ll i = s; i < (n); i++)\...
aoj_2642_cpp
2014 年春,ある学生は無事大学に合格し,一人暮らしを始める事となった.ここで問題となるのが夕食をどうするかである.彼はこれから N 日間の夕食の計画を立てる事にした. 彼は N 日間で得られる幸福度の合計を出来る限り大きくしたい.もちろん,美味しいものや好きなものを食べるほど幸福度は高い. 彼の夕食の選択肢は2 つ,近くの食堂に向かうか,自炊をするかのどちらかである. 食堂で得られる幸福度は,その日のメニューによって変わる.メニューは日替わりだが毎日一種類のみで, N 日間のメニューは全て既に公開されている.なので,彼は i 日目 (1 ≤ i ≤ N ) に食堂に行けば C i の幸福度を得られるという情報を全て知っている. ...
[ { "submission_id": "aoj_2642_10850473", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing VS = vector<string>; using LL = long long;\nusing VI = vector<int>; using VVI = vector<VI>;\nusing PII = pair<int, int>; using PLL = pair<LL, LL>;\nusing VL = vector<LL>; using ...
aoj_2646_cpp
今年も,全国プログラミング選手権大会の時期がやってきた.全国大会の参加権を賭けた地区大会は, 2 n チームが1 対1 の勝ち残り式トーナメント方式で対決する. トーナメント表にはチーム番号 0, . . . 2 n − 1 が割り振られており,1 回戦から n 回戦までの対決手順は次の通りである. 1 回戦では,(チーム番号が l のチーム)と(チーム番号が l + 1 のチーム)が対決する.( l ≡ 0 (mod 2)) i + 1 回戦( 1 ≤ i < n ) では,「チーム番号が l 以上 l + 2 i 未満のチームのうち, i 回戦までの対決で 1 回も負けていないチーム」と「チーム番号が l + 2 i 以上 l ...
[ { "submission_id": "aoj_2646_10313129", "code_snippet": "// AOJ #2646 Tournament\n// 2025.3.20\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\tdo n = 10*n + (c & 0xf), c = gc(); wh...
aoj_2644_cpp
文字列 S と, m 個のクエリが与えられる. i 番目のクエリは二つの文字列 x i , y i で与えられる. 各クエリについて,文字列 S の部分文字列であり, x i で始まり y i で終わるものの中で,最長の長さを答えよ. 文字列 S について, |S| は S の長さを表す.また,文字列 T が文字列 S の部分文字列であるとは,ある整数 i が存在して, 1 ≤ j ≤ |T| に対して T j = S i+j を満たすことを言う.ただし T j は T の j 番目の文字を表す. Input 入力は以下の形式で与えられる. S m x 1 y 1 x 2 y 2 : x m y m 1 行目には,文字列 S が与え...
[ { "submission_id": "aoj_2644_10946052", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair<ll, ll> P;\n\n#define each(i,a) for (auto&& i : a)\n#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)\n#define RFOR(i,a,b) for (ll i=(b)-1,__last_#...
aoj_2643_cpp
盤面上にロボットと壁,ゴールが設置されており, ロボットの行動パターンを記述したプログラムが与えられる. 与えられるプログラムは以下のEBNF で表される. プログラム:= {文}; 文:= if 文|while 文|動作文; if 文:= "[", 条件, プログラム, "]"; while 文:= "{", 条件, プログラム, "}"; 動作文:= "^"|"v"|"<"|">"; 条件:= ["~"], "N"|"E"|"S"|"W"|"C"|"T"; 「プログラム」は0個以上の「文」からなり,1つ以上の文が存在する場合は 1 つ目の文から順番に1 つずつ文が実行される.「文」は「動作文」,「if 文」,「while 文」...
[ { "submission_id": "aoj_2643_9721841", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)...
aoj_2647_cpp
閉路のない連結な有向グラフが与えられる.(有向グラフが連結であるとは,これを無向グラフとした時に連結であるという事である.) このグラフに対して一つの頂点を選んで首都 s を定めたい. T(v) = " v から全ての点を到達可能にするために必要な「辺の反転」操作の回数の最小値"とする. ただし,「辺の反転」とは,頂点 v, u に関して (v, u) に張られていた有向辺を削除して (u, v) に張り直すことである. 頂点 s が首都であるとは任意の頂点 v に対して, T(s) ≤ T(v) が成立することである. 首都であるような頂点をすべて列挙して答えよ. Input 入力は以下のような形式で M + 1 行で与えられる....
[ { "submission_id": "aoj_2647_10853904", "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_2659_cpp
D : Chopsticks / 箸 Problem お箸は 2 本 1 セット(1 膳)で用いるものである。しかしあるとき一人暮らしの大学生であるいあづ君は箸立てに入っているお箸が奇数本であることに気がついた。これは明らかにおかしい。いつの間にか何本か無くしてしまったのである。 困ったいあづ君は、今後このようなことが無いように箸の本数を毎日記録することにした。 ところが、いあづ君が決めた記録の方法は少し変わっている。 それは、まず M 個の自然数 A 1 , ... , A M を決めた後、 箸の本数をそれらで割った余りを毎日記録するというものである。 例えばある日に残っている箸の本数が T のとき、 その日の記録として T % ...
[ { "submission_id": "aoj_2659_4268770", "code_snippet": "#define _USE_MATH_DEFINES\n#include <bits/stdc++.h>\nusing namespace std;\n#define FOR(i,m,n) for(int i=(m);i<(n);++i)\n#define REP(i,n) FOR(i,0,n)\n#define ALL(v) (v).begin(),(v).end()\nusing ll = long long;\nconst int INF = 0x3f3f3f3f;\nconst ll LINF...
aoj_2657_cpp
B : Books / 本 Problem 大学生のいづあ君はかなりの読書家である。面白そうだと思った本は迷わず買うため、蔵書が増えすぎて管理できなくなっているのが悩みである。そこでいづあ君は、持っている本の中から目的の本を検索するシステムを作ることにした。 全ての本は次の 3 つの属性を持つ。 title : 本のタイトルを表す文字列である。 author : 本の著者を表す文字列である。 date : 本の出版日を表す 2014/07/07 のような形式をした文字列である。 検索のクエリは次のような形式で与えられる。 Q_title Q_author Q_date_from Q_date_to Q_title : タイトルに文字...
[ { "submission_id": "aoj_2657_3657398", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n#define FOR( i, m, n ) for( int (i) = (m); (i) < (n); (i)++ )\n#define REP( i, n ) FOR( i, 0, n )\n#define REPR( i, m ) for( int (i) = (m); (i) >= 0; (i)-- )\n...
aoj_2664_cpp
C : Shopping / 買い物 問題文 料理が得意な2D君は昼ごはんを作ろうとしている。料理には N 個の材料 a_{0}, a_{1}, … , a_{N−1} が全てが必要である。 さて、今2D君の家の冷蔵庫には一つも材料が入っていないので、スーパーに買いに行かなければならない。スーパーでは材料 a_{i} を値段 x_{i} 円で買うことができる。 2D君は魔法使いでもあり、 M 種類の魔法が使える。 i 番目の魔法を材料 s_{i} にかければ材料 t_{i} に、また逆に t_{i} にかければ s_{i} に変えることができる。さらに、一つの材料に対して複数の魔法を繰り返して使うことができる。例えば、 p から q...
[ { "submission_id": "aoj_2664_9233111", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)\n#define all(v) (v).begin(),(v).end()\nusing namespace std;\nusing ll = long long;\n\ntemplate<typename T>\nbool chmin(T &a, const T &b){\n if (a <= b) return fal...
aoj_2663_cpp
B : RUPC 問題文 ロシア連邦でプログラミングコンテストが開催される。コンテストには N 個の問題が出題され、 M 人の参加者がいる。問題 i には得点 a_i が設定されており、参加者 j の実力は b_j であることがわかっている。問題 i と参加者 j について、 a_i ≤ b_j のときかつそのとき限り、参加者 j は問題 i を必ず解くことができる。 コンテストを通した参加者の得点は、その人が解くことができた問題の得点の総和である。また、参加者 j は、このコンテストでの目標点数 c_j を定めている。 各参加者が、目標点数以上の得点を獲得できるか判定せよ。 入力 入力は以下の形式で与えられる。 N a_{0} a...
[ { "submission_id": "aoj_2663_9595996", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\n#define all(x) (x).begin(), (x).end()\nint a[300001], b1[300001];\nll c1[300001];\nll pr[300001];\n\nint main() {\n int n;\n cin >> n;\n for (int i = 0; i < n; i++) {\n ...
aoj_2667_cpp
F : Tree / 木 問題文 大きさ N の根付き木がある。 各頂点には 0 から N−1 までの番号が付けられ、根が 0 である。 任意の辺の両端の頂点について、割り当てられた整数は根に近いほうが小さい。初めは全ての辺の重みは 0 である。 この木に対する Q 個のクエリを順に処理せよ。クエリには以下の 2 種類がある。 頂点 u , v の距離(パスに含まれる辺の重みの和)を求める。 頂点 v の子孫(自身を含まない)に接続する辺の重みを全て x 増加させる。 入力 入力は以下の形式からなる。 N Q a_0 b_0 … a_{N−2} b_{N−2} q_0 … q_{Q−1} a_i,b_i は i 番目の辺が結ぶ頂点で...
[ { "submission_id": "aoj_2667_10933935", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define g(x) ((x)>>i)\n#define f(x) (g(x)<<i) != x\n#define r() for(int i = 1; i <= lg; i++)\n#define rr() for(int i = lg; i >= 1; i--)\ntemplate<typename S, S(*op)(S, S), S(*e)(), typename F, S(*mappi...
aoj_2665_cpp
D : Hopping Hearts / こころぴょんぴょん 問題文 N 羽のうさぎが長さ L−1 の平均台の上にいる。 i 番目のうさぎの初期位置は整数 x_i であり、 0 ≤ x_{i} \lt x_{i+1} ≤ L−1 を満たす。座標は右に進むほど大きくなる。任意の i 番目のうさぎは、任意の回数だけ、ちょうど距離 a_i だけ右方向にジャンプ(すなわち、 x_i から x_i+a_i へ移動)することができる。ただし別のうさぎを飛び越えること、 −1 以下または L 以上の位置に入ることはできない。また、同時にジャンプしていられるのは高々 1 羽であり、ある座標に存在できるうさぎの数も高々 1 羽である。 初期状態から始...
[ { "submission_id": "aoj_2665_10850463", "code_snippet": "#define _USE_MATH_DEFINES\n#include <algorithm>\n#include <array>\n#include <bitset>\n#include <cassert>\n#include <cctype>\n#include <climits>\n#include <clocale>\n#include <cmath>\n#include <complex>\n#include <cstdio>\n#include <cstdlib>\n#include ...
aoj_2669_cpp
A: A-Z Cat / A-Z キャット 物語 あいずにゃんは若ヶ松高校のプログラミングコンテスト部,通称ぷろこん部に所属する2年生である.とてつもなくかわいい.あいずにゃんは友達のジョイに頼まれて猫を預かることになった.A-Z キャットと呼ばれる珍種の猫である.あいずにゃんは預かった A-Z キャットを「あいずにゃん 2 号」と (勝手に) 名付け,大層可愛がった. A-Z キャットは特定の条件を満たす文字列を好むとされる.そこであいずにゃんが試しに文字列を与えてみると,あいずにゃん 2 号は文字列の一部を爪で切り取った後,満足げな表情を浮かべた.どうやら,好みの文字列に書き換えようとしているようだ. 天使のごとくかわいいあいず...
[ { "submission_id": "aoj_2669_9598797", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nint main() {\n string s;\n cin >> s;\n int n = (int)s.size();\n int ans = 1e9, opt_mask = -1;\n for (int mask = 0; mask < (1 << n); mask++) {\n string f;\n int cnt = 0;\n ...
aoj_2666_cpp
E : Arojam's Mask / 仮面 問題文 あなたは勇者である。勇者が旅をしている世界は N 個の街と、異なる街同士を結ぶ M 本の道からなる。道 i は街 a_i と街 b_i を結び、双方向に移動可能である。 街 S から出発し、街 T に移動することが勇者の目的である。 S,T は異なる街である。勇者は 0 日目に街を出発し、ちょうど 1 日かけて 1 本の道を通って移動することができる。道を使った移動には日数の制限 R があり、 R 日目を超えることはできない。 また、勇者は任意の街で「オカリナを吹く」こともできる。オカリナを吹くと、時は 0 日目に、位置は街 S に戻される。つまり、 R 回を超える移動を行う場合...
[ { "submission_id": "aoj_2666_9233718", "code_snippet": "/*______\n   ||      |\n   ||ACはこちらへ|\n   ||      |\n   || ̄ ̄ ̄ ̄ ̄ ̄ \n∧_∧||\n(`・ω・||\n( つ||0\n uーu*/\n#include <bits/stdc++.h>\nusing namespace std;\n//output and debug\ntemplate <class T> using V = vector<T>;\ntemplate <class T, class U> \nostream& ope...
aoj_2660_cpp
E : Sigma / Σ Problem 小学生のづあい君は同じ足し算にも得意不得意があり、 0 以上の整数 X , Y に対して、 X + Y を計算するのにかかる時間(秒)が次のように決まる。 1 の位から順番に計算していく。 10 進数表記で 10 i 位の計算には x i × y i + c i 秒かかる。 x i は X の10進数表記で 10 i の位の数である。 y i は Y の10進数表記で 10 i の位の数である。 ただし i が X の桁数より大きくなる時は x i = 0 とする。 Y についても同様である。 c i は、 i = 0 または x i-1 + y i-1 + c i-1 < 10 ならば ...
[ { "submission_id": "aoj_2660_4723635", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#ifdef _DEBUG\n #include \"_DEBUG.hpp\"\n#endif\n#define int long long\nconst int INF = 1LL << 60;\n\ntemplate<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }\ntemplate<class T, class... T...
aoj_2673_cpp
E: Do You Divide It? / 切り刻む気か? 物語 T君は過去に出場したプログラミングコンテストで平面図形の問題にひどく手こずらされ,それ以来,平面図形に強い恨みを抱いている. 中でも,特に二次元平面上に描かれる多角形に対して複雑な感情を抱いているため,多角形を見かけると切り刻まずにはいられない. T君が多角形を切り刻むときには,y軸に平行に幅 0.5 の間隔でスリットの入った板で多角形を覆い,スリットで見えない部分を切り刻んで捨ててしまう. しかしながら,T君は一方的な殺戮を好まないため,多角形に再起の芽を残すべく,切り刻んだ後に残る図形の合計面積ができるだけ大きくなるように配慮する. T君が切り刻んだ後に残る図形...
[ { "submission_id": "aoj_2673_8439442", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define chmin(x,y) x = min(x,y)\n#define chmax(x,y) x = max(x,y)\n#define BIG_NUM 2000000000\n#define HUGE_NUM 4000000000000000000 //オーバーフローに...
aoj_2671_cpp
C: Digital Clock / デジタル時計 物語 あいずにゃんは最近,風邪を引いてしまった.あまりのだるさにベットから出られない.辛そうにしている姿もまたかわいい. しかし暇で暇で仕方がないあいずにゃんは,枕下にあるデジタル時計で遊ぶ方法を考えついた.下の図のようなデジタル時計の光っている棒の本数を毎秒毎秒,ただひたすらに数えるのである. 何時間かこの遊びを続けた頃,あいずにゃんは時間が違っていても光っている棒の本数が等しい場合があることに気づいた.光っている棒の本数が等しい時間が何通りあるのか気になったあいずにゃんは,看病中のあなたに数えてくれるようお願いしてきた. ベッドから出られないあいずにゃんのために,あなたはプログ...
[ { "submission_id": "aoj_2671_9134365", "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) { return (ull)rn...
aoj_2672_cpp
D: Rescue a Postal Worker / 郵便局員を救え 物語 あなたは,この春に長年の夢だった郵便局に就職できました.担当する配達地域も決定し,ウキウキ気分で迎えた初仕事ですが,あまりに浮かれていたため郵便物を入れた袋に穴が空いているのに気づかず,入っていた郵便物を全部落としてしまいました.しかし,用意周到なあなたはすべての郵便物にGPSをつけていたため,どこに郵便物が落ちているかを知ることができます. 郵便物を拾いなおしていると予定していた配達時間を超えてしまうかもしれないので,あなたはできる限り短い時間で配達を終えたいと思っています.落としてしまったすべての郵便物を拾いなおして,それぞれの配達先に届ける最短の時間...
[ { "submission_id": "aoj_2672_7680942", "code_snippet": "#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <queue>\n#include <cstdint>\n#include <limits>\n\n#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)\n#define rrep(i, a, n) for (int i = ((int)(n - 1)...
aoj_2675_cpp
G: Dungeon of Cards / カードの迷宮 物語 ここは不思議の国あじふらい.あじふらい辺境の地に位置するカードの迷宮には,金銀財宝が眠ると伝えられている.好奇心旺盛なあいずにゃんは,この言い伝えを聞くやいなや,友人のウィを連れてカードの迷宮を目指す旅に出ることにした. 翌日,旅の計画を立てるためにあいずにゃんがウィの家を訪れると,ウィは何やら考え込んでいるようだった.どうやら用意周到なウィはカードの迷宮に関する重要な情報を入手したようだ.それは,カードの迷宮には N 枚の扉があり,それぞれの扉を開けるためにカードが必要になるということだ. カードの迷宮への道中には,扉を開くためのカードを扱う店がある.ウィはここでカー...
[ { "submission_id": "aoj_2675_10224397", "code_snippet": "// AOJ #2675 Dungeon of Cards\n// 2025.2.16\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst ll INF = 1e15;\n \nll letterCost[26];\nll digitCost[10];\nll costPair[26][10];\n \nstruct Door { int l, d; };\n \nint doorMas...
aoj_2670_cpp
B: Cram School Schedule / 塾の時間割 物語 あなたは塾の経営者である.あなたの塾は個人授業制で1人の生徒と1人の先生で授業を行う.この塾の先生は非常に優秀で科目にかかわらずすべての授業を行うことができる.また,先生と生徒は非常にタフなので,出席できる授業には他の授業の出席状況にかかわらず,すべて出席することが可能である.例えば,同じ時間帯の授業に出席できる2人の生徒と4人の先生がいる場合は,その時間帯に2つの授業を行える. あなたは来月の授業予定を立てなくてはいけないが,先生と生徒の人数が多いため予定を立てるのが非常に大変である.また,あなたはできるだけ多くの授業を行いたいと考えている.そのため,あなたは行...
[ { "submission_id": "aoj_2670_4512675", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\ntypedef long long int ll;\ntypedef pair<ll,ll> mp;\nll inf = 1e9;\n\n\nint main(){\n ll k;\n cin>>k;\n vector<mp> clas(k);\n for(ll i=0;i<k;i++){\n string s;\n cin>>s;\n int a=0,b=0;\n a = ( (s[0]-'0'...
aoj_2676_cpp
H : Typing Game / タイピングゲーム 物語 ここからは,タイピング力を鍛える時間です.皆さんは早く正確なタイピングをすることができますか? Let’s enjoy Typing Game! 問題 タイピングゲームのゲームシステムとして,ジャッジ側が用意したAIの出力に対して対話的に動作するプログラムを作成せよ. AIは N 個の文字列をタイプするゲームをプレイする.AIは体力を持っており,その初期値は H である.AIは体力がある限り文字のタイプを行う.システムはAIがタイプすべき文字列を提示する.システムはAIがタイプした文字を受け取り,次にタイプすべき文字と一致するか判定する.AIが文字列を 1 つタイプし終える...
[ { "submission_id": "aoj_2676_4513902", "code_snippet": "// #define _GLIBCXX_DEBUG // for STL debug (optional)\n#include <iostream>\n#include <iomanip>\n#include <cstdio>\n#include <string>\n#include <cstring>\n#include <deque>\n#include <list>\n#include <queue>\n#include <stack>\n#include <vector>\n#include...
aoj_2677_cpp
A - Breadth-First Search by Foxpower Problem Statement Fox Ciel went to JAG Kingdom by bicycle, but she forgot a place where she parked her bicycle. So she needs to search it from a bicycle-parking area before returning home. The parking area is formed as a unweighted rooted tree $T$ with $n$ vertices, numbered $1$ thr...
[ { "submission_id": "aoj_2677_9958268", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint N;\nconst int MAX = 100100;\nvector<int> G[MAX];\nvector<int> d;\nvector<vector<int>> dp(30, vector<int>(MAX));\n\nvoid dist(int v){\n\tfor(auto c:G[v]){\n\t\td[c] = d[v] + 1;\...
aoj_2674_cpp
F: Disordered Data Detection / 異常検知 物語 宮守あかねは武蔵野ソフトウェアに務めるエンジニアである.今日は顧客から受けた不具合報告に頭を悩ませている.「変な話,この前作ってもらったソフトの挙動がぷるんぷるんしてるんでぇ,そちらでチェックしてもらえますか?保守するのもおたくらの仕事でしょ?」いつも無理難題ばかり押し付けてくるこの顧客だが,今回ばかりはこちらに非がある.なぜなら,いつも適当な仕事ばかりのジローがテストに通っていないコードをそのまま放置して製品に組み込んだことを告白したからである.普通の人間ならジローに殴りかかりそうなものだが,もはやいつものことだ,あかねは怒りを通り越し,すでに悟りを開き...
[ { "submission_id": "aoj_2674_10906045", "code_snippet": "#line 1 \"test/aoj/2674.test.cpp\"\n// clang-format off\n// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/challenges/search/titles/2674\n// clang-format on\n#line 2 \"other/fastio.hpp\"\n// ref: https://maspypy.com/library-checker-man...
aoj_2683_cpp
G - Proportional Representation Problem Statement An election selecting the members of the parliament in JAG Kingdom was held. The only system adopted in this country is the party-list proportional representation. In this system, each citizen votes for a political party, and the number of seats a party wins will be pro...
[ { "submission_id": "aoj_2683_10851236", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cassert>\n#include <cstring>\n#include <vector>\n#include <valarray>\n#include <array>\n#include <queue>\n#include <set>\n#include <unordered_set>\n#include <map>\n#include <unordered_map>\n#include <a...
aoj_2678_cpp
B - Cube Coloring Problem Statement Great painter Cubic is famous for using cubes for his art. Now, he is engaged in a new work of art. He tries to form an $X \times Y \times Z$ rectangular parallelepiped by arranging and piling up many $1 \times 1 \times 1$ cubes such that the adjacent surfaces of cubes are fully shar...
[ { "submission_id": "aoj_2678_10848633", "code_snippet": "#include<cstdio>\n#include<algorithm>\n#include<iostream>\n#include<cstring>\n#include<vector>\n#include<cmath>\n#include<map>\n#include<set>\nusing namespace std;\ntypedef long long ll;\nconst ll N=1e3+10;\nconst ll P=1e9+7;\nll a[3][N],b[N],c[N];\ni...
aoj_2679_cpp
C - Decoding Ancient Messages Problem Statement Professor Y's work is to dig up ancient artifacts. Recently, he found a lot of strange stone plates, each of which has $N^2$ characters arranged in an $N \times N$ matrix. Further research revealed that each plate represents a message of length $N$. Also, the procedure to...
[ { "submission_id": "aoj_2679_10853311", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <queue>\n\nusing namespace std;\n\nvector<int> operator + (const vector<int> &A, const vector<int> &B)\n{\n vector<int> v(52);\n for (int i = 0; i < 52; ++i)\n v[i] = A[i] + B[i];\n retur...
aoj_2684_cpp
H - RLE Replacement Problem Statement In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only contain uppercase English letters and the same letters often appear repeatedly in ICPC programs. Thus, programmers in JAG Kingdom prefer to ...
[ { "submission_id": "aoj_2684_4961665", "code_snippet": "#pragma GCC optimize(\"Ofast\")\n#include <iostream> // cout, endl, cin\n#include <string> // string, to_string, stoi\n#include <vector> // vector\n#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound\n#include <utility> // p...
aoj_2682_cpp
F - Polygon Guards Problem Statement You are an IT system administrator in the Ministry of Defense of Polygon Country. Polygon Country's border forms the polygon with $N$ vertices. Drawn on the 2D-plane, all of its vertices are at the lattice points and all of its edges are parallel with either the $x$-axis or the $y$-...
[ { "submission_id": "aoj_2682_10848305", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nconst int maxp=50;\nconst double eps=1e-8;\nint n;\ninline int sgn(double v)\n{\n\tif(abs(v)<eps)return 0;\n\treturn v<0?-1:1;\n}\nstruct Point\n{\n\tdouble x,y;\n\tPoint(double X=0,double Y=0)\n\t{\n\t\t...
aoj_2680_cpp
D - LR Problem Statement JAG Kingdom will hold a contest called ICPC (Interesting Contest for Producing Calculation). At the contest, you are given a string composed of ? s and usable characters . You should replace all ? s in the string with the usable characters to make the string valid mathematical expression, befor...
[ { "submission_id": "aoj_2680_6290308", "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 inc(i, a, b) for (int i = (a); i <= (b); ++i)\n#define dec(i, a, b) for (int i = (a); i >= (b); --i)\n\nstring mx(string a, ...
aoj_2685_cpp
I - Tokyo Olympics Center Problem Statement You are participating in the Summer Training Camp for Programming Cotests. The camp is held in an accommodation facility called Tokyo Olympics Center . Today is the last day of the camp. Unfortunately, you are ordered to check if all the participants have properly cleaned the...
[ { "submission_id": "aoj_2685_10318989", "code_snippet": "// AOJ #2685 Tokyo Olympics Center\n// 2025.3.23\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int INF = 1070000000;\n\nint H, W, K;\nint s, t, Tm, Tc;\nchar grd[55][55];\nint dst[55][55][55][55];\n\nint dy[4] = {0, 1...
aoj_2686_cpp
J - Unfair Game Problem Statement Rabbit Hanako and Fox Jiro are great friends going to JAG primary school. Today they decided to play the following game during the lunch break. This game is played by two players with $N$ heaps of some number of stones. The players alternatively take their turn to play the game. Jiro i...
[ { "submission_id": "aoj_2686_9805576", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)\n#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)...
aoj_2687_cpp
Problem A Balanced Paths You are given an undirected tree with $n$ nodes. The nodes are numbered 1 through $n$. Each node is labeled with either '(' or ')'. Let $l[u \rightarrow v]$ denote the string obtained by concatenating the labels of the nodes on the simple path from $u$ to $v$. (Note that the simple path between...
[ { "submission_id": "aoj_2687_10854036", "code_snippet": "#include <cstdio>\n#define L 1<<23\n#define C (c=*A++)\n#define N 200001\n\nint n,m,x,y,i,j,k,pr[N],sum,cnt,et=1,root,fe,hl,s[N],m1,m2,fw[N],e[N],f[N],g[N],cd[N<<1],nt[N<<1],wt,ss[19];char c,fl[L],*A=fl;bool u[N],v[N];long long MAPLE;\n\ninline void r...
aoj_2688_cpp
Problem B Card Game Strategy Alice and Bob are going to play a card game. There are $n$ cards, each having an integer written on it. The game proceeds as follows: Alice chooses an integer between $a$ and $b$, inclusive. Call this integer $t$. Alice then tells Bob the value of $t$. Bob chooses $k$ out of the $n$ cards. ...
[ { "submission_id": "aoj_2688_10318993", "code_snippet": "// AOJ #2688 Card Game Strategy\n// 2025.3.23\n\n#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef pair<int, int> pii;\ntemplate<typename T, typename U>\ninline void amin(T &x, U y) { if(y < x) x = y; }\ntemplate<typename T, typename U>\ninlin...
aoj_2694_cpp
Problem H Kimagure Cleaner Ichiro won the newest model cleaner as a prize of a programming contest. This cleaner automatically moves around in a house for cleaning. Because Ichiro's house is very large, it can be modeled as an infinite two-dimensional Cartesian plane, whose axes are called $X$ and $Y$. The positive dir...
[ { "submission_id": "aoj_2694_10852794", "code_snippet": "//by yjz\n#include<bits/stdc++.h>\nusing namespace std;\n#define FF first\n#define SS second\n#define PB push_back\n#define MP make_pair\n#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)\n#ifndef LOCAL\n#define cerr i...
aoj_2690_cpp
Problem D Content Delivery You are given a computer network with n nodes. This network forms an undirected tree graph. The $i$-th edge connects the $a_i$-th node with the $b_i$-th node and its distance is $c_i$. Every node has different data and the size of the data on the $i$-th node is $s_i$. The network users can de...
[ { "submission_id": "aoj_2690_10852805", "code_snippet": "#include<bits/stdc++.h>\n#define maxn 2500\nusing namespace std;\nint n,m;\nvector<pair<int,int> > g[maxn];\nlong long s[maxn];\nint p[maxn];\nint ep[maxn];\nint lb[maxn];\nint rb[maxn];\nlong long val[maxn];\nbool vis[maxn];\nint t[maxn];\nint rt;\ni...
aoj_2691_cpp
Problem E Cost Performance Flow Yayoi is a professional of money saving. Yayoi does not select items just because they are cheap; her motto is "cost performance". This is one of the reasons why she is good at cooking with bean sprouts. Due to her saving skill, Yayoi often receives requests to save various costs. This t...
[ { "submission_id": "aoj_2691_5477858", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst long long INF = 10000000000;\nconst int INF2 = 10000;\nstruct bigint{\n bool neg;\n vector<int> d;\n bigint(){\n neg = false;\n }\n bigint(long long x){\n neg = x < 0;\n x = abs(x);\n ...
aoj_2692_cpp
Problem F ICPC Teams You are a coach of the International Collegiate Programming Contest (ICPC) club in your university. There are 3N students in the ICPC club and you want to make $N$ teams for the next ICPC. All teams in ICPC consist of 3 members. Every student belongs to exactly one team. When you form the teams, yo...
[ { "submission_id": "aoj_2692_10853830", "code_snippet": "#include <bits/stdc++.h>\n\n#define x first\n#define y second\n#define pb push_back\n#define mp make_pair\n#define vi vector<int>\n#define pr pair<int,int>\n#define Rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)\n#define For(i,a,b) for(int i=(int)(a);i...