group_id
stringlengths
12
18
problem_description
stringlengths
85
3.02k
candidates
listlengths
3
20
aoj_2320_cpp
Problem A: Infnity Maze Dr. Fukuoka has placed a simple robot in a two-dimensional maze. It moves within the maze and never goes out of the maze as there is no exit. The maze is made up of H × W grid cells as depicted below. The upper side of the maze faces north. Consequently, the right, lower and left sides face east...
[ { "submission_id": "aoj_2320_10568641", "code_snippet": "// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/2320\n#include <algorithm>\n#include <cstdint>\n#include <iostream>\n#include <iterator>\n#include <numeric>\n#include <string>\n#include <vector>\n#include <cassert>\n#include...
aoj_2324_cpp
Problem E: Full Text Search Mr. Don is an administrator of a famous quiz website named QMACloneClone. The users there can submit their own questions to the system as well as search for question texts with arbitrary queries. This search system employs bi-gram search method. The bi-gram search method introduces two phase...
[ { "submission_id": "aoj_2324_3161155", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define int long long\n#define all(v) (v).begin(), (v).end()\n#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)\n#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)\n#define rep(i, ...
aoj_2321_cpp
Problem B: Butterfly Claire is a man-eater. She's a real man-eater. She's going around with dozens of guys. She's dating all the time. And one day she found some conflicts in her date schedule. D'oh! So she needs to pick some dates and give the others up. The dates are set by hours like 13:00 to 15:00. She may have mor...
[ { "submission_id": "aoj_2321_11059617", "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_2312_cpp
問題文 世の中の少女たちはキュゥべえと契約し願いを叶えてもらい,それとひきかえに魔法少女となる.使う魔法の形・効果は願いに強く影響を受ける.魔法少女 さやか ちゃんは最近キュゥべえと契約した新米魔法少女である. さやか の願いは「事故のため指が動かなくなり,音楽を演奏するのを諦めていた男の子を助けること」であったので,作る魔方陣は音符が輪の上に並んだ形をしている. さやか は N 個の音符を持っており,それらを輪の上に並べることによって魔方陣を作る.音符をどのような順番で並べるかは彼女の自由である.魔方陣を作るために精神力が消費され,その量は音符の配置によって以下のように決まる. まず, M 個の正の整数からなる 音楽的美しさ S_...
[ { "submission_id": "aoj_2312_10946081", "code_snippet": "#include \"bits/stdc++.h\"\n\nusing namespace std;\n#define FOR(i,s,t) for (int i = s; i < t; i++)\n#define SZ(x) (int)x.size()\nusing LL = long long; using ll = LL;\nusing VI = vector<int>; using VL = vector<LL>;\nconst LL INF = 1e9; const LL LINF = ...
aoj_2322_cpp
Problem C: Chinese Classics Taro, a junior high school student, is working on his homework. Today's homework is to read Chinese classic texts. As you know, Japanese language shares the (mostly) same Chinese characters but the order of words is a bit different. Therefore the notation called "returning marks" was invente...
[ { "submission_id": "aoj_2322_10257213", "code_snippet": "// AOJ #2322 Chinese Classics\n// 2025.3.1\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\tdo n = 10*n + (c & 0xf), c = gc(); w...
aoj_2325_cpp
Problem F: Mysterious Maze A robot in a two-dimensional maze again. The maze has an entrance and an exit this time, though. Just as in the previous problem, the maze is made up of H × W grid cells, its upper side faces north, and each cell is either empty or wall. Unlike the previous, on the other hand, one of the empt...
[ { "submission_id": "aoj_2325_10858305", "code_snippet": "#include<stdio.h>\n#include<string.h>\n#include<math.h>\n#include<algorithm>\n#include <queue>\n//#define debug 1\nusing namespace std;\n\nconst int maxn = 1010;\nconst int inf = (1<<30);\n\nint dx[4] = {-1,0,1,0};\nint dy[4] = {0,1,0,-1};\n\nstruct n...
aoj_2326_cpp
Problem G: Number Sorting Consider sets of natural numbers. Some sets can be sorted in the same order numerically and lexicographically. {2, 27, 3125, 9000} is one example of such sets; {2, 27, 243} is not since lexicographic sorting would yield {2, 243, 27}. Your task is to write a program that, for the set of integer...
[ { "submission_id": "aoj_2326_10858261", "code_snippet": "#include<cstdio>\n#include<iostream>\n#include<cstring>\n#include<algorithm>\nusing namespace std;\n#define lowbit(n) (n&-n)\nint l,r,m,a[100005],b,c[100005];\nvoid add(int pos,int val)\n{\n while(pos<=r-l+1) c[pos]=(c[pos]+val)%m,pos+=lowbit(pos...
aoj_2329_cpp
Problem J: Blue Forest John is playing a famous console game named 'Tales of Algorithmers.' Now he is facing the last dungeon called 'Blue Forest.' To find out the fastest path to run through the very complicated dungeon, he tried to draw up the dungeon map. The dungeon consists of several floors. Each floor can be des...
[ { "submission_id": "aoj_2329_2010618", "code_snippet": "#include<bits/stdc++.h>\n#define f first\n#define s second\n#define ff f,f\n#define fs f.s\n#define sf s.f\n#define ss s.s\n#define mp make_pair\n#define MAX 51\n#define inf 1e10\n#define eps (1e-11)\n#define pi M_PI\n#define equals(a,b) (fabs((a)-(b))...
aoj_2323_cpp
Problem D: Revenge of Champernowne Constant Champernowne constant is an irrational number. Its decimal representation starts with "0.", followed by concatenation of all positive integers in the increasing order. You will be given a sequence S which consists of decimal digits. Your task is to write a program which compu...
[ { "submission_id": "aoj_2323_9477278", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing vll = vector<ll>;\n#define rep(i,n) for(ll i=0;i<ll(n);i++)\n#define all(A) A.begin(),A.end()\n\nll f(ll N) {\n if (N > 1e16)return 1e18;\n ll res = 0;\n ll d = 1;\n ...
aoj_2328_cpp
Problem I: Mobile Network The trafic on the Internet is increasing these days due to smartphones. The wireless carriers have to enhance their network infrastructure. The network of a wireless carrier consists of a number of base stations and lines. Each line connects two base stations bi-directionally. The bandwidth of...
[ { "submission_id": "aoj_2328_10848629", "code_snippet": "#pragma comment(linker, \"/STACK:1024000000,1024000000\")\n#include <cstdio>\n#include <cmath>\n#include <cstring>\n#include <iostream>\n#include <queue>\n#include <map>\n#include <stack>\n#include <string>\n#include <algorithm>\n#include <vector>\n#i...
aoj_2331_cpp
Problem B: 友だちの誘い方 明日から、待ちに待った夏休みが始まります。なのでわたしは、友だちを誘って、海に遊びに行くこ とに決めました。 けれども、わたしの友だちには、恥ずかしがりやさんが多いです。その人たちは、あまり多くの人が いっしょに来ると知ったら、きっと嫌がるでしょう。 ほかにも、わたしの友だちには、目立ちたがりやさんも多いです。その人たちは、いっしょに来る人 があまり多くないと知れば、きっと嫌がるでしょう。 それと、わたしの友だちには、いつもは目立ちたがりやなのに実は恥ずかしがりやさんな人もいま す。その人たちは、いっしょに来る人が多すぎても少なすぎても、きっと嫌がるでしょう。 こういうのは、大勢で行った方が楽し...
[ { "submission_id": "aoj_2331_10885637", "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_2327_cpp
Problem H: Sky Jump Dr. Kay Em, a genius scientist, developed a new missile named "Ikan-no-i." This missile has N jet engines. When the i -th engine is ignited, the missile's velocity changes to ( vx i , vy i ) immediately. Your task is to determine whether the missile can reach the given target point ( X , Y ). The mi...
[ { "submission_id": "aoj_2327_10854011", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <algorithm>\n\n#define MAXN 1005\n#define EPS 1e-8\n\nconst double g = 9.8;\n\nint n;\nstruct Point {\n\tdouble x, y;\n}p[MAXN];\ndouble X, Y;\n\nbool cmp(Point a, Point b) {\n\tretur...
aoj_2332_cpp
Problem 3: 時空のスゴロク・ロード 全時空統一ディメンション・スゴロク・トーナメント。500 兆人を超える参加者の中から、ただ1人 のスゴロク絶対王者を決定するその大会に、あなたは21世紀の地球代表として参加している。 今あなたが挑戦している課題は、自分自身をコマとした1次元スゴロク。端のスタートマスから出発 して、1から6までの目が一つずつ書かれた巨大な6面ダイスを振って出た目の数だけ進むことを繰 り返す、あなたもよく知っている形式のスゴロクだ。スタートマスとは反対の端にあるゴールマスに 止まるとゴールとなる。もちろん、ゴールするまでにサイコロを振った回数が少なければ少ないほど 良い成績となる。 マスの中には特殊な効果を...
[ { "submission_id": "aoj_2332_9637294", "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_2335_cpp
Problem F: 10歳の動的計画 ある日の夕方。いつものようにあなたが居間でテレビを見ていると、小学5年生の妹から相談を持ち かけられた。話を聞いてみると、今日学校で出された算数の問題が難しくて理解できなかったので、 あなたに解き方を教えてほしいのだという。 妹を悩ませている問題は、「道が碁盤目状に通っている街において、家(0, 0) から学校( N , M ) まで最短距離で進む方法は何通りあるか?」というものだった。もちろん、あなたにとっては赤子の手をひねるよりも簡単な問題である。すぐに上のような図を書いて「家(0, 0) から順番に足し算していけば解けるよ」と教えてあげた。 ところが、それを聞いてもまだ、妹はなにやら下を...
[ { "submission_id": "aoj_2335_9770269", "code_snippet": "#line 2 \"cp-library/src/cp-template.hpp\"\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing ld = long double;\nusing uint = unsigned int;\nusing ull = unsigned long long;\nusing i32 = int;\nusing u32 = unsigned int;\nusing...
aoj_2334_cpp
Problem E: 街を駆ける道 ネーヴァ王国には、トタタ族とツテテ族、2種類の民族が暮らしている。トタタ族の最大の特徴は、 酢豚にパイナップルを入れて食べることである。だがツテテ族は、パイナップルに酢豚を入れて食べ る。こんな2つの民族がお互いに仲良くやっていけるはずもなく、トタタ族とツテテ族は、何百年も の昔からずっといがみ合いを続けてきた。 そんなある日、ネーヴァ王のもとに、2つの民族から嘆願書が届いた。それによるとトタタ族は、自 分たちが暮らす街Aと街Bのあいだを結ぶ道を建設してほしいらしい。一方でツテテ族も、自分たち が暮らす街Cと街Dのあいだを結ぶ道を建設してほしいらしい。 2つの民族が衝突するのを防ぐため、トタタ族が...
[ { "submission_id": "aoj_2334_10880844", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i,n) for(int i = 0; i < (n); i++)\nusing namespace std;\ntypedef long long ll;\n\nusing Real = double;\nusing Point = complex< Real >;\nusing Polygon = vector< Point >;\nconst Real EPS = 1e-9, PI = acos(-1);\ncons...
aoj_2337_cpp
Problem H: ねこ鍋改造計画(仮) あなたは、自宅にたくさんのねこを飼っている。そんなあなたの日課は、飼っているねこが土鍋の中 に入って昼寝している様子(通称:ねこ鍋)を撮影することだ。何匹かのねこが、鍋の中でいっしょ に丸くなって眠る姿は、実に愛くるしい。 それぞれのねこには、「重さ」 m i と「Cute」 c i が定義されている。Cute とは、そのねこ1 匹だけを見たときの、愛らしさ・あどけなさ・しなやかさ・やわらかさ・ういういしさ、などを総合的に評価した数値であり、大きければ大きいほどそのねこは魅力的である。 また、ねこ鍋に対しては「UnCute」という数値が定義される。これは、ねこ鍋全体としてのアンバラ ンスさ...
[ { "submission_id": "aoj_2337_10292218", "code_snippet": "// AOJ #2337 Remodeling Plan for Neko-Nabe (tentative)\n// 2025.3.13\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nstruct BS {\n int sz, nw;\n vector<ll> d;\n BS(int s) : sz(s), nw((s+63)/64) { d.assign(nw,0ULL);...
aoj_2339_cpp
Problem J: 問題文担当者は働かない! N 個の点からなる有向グラフがある。このグラフに閉路はない。それぞれの点には、いくつかの石が置かれている。このグラフを使って、2人のプレイヤーがゲームをする。おのおのの手番は、交互に訪れる。各プレイヤーは、自分の手番において、頂点 v を選び、そこに置かれた石を1つ以上取り除く。その後、 v から w に辺が張られているすべての頂点 w について、 w に置かれている石の個数を自由に変化させることができる(いくつ増やしても、いくつ減らしても、変化させなくてもよい)。これを繰り返して、最初に取る石がなくなった方の負けである。両者が最善をつくしたとき、先手と後手、どちらが勝つか。もしくは、...
[ { "submission_id": "aoj_2339_1712886", "code_snippet": "#define _USE_MATH_DEFINES\n#include <algorithm>\n#include <cstdio>\n#include <functional>\n#include <iostream>\n#include <cfloat>\n#include <climits>\n#include <cstdlib>\n#include <cstring>\n#include <cmath>\n#include <map>\n#include <queue>\n#include ...
aoj_2338_cpp
Problem I: よくわかる二重魔法 紀慧暦2119 年15 の月。宮廷魔術士Sengemon Lugene の手によって、一冊の魔術書が書き記された。この魔術書「In Magiray」は、この世界の魔術法則の根幹に深く関わる「二重魔法」を、誰にでも習得可能な技術として体系化した、という点で革新的な書物であった。まずは、この書物の内容を要約したものを見ていこう。 【エレメント】 世界中のあらゆる物体は、「泉」「風」「羽」「花」「砂」「灯」……といった、極小要素「エレメント」から構成されている。エレメントには多くの種類があり、人間はエレメントと契約を交わすことで、契約を交わした種類のエレメントを用いた二重魔法を発動させることができ...
[ { "submission_id": "aoj_2338_8283689", "code_snippet": "#include <iostream>\n#include <vector>\nusing namespace std;\n\nclass UnionFind {\npublic:\n\tvector<int> par;\n\n\tvoid init(int sz) {\n\t\tpar.resize(sz, -1);\n\t}\n\n\tint root(int pos) {\n\t\tif (par[pos] == -1) return pos;\n\t\tpar[pos] = root(par...
aoj_2336_cpp
Problem G: スプリング・タイル ある朝、あなたが目覚めると、そこはバネだらけの迷宮の中だった。 なぜ自分がこんな見知らぬ場所にいるのかはわからない。この場でじっと助けを待つという選択肢も あるにはあるが、こういった迷宮の中に長居していると、いつかは必ず突風が吹いてきて吹き飛ばさ れてしまうことを、あなたは経験上知っていた。しかし、突風が吹いてくるまでの時間は判断のしよ うがない。そこであなたは、迷宮から脱出するまでに必要な移動回数の期待値が最小になるように行 動するのが最善の戦略だと考えた。 足元に落ちていた正体不明の巻物を拾ってためしに読んでみたところ、偶然にも迷宮の全体マップを 知覚することができた。さらに、たまたま持...
[ { "submission_id": "aoj_2336_10880834", "code_snippet": "#include <queue>\n#include <string>\n#include <iomanip>\n#include <iostream>\n#pragma warning(disable : 4996)\nusing namespace std;\nstruct state {\n\tint x, y; long double dist;\n};\nbool operator<(const state& s1, const state& s2) {\n\treturn s1.dis...
aoj_2340_cpp
Carpenters' Language International Carpenters Professionals Company (ICPC) is a top construction company with a lot of expert carpenters. What makes ICPC a top company is their original language. The syntax of the language is simply given in CFG as follows: S -> SS | (S) | )S( | ε In other words, a right parenthesis ca...
[ { "submission_id": "aoj_2340_10728160", "code_snippet": "#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n#define N 100000\n#define ll long long\n#define clr(xx,yy) memset(xx,yy,sizeof(xx))\nll a[N],b[N];\nint main()\n{\n long long i,j,n,m,k,t,tt,max,maxn,p,T;\n char c...
aoj_2333_cpp
Problem D: 僕の友達は小さい 僕には、たくさんの友達がいる。どの友達も、とても小さい。 僕は、よく友達と一緒に出かける。何人かの友達をリュックに入れて、一緒に出かける。 僕は毎朝、その日一緒に出かける友達を決める。空のリュックに、1人ずつ友達を入れていく。 僕は、あまり力が強くない。だから、同時に運べる友達の重さには限界がある。 僕は、重さの限界を超えないように友達を入れていく。どの順番で入れていくかは気分次第。 僕は、入れられる友達がまだ残っている限り、入れるのを止めない。決して止めない。 ……ところで、リュックに入った友達の組み合わせは、全部で何パターンあるんだろう? Input N W w 1 w 2 . . . w...
[ { "submission_id": "aoj_2333_10880846", "code_snippet": "#include <vector>\n#include <iostream>\n#include <algorithm>\n#include <functional>\nusing namespace std;\nconst int mod = 1000000007;\nint N, W;\nint main() {\n\tcin >> N >> W;\n\tvector<int> a(N);\n\tfor (int i = 0; i < N; i++) cin >> a[i];\n\tsort(...
aoj_2343_cpp
Matrix Operation You are a student looking for a job. Today you had an employment examination for an IT company. They asked you to write an efficient program to perform several operations. First, they showed you an N \times N square matrix and a list of operations. All operations but one modify the matrix, and the ...
[ { "submission_id": "aoj_2343_10848580", "code_snippet": "#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <map>\n\nusing namespace std;\n\nconst int maxn=4e4+5;\n\nbool RH,RV,R;\nint row[maxn],colum[maxn];\nint A,B,C,D,E,F,G,n,q;\n\nstruct HashMap\n{\n int mod;\n int begin[100007],n...
aoj_2341_cpp
Kth Sentence A student, Kita_masa, is taking an English examination. In this examination, he has to write a sentence of length m . Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating the words he knows and write the K -th sentence among the candi...
[ { "submission_id": "aoj_2341_10848657", "code_snippet": "#include <cstdio>\n#include <cstring>\n#include <algorithm>\n#include <vector>\n#include <string>\n#include <map>\n#include <set>\n#include <queue>\n#include <cmath>\n#include <iostream>\n#include <cstdlib>\n#include <sstream>\n\nusing namespace std;\...
aoj_2345_cpp
Network Reliability An undirected graph is given. Each edge of the graph disappears with a constant probability. Calculate the probability with which the remained graph is connected. Input The first line contains three integers N ( 1 \leq N \leq 14 ), M ( 0 \leq M \leq 100 ) and P ( 0 \leq P \leq 100 ), separated by a ...
[ { "submission_id": "aoj_2345_10760531", "code_snippet": "/*\n * 2345.cc: Network Reliability\n */\n\n#include<cstdio>\n#include<cstdlib>\n#include<cstring>\n#include<cmath>\n#include<iostream>\n#include<string>\n#include<vector>\n#include<map>\n#include<set>\n#include<stack>\n#include<list>\n#include<queue>...
aoj_2346_cpp
Runaway Domino ``Domino effect'' is a famous play using dominoes. A player sets up a chain of dominoes stood. After a chain is formed, the player topples one end of the dominoes. The first domino topples the second domino, the second topples the third and so on. You are playing domino effect. Before you finish to set u...
[ { "submission_id": "aoj_2346_1626194", "code_snippet": "#include<stdio.h>\n#include <iostream>\n#include <math.h>\n#include <numeric>\n#include <vector>\n#include <map>\n#include <functional>\n#include <stdio.h>\n#include <array>\n#include <algorithm>\n#include <string>\n#include <string.h>\n#include <asser...
aoj_2342_cpp
A Light Road There is an evil creature in a square on N-by-M grid ( 2 \leq N, M \leq 100 ), and you want to kill it using a laser generator located in a different square. Since the location and direction of the laser generator are fixed, you may need to use several mirrors to reflect laser beams. There are some obstacl...
[ { "submission_id": "aoj_2342_10895982", "code_snippet": "/*###############################################################################################################\n## Author : Minseong Gwak (astilate, minsung05) ##\n#####################...
aoj_2352_cpp
問題文 正整数列 $X_1,X_2,...,X_N$ がある。数列 $\{1,2,...,N\}$ から部分列 $S$ を選ぶ。ただし $S$ は以下の条件を満たす必要がある。 $T=\{X_s | s \in S\}$ とする。このとき、任意の $x \in T$ について、$x$ の約数(ただし $x$ は除く)は $T$ に含まれない。 条件を満たす $S$ のうち、最も多くの要素を含むものを求めよ。また、そのような $S$ が複数ある場合は辞書式順序で最小のものを求めよ。 入力 入力は以下の形式に従う。与えられる数は全て整数である。 $N$ $X_1$ $X_2$ $...$ $X_N$ 制約 $1 \leq N \leq ...
[ { "submission_id": "aoj_2352_4272561", "code_snippet": "#include<iostream>\n#include<string>\n#include<iomanip>\n#include<cmath>\n#include<vector>\n#include<algorithm>\n#include<utility>\n\nusing namespace std;\n\n#define int long long\n#define endl \"\\n\"\n\nconstexpr long long INF = (long long)1e18;\ncon...
aoj_2347_cpp
Sunny Graph The Sun is a great heavenly body. The Sun is worshiped by various religions. Bob loves the Sun and loves any object that is similar to the Sun. He noticed that he can find the shape of the Sun in certain graphs. He calls such graphs "Sunny". We define the property "Sunny" mathematically. A graph G=(V,E) wit...
[ { "submission_id": "aoj_2347_10848164", "code_snippet": "#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#include <string>\n#include <map>\n#include <set>\n\nusing namespace std;\ntypedef long lo...
aoj_2344_cpp
Multi-ending Story You are a programmer who loves bishojo games (a sub-genre of dating simulation games). A game, which is titled "I * C * P * C!" and was released yesterday, has arrived to you just now. This game has multiple endings. When you complete all of those endings, you can get a special figure of the main her...
[ { "submission_id": "aoj_2344_10854001", "code_snippet": "//made by kuailezhish\n//gl && hf\n#include <vector>\n#include <map>\n#include <set>\n#include <queue>\n#include <algorithm>\n#include <utility>\n#include <iostream>\n#include <cstdio>\n#include <cmath>\n#include <cstdlib>\n#include <string>\n#include...
aoj_2354_cpp
問題文 実数変数 $x_1, x_2, ..., x_N$ は以下の条件を満たす。 $0 \leq x_i \leq 1$ ($1 \leq i \leq N$) $w_1x_1+w_2x_2+...+w_Nx_N \leq W$ このとき $v_1x_1+v_2x_2+...+v_Nx_N$ のとりうる最大値を求めよ。そのような最大値は実際に存在することが知られている。 入力 入力は以下の形式に従う。与えられる数は全て整数である。 $N$ $W$ $w_1$ $v_1$ $w_2$ $v_2$ $...$ $w_N$ $v_N$ 制約 $1 \leq N \leq 10^5$ $1 \leq W \leq 10^5$ $-10^4...
[ { "submission_id": "aoj_2354_2659387", "code_snippet": "#include \"bits/stdc++.h\"\n#include<unordered_map>\n#include<unordered_set>\n#include<random>\n#pragma warning(disable:4996)\nusing namespace std;\nusing ld= long double;\n\nint main()\n{\n\tint N;\n\tld W;\n\tcin>>N>>W;\n\tvector<pair<ld,ld>>pluss;\n...
aoj_2351_cpp
問題文 $N$ 本の線分 $s_1, s_2, ..., s_N$ が与えられる。このとき、 dist$(s_i, s_j)$, ( $1 \leq i,j \leq N, i \ne j $ ) のとりうる最小値を求めよ。 dist$(s_i, s_j)$ は $\sqrt{(x_i-x_j)^2 + (y_i-y_j)^2}$, ( $(x_i,y_i)$ は $s_i$ 上の点、$(x_j,y_j)$ は $s_j$ 上の点) のとりうる最小値で定義される。 以下はSample Inputのデータセットを図示したものである。 入力 入力は以下の形式に従う。与えられる数は全て整数である。 $N$ $x_{1,1}$ $y_{1,...
[ { "submission_id": "aoj_2351_2719318", "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;\n\nconst double EPS = 1e-10;\nconst double INF = 1e12;\n#define EQ(n,m) (abs((n)-(m)) < EPS)\...
aoj_2357_cpp
問題文 以下の条件を満たす整数列 $X_1, X_2, ..., X_N$ の個数を求めよ。 任意の整数 $i$ ($1 \leq i \leq N$)に対して、$X_j=i$ となる $j$ ($1 \leq j \leq N$)が存在する。 $X_s = t$ $X_{a_i} < X_{b_i}$ ($1 \leq i \leq C$) 入力 入力は以下の形式に従う。与えられる数は全て整数である。 $N$ $C$ $s$ $t$ $a_1$ $b_1$ $a_2$ $b_2$ $...$ $a_C$ $b_C$ 制約 $1 \leq N \leq 2000$ $0 \leq C \leq N$ $1 \leq s \leq N...
[ { "submission_id": "aoj_2357_387243", "code_snippet": "#include <cstdio>\n#include <vector>\n#include <algorithm>\n#include <cstring>\nusing namespace std;\n\ntypedef long long int64;\n\nconst int MAX_N = 2000 + 1;\nconst int64 MOD = (int64)(1e9 + 7);\n\nint N, C, target, ord;\n\nint parent[MAX_N+1];\nvecto...
aoj_2353_cpp
問題文 有理数列 $X_0, X_1, X_2, ..., X_N$ がある。各項は以下のように定義される。 $X_0 = 0$ $X_i = X_{i-1}$ $op_i$ $Y_i$ ($1 \leq i \leq N$). ただし $op_i$ は $+$、$−$、$×$、$÷$のいずれかである。 $X_N$ を求めよ。 入力 入力は以下の形式に従う。与えられる数は全て整数である。 $N$ $o_1$ $Y_1$ $o_2$ $Y_2$ $...$ $o_N$ $Y_N$ $o_i = 1$ のとき $op_i$ は+、$o_i = 2$ のとき $op_i$ は−、$o_i = 3$ のとき $op_i$ は×、$o_i =...
[ { "submission_id": "aoj_2353_9629970", "code_snippet": "#include <iostream>\n#include <cmath>\n\nusing namespace std;\n\nsigned main() {\n ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);\n long double x = 0;\n int n; cin >> n;\n while (n--) {\n int o; long double y; cin >> o >>...
aoj_2348_cpp
Testing Circuits A Boolean expression is given. In the expression, each variable appears exactly once. Calculate the number of variable assignments that make the expression evaluate to true. Input A data set consists of only one line. The Boolean expression is given by a string which consists of digits, x, (, ), |, &, ...
[ { "submission_id": "aoj_2348_10750504", "code_snippet": "#include <iostream>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\nusing namespace std;\n#define SE second\n#define FI first\n#define MP(x,y) make_pair(x,y)\nconst int MAXN = 1000010;\nconst int MOD = 1000000007;\nchar str[MAXN];\nint sta...
aoj_2355_cpp
問題文 ふたりのプレイヤーがゲームをしている。以下、ゲームのルールを説明する。 $N×N$ マスのボードがあり、各マスには数字 $X_{i,j}$ ($1 \leq i,j \leq N$)が書かれている。先手と後手は交互に手を選んで点を積み重ねてゆく。最初に先手は $F$ 点持っており、後手は $0$ 点持っている。 $t$ ターン目($1 \leq t \leq 2N$)のプレイヤーの行動を示す。 これ以降自分と相手がどのような手を選んだとしても自分が負けてしまう場合、即座に負けを宣言してゲームを終了する。 これまでに自分が一度も選んだことのない数字を $1,2,...,N$ から一つ選んで $Y_t$ とする。 先手の手番(つ...
[ { "submission_id": "aoj_2355_2727715", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define int long long\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define pb push_back\n#define all(v) (v).begin(),(v).end()\n#define fi first\n#define se second\ntypedef vector<int>vint;\ntypedef pair<i...
aoj_2361_cpp
問題文 $1,2,...,N$ を並べ替えた順列がある。2つの異なる数字 $i$, $j$ を選んで入れ替えることを繰り返してソートされた状態( $1,2,...,N$ の順番に並んだ状態)にしたい。 数字 $i$, $j$ を入れ替える度にコストが $c_{i,j}$ 必要になる。 順列 $p$ に対して、 $p$ をソートするのに必要な最小コストを $f(p)$ とする。 $f(p)$ のとりうる最大値を求めよ。 入力 入力は以下のフォーマットに従う。与えられる数は全て整数である。 $N$ $c_{1,1}$ $c_{1,2}$ $...$ $c_{1,N}$ $c_{2,1}$ $c_{2,2}$ $...$ $c_{2,N}...
[ { "submission_id": "aoj_2361_3596190", "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_2364_cpp
Lucky Dip Time Limit: 8 sec / Memory Limit: 64 MB C: 福袋 福袋,それは年始を祝う商習慣の一つである. 人気の福袋には多くの人が開店前から行列を作り,ターゲットの福袋へダッシュする. この風物詩に魅了されたあなたは,今年もお目当ての福袋を狙い,計画を立てていた. しかし,お客を呼び寄せる側の某百貨店の店長は頭を悩ませていた. どうやらフロアの準備が開店に間に合いそうにない. そこで店長はある一つのアイディアを思いついた. それは開店後,店内を徐々に開放すればなんとか営業できるのではないかというものである. あなたは刻一刻と変化する店内の情報を元に,お目当ての福袋がどの時間帯から入手...
[ { "submission_id": "aoj_2364_7994970", "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_2349_cpp
World Trip Kita_masa is planning a trip around the world. This world has N countries and the country i has M_i cities. Kita_masa wants to visit every city exactly once, and return back to the starting city. In this world, people can travel only by airplane. There are two kinds of airlines: domestic and international li...
[ { "submission_id": "aoj_2349_4934973", "code_snippet": "#include<bits/stdc++.h>\ntypedef long long int ll;\ntypedef unsigned long long int ull;\n#define BIG_NUM 2000000000\n#define HUGE_NUM 1000000000000000000\n#define MOD 1000000007\n#define EPS 0.000000001\nusing namespace std;\n\n\n#define SIZE 15\n#defi...
aoj_2366_cpp
Elevator Time Limit: 8 sec / Memory Limit: 64 MB E: エレベータ あなたの友人は,キリンのマークの引越業者でアルバイトをしている. 彼の仕事は,建物から荷物を運び出すことである. 今回,彼はある n 階建てのビルからいくつかの荷物を運び出すことになった. 幸い,このビルにはエレベータが1つ備え付けられているため, エレベータで荷物を運び出すことにした. 運び出すべき荷物は,各階に複数個あり,荷物毎に重さが異なる. エレベータには,重量制限が設定されており,重さ W を超える荷物を載せることはできない. エレベータは十分に広く,重量制限を満たすならば,どれだけ多くの荷物でも載せることが...
[ { "submission_id": "aoj_2366_9054837", "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_2359_cpp
問題文 実数変数 $X_1, X_2, ...$ があり、何らかの初期値が割り振られている。 これから $Q$ 個の情報が順番に与えられる。与えられる情報は以下の2種類のいずれかである。 min $\{X_{a_i}, X_{a_i+1}, ..., X_{b_i}\} = y_i$ である。 変数 $X_{a_i}, X_{a_i+1}, ..., X_{b_i}$ に $y_i$ を代入する。 これら $Q$ 個の情報が矛盾しないように各変数の初期値を選べるかどうか判定せよ。 入力 入力は以下の形式に従う。与えられる数は全て整数である。 $Q$ $t_1$ $a_1$ $b_1$ $y_1$ $t_2$ $a_2$ $b_2$ ...
[ { "submission_id": "aoj_2359_9883680", "code_snippet": "#include <iostream>\n#include <vector>\n#include <cstdio>\n#include <queue>\n#include <cstdlib>\n#include <set>\n#include <algorithm>\nusing namespace std;\n#define N (1<<18)\n\nstruct Query{\n\tint t,a,b,y;\n};\nint Q;\nQuery que[50000];\n\nset<int> n...
aoj_2369_cpp
Problem A: CatChecker 外見からねこかどうかわからない動物がいる. あなたは, 鳴き声がねこの鳴き声であればねこであり, そうでなければうさぎであると判定することにした. ねこの鳴き声は次のように定義される. "" (empty string) はねこの鳴き声である. $X$, $Y$ がねこの鳴き声であれば 'm' + $X$ + 'e' + $Y$ + 'w' は猫の鳴き声である. ただし + は文字列の連結を表す. 以上で定義されるものだけがねこの鳴き声である. BNF で表すとねこの鳴き声 $CAT$ は $CAT$ := "" (empty string) $|$ 'm' + $CAT$ + 'e' +...
[ { "submission_id": "aoj_2369_10853968", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing P = pair<int, int>;\n\nint N;\nstring S;\nmap<pair<int, int>, int> mp;\n\nbool is(int s, int t) {\n\tif (s == t) return true;\n\tif (t - s < 3 || S[s] != 'm' || S[t - 1] != 'w') return false;\n\n\t...
aoj_2373_cpp
Problem E: HullMarathon うさぎはフルマラソンという競技が好きである. この競技はチームで行う. チームメンバーは競技開始前に原点に集まる. 競技開始と同時に走り出し, 1 分後に立ち止まる.このとき,チームメンバーの位置の凸包の面積が最も大きなチームが勝ちとなる. あなたは $N$ 匹のうさぎからなるチームの監督である. $i$ 匹目のうさぎは 1 分で $r_i$ 移動することができる. このチームが最適な戦略をとった場合の, 1 分後の凸包の面積の最大値を求めよ. Constraints $N$ will be between 3 and 8, inclusive. $r_i$ will be an in...
[ { "submission_id": "aoj_2373_10579537", "code_snippet": "#include<bits/stdc++.h>\n\nusing namespace std;\n#define rep2(i, j, k) for(ll i=ll(j);i<ll(k);i++)\n#define rep(i, j) rep2(i,0,j)\n#define rrep2(i, j, k) for(ll i=ll(j)-1;i>=ll(k);i--)\n#define rrep(i, j) rrep2(i,j,0)\n#define SZ(a) ll(a.size())\n#def...
aoj_2370_cpp
Problem B: RabbitWalking うさぎの住んでいる都市には, $V$ 個の交差点と $E$ 本の道がある. 交差点は 1-indexed で番号が付けられている. $i$ 番目の道は交差点 $a_i$ と交差点 $b_i$ を bidirectional につないでいる. うさぎは, 散歩と奇数が好きである.うさぎはある交差点から出発し, 道を奇数本辿り, 出発した頂点に戻るような経路に沿って散歩したいと思っている. この都市の市長であるねこは, 都市内の移動を効率化するために異なる2 つの交差点を結ぶ道をたくさん追加しようとしている.ただし,ある交差点の組に対して敷設することが出来る道は高々1本までである.また,...
[ { "submission_id": "aoj_2370_10209831", "code_snippet": "// AOJ #2370\n// RabbitWalking 2025.2.10\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint main() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n \n int V, E;\n cin >> V >> E;\n\n if(E == 0) {\n ll a...
aoj_2371_cpp
Problem C: TransferTrain うなぎは電車に乗るのが好きである. いま,うなぎは駅 A から駅 B へ電車を使って行こうとしている. うなぎは急いでいるので, 最短時間の経路を選ぶことにした. ただし,うなぎは乗り換えが苦手なので, 最短時間の経路が複数ある場合は最も乗り換え回数の少ない経路を選ぶことにした. $N$ 本の路線がある. $i$ 本目の路線は $a_i$ 個の駅を通っている. $i$ 本目の路線の通る駅名は通る順に $s_{i,0}, ... , s_{i,a_i -1}$ であり, 駅間の所要時間は $t_{i,0}, ..., t_{i,a_i - 2}$ である. 電車は路線上を上下方向に走...
[ { "submission_id": "aoj_2371_10855658", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nusing lint = long long;\n\nconstexpr lint LLINF = 1LL << 61;\nconstexpr pair<lint, lint> INF = make_pair(LLINF, LLINF);\n\nstruct edge{\n int to;\n lint cost;\n lint trans;\n};\n\nstruct node{\...
aoj_2367_cpp
Icy Composer Time Limit: 8 sec / Memory Limit: 64 MB F: 氷の作曲家 岡部錬太郎(愛称オカレン)は,西洋音楽の第一人者である. 彼は,5歳から作曲を行うことができた天才であり,彼が作詞・作曲した『攻城の槌』はとても有名である. 才能あふれるオカレンだが,残念なことに,彼は,レストランで食べた魚にあたって亡くなっている. ・・・少なくとも,この世界線では,そういうことになっている. 世界線とは何か? 一つの歴史は,一つの世界線に対応する. 我々が歩んできた歴史とは,無限に存在する世界線のうちの一つに過ぎず, 別の世界線では,また違った歴史が刻まれている. オカレンは,自らを待ちうけ...
[ { "submission_id": "aoj_2367_372125", "code_snippet": "#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#include <string>\n#include <map>\n#include <set>\n\nusing namespace std;\ntypedef long long...
aoj_2372_cpp
Problem D: IkaNumber 数直線上の整数座標に, ねこの Taro の家, にんじん, うさぎの Hanako の家がこの順に並んでいる. 点 $x$ にいるイカは, 一回のジャンプで $x + 1$ または $x + 2$ に移動することができる. あなたは, イカが Taro の家から Hanako の家までにんじんの置かれている座標に止まらずに行く経路が何通りあるか求めようとしたが, Taro の家, にんじん, Hanako の家の座標を知らないので 求めることができなかった. そこで, 代わりに経路の数として考えられる数をすべて列挙することにした. ある Taro の家, にんじん, Hanako の家の配...
[ { "submission_id": "aoj_2372_4964447", "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=(int)(n)-1; i>=0; --i)\n#define FOR(i, a, n) for (int i=(a); i<(n); ++i)\n#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a)...
aoj_2375_cpp
Problem G: CarrotBreeding にんじんは繁殖の好きな植物である. うさぎが畑でにんじんを飼うことにした. 畑は (0, 0) と (1000000000, 1000000000) を対角線とする正方形 (boundary を含む) である. うさぎは, 2 個以上のにんじんを通るすべての直線に沿って毎日1 回ずつ水をまくことにした. このにんじんたちは, 毎日 $N$ 回ずつ水をまかれるのが繁殖に最適だと考えているので, そのような条件を満たすようにうさぎの畑に並ぶことにした. にんじんは畑内部の格子点にしか並ぶことができない. また, そのような条件を満たす並び方が複数ある場合は, 最もにんじんの個数が少ない...
[ { "submission_id": "aoj_2375_9450948", "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\nll M=1e9;\n\nll num(vector<pair<ll,ll>> &V){\n ll N=V.size();\n set<tuple<ll,ll,ll>> L...
aoj_2379_cpp
Problem A: Bicube Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some colorful color (such as red and blue) on the front side. Cutting off the unpainted part, she will have eight opened-up unit cubes. A unit cube here refers to a cube of which each face consists of o...
[ { "submission_id": "aoj_2379_3648858", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\n// 0: top, 1: front, 2:right, 3:back, 4:left, 5:bottom\nconst vector<vector<string>> dice_map = {\n {\"0...\",\n \"1234\",\n \"5...\"},\n {\"0...\",\n \"1234\",\n \".5..\"},\n {...
aoj_2376_cpp
Problem H: DisconnectedGame Taro と Hanako がゲームをしている. 最初に, 非連結な無向グラフ(二重辺や self loop を含まない) が与えられる. Taro と Hanako は交互に操作を行う. 操作では, 辺で直接つながれていない異なる2 頂点を選び, その間に辺を加える. グラフを連結にしたほうが負けである. グラフには $V$ 個の頂点がある. $V \times V$ の行列が与えられる. 行列の $(i, j)$-成分が'Y' であるとき $i$ と $j$ の間には辺があり, 'N' であるときは辺が無い. 両者が最善に操作をしたとき, どちらが勝つかを出力せよ. Con...
[ { "submission_id": "aoj_2376_10238725", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nstring dp[1009][1009][2];\nbool used[1009];\n\nvoid dfs(int pos, int &cnt, vector<vector<int>> &G) {\n used[pos] = true;\n cnt += 1;\n for (int to : G[pos]) {\n if (used[to] == true) co...
aoj_2378_cpp
Problem J: SolveMe $N$ 個の部屋があり, それぞれの部屋の床にはうさぎの絵が描かれている. あなたが部屋 $r$ のうさぎの絵の右耳の部分に乗ると, あなたは部屋 $A[r]$ に書かれたうさぎのしっぽの上にテレポートする. 同様に, 部屋 $r$ のうさぎの絵の左耳の部分に乗ると, 部屋 $B[r]$ に書かれたうさぎのしっぽの上にテレポートする. 整数 $X$, $Y$, $Z$ が与えられる. ねこは, 以下の条件を満たすようにテレポートを設定しようとしている. テレポートの $N^{2N}$ 通りの設定方法のうち, 条件を満たすものは何通りか, mod 1,000,000,007で求めよ. 条件: 任意...
[ { "submission_id": "aoj_2378_10910520", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <utility>\nusing namespace std;\n\nusing ll = long long;\n#define REP(i,n) for(ll i=0; i<ll(n); i++)\ntemplate<class T>using V = vector<T>;\n\nconst int MOD = 1000000007;\n\nstruct...
aoj_2374_cpp
Problem F: RabbitLunch うさぎは昼食ににんじんとキウイを1 個ずつ食べる. うさぎはとても個性的なので, 食べるにんじんの種類もキウイの種類も同じであるような, 異なる2 匹のうさぎが存在してはならない. にんじんは $M$ 種類ある. $i$ 種類目のにんじんは $m_i$ 個ある. キウイは $N$ 種類ある. $i$ 種類目のキウイは $n_i$ 個ある. 最大何匹のうさぎが昼食をとれるか求めよ. $m_i$ と $n_i$ は次の漸化式を用いて生成せよ. $m_0 = m0$ $m_{i+1} = (m_i * 58 + md )$ mod $(N + 1)$ $n_0 = n0$ $n_{i+1} =...
[ { "submission_id": "aoj_2374_10850909", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define rep(i,n) for(int i=0;i<(n);i++)\n#define REP(i,n) for(int i=1;i<=(n);i++)\n#define mp make_pair\n#define pb push_back\n#define fst first\n#define snd second\ntypedef long long ll;\ntypedef pair<...
aoj_2377_cpp
Problem I: ThreeRooks ねこがチェスの練習をしている. ねこは, $X \times Y$ のチェス盤の上にルークを 3 つ置こうとしている. このチェス盤の $K$ 個のマス目にはうさぎが座っている. $i$ 匹目のうさぎの座標は $(x[i], y[i])$ である. ただし, チェス盤の左上端のマス目の座標を $(0, 0)$, 右下端のマス目の座標を $(X-1, Y-1)$ とする。うさぎが座っている場所にはルークを置くことができない. また, 1 つのマス目に複数個のルークを置くことはできない. どの 2 つのルークも互いに攻撃し合わないようにルークを3 つ置く方法は何通りあるか, mod 1,000...
[ { "submission_id": "aoj_2377_10351503", "code_snippet": "// AOJ #2377 ThreeRooks\n// 2025.4.6\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nconst int MOD = 1000000007;\n\n#define gc() getchar_unlocked()\n#define pc(c) putchar_unlocked(c)\n\nint Cin() {\n\tint n = 0; int c = gc();...
aoj_2386_cpp
Problem H: Sightseeing Tour KM city has $N$ sightseeing areas. Currently every pair of area is connected by a bidirectional road. However for some reason, Mr. KM, the mayor of this city, decided to make all of these roads one-way . It costs $C_{i, j}$ dollars to renovate the road between area $i$ and area $j$ to a one-...
[ { "submission_id": "aoj_2386_1855992", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n#define int long long // <-----!!!!!!!!!!!!!!!!!!!\n\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 rrep(i,n) for (int i=(n)-1;i>=0;i--)\n#define rrep2...
aoj_2380_cpp
Problem B: Bubble Puzzle A browser-based puzzle game called "Bubble Puzzle" is now popular on the Internet. The puzzle is played on a 4 × 4 grid, and initially there are several bubbles in the grid squares. Each bubble has a state expressed by a positive integer, and the state changes when the bubble gets stimulated. Y...
[ { "submission_id": "aoj_2380_10850629", "code_snippet": "#include<bits/stdc++.h>\nusing namespace std;\n\nint ans = 6;\n\nstruct drop{\n int y, x, d;\n\n int id;\n\n bool operator==(const drop & rhs) const {\n return y == rhs.y && x == rhs.x && d == rhs.d;\n }\n};\n\ntemplate<typename T>\...
aoj_2382_cpp
Problem D: King Slime There is a grid of size W × H surrounded by walls. Some cells in the grid are occupied by slimes. The slimes want to unite with each other and become a "King Slime". In each move, a slime can move to east, west, south and north direction until it enters a cell occupied by another slime or hit the ...
[ { "submission_id": "aoj_2382_10854004", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nconstexpr int INF = 1e9;\n\nclass union_find {\npublic:\n union_find(int N)\n : par(N, -1)\n {}\n\n int root(int x) {\n return par[x] < 0 ? x : par[x] = root(par[x]);\n }\n\n ...
aoj_2383_cpp
Problem E: Rabbit Game Playing Honestly, a rabbit does not matter. There is a rabbit playing a stage system action game. In this game, every stage has a difficulty level. The rabbit, which always needs challenges, basically wants to play more difficult stages than he has ever played. However, he sometimes needs rest to...
[ { "submission_id": "aoj_2383_9666591", "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_2385_cpp
Problem G: Shelter Taro lives in a town with N shelters. The shape of the town is a convex polygon. He'll escape to the nearest shelter in case of emergency. Given the current location, the cost of escape is defined as the square of the distance to the nearest shelter. Because emergency occurs unpredictably, Taro can b...
[ { "submission_id": "aoj_2385_3684476", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nusing ld = long double;\nusing point = std::complex<ld>;\nusing polygon = std::vector<point>;\n\nconstexpr ld eps = 1e-10;\n\nld dot(point const& a, point const& b) {\n return std::real(std::conj(a) ...
aoj_2387_cpp
Problem I: Tampopo Machine "Today is another day of endless, tedious work to put a tampopo on sashimi..." Yaruo works in a sashimi (sliced raw fish) factory. His job is to put tampopos on sashimi packages everyday. Tired of this menial job, he decided to develop a tampopo machine to do the job instead of him. The tampo...
[ { "submission_id": "aoj_2387_8860926", "code_snippet": "#include <algorithm>\n#include <bitset>\n#include <cassert>\n#include <cmath>\n#include <complex>\n#include <cstdio>\n#include <cstring>\n#include <iostream>\n#include <map>\n#include <random>\n#include <unordered_map>\n#include <vector>\nusing namespa...
aoj_2390_cpp
AYBABTU There is a tree that has n nodes and n-1 edges. There are military bases on t out of the n nodes. We want to disconnect the bases as much as possible by destroying k edges. The tree will be split into k+1 regions when we destroy k edges. Given the purpose to disconnect the bases, we only consider to split in...
[ { "submission_id": "aoj_2390_10849697", "code_snippet": "/*\n * =====================================================================================\n *\n * Filename: j.cpp\n *\n * Description:\n *\n * Version: 1.0\n * Created: 2013年11月23日 14时47分56秒\n * Revision: none\n * ...
aoj_2384_cpp
Problem F: Rabbit Jumping There are $K$ rabbits playing on rocks floating in a river. They got tired of playing on the rocks on which they are standing currently, and they decided to move to other rocks. This seemed an easy task initially, but there are so many constraints that they got totally confused. First of all, ...
[ { "submission_id": "aoj_2384_10850168", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <unordered_set>\n#include <iomanip>\n#include <vector>\n#include <bitset>\n#include <queue>\n#include <cmath>\n#include <unordered_map>\n\nusing namespace std;\n\nconst double INF = 1e100;\nint N, K;...
aoj_2393_cpp
Dungeon Creation The king demon is waiting in his dungeon to defeat a brave man. His dungeon consists of H \times W grids. Each cell is connected to four (i.e. north, south, east and west) neighboring cells and some cells are occupied by obstacles. To attack the brave man, the king demon created and sent a servant tha...
[ { "submission_id": "aoj_2393_10854038", "code_snippet": "#include <iostream>\n#include <algorithm>\n#include <vector>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\n#include <climits>\n\nusing namespace std;\n\ntypedef long long LL;\nconst int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};\nconst int ...
aoj_2392_cpp
Digit For a positive integer a , let S(a) be the sum of the digits in base l . Also let L(a) be the minimum k such that S^k(a) is less than or equal to l-1 . Find the minimum a such that L(a) = N for a given N , and print a modulo m . Input The input contains several test cases, followed by a line containing "0 0 0". E...
[ { "submission_id": "aoj_2392_10351770", "code_snippet": "// AOJ #2392 Digit\n// 2025.4.6\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 int n = 0; int c = gc();\n do n = 10*n + (c & 0xf), c...
aoj_2394_cpp
Longest Lane Mr. KM, the mayor of KM city, decided to build a new elementary school. The site for the school has an awkward polygonal shape, which caused several problems. The most serious problem was that there was not enough space for a short distance racetrack. Your task is to help Mr. KM to calculate the maximum po...
[ { "submission_id": "aoj_2394_10853935", "code_snippet": "#include<cstdio>\n#include<cstring>\n#include<algorithm>\n#include<cmath>\n#include<vector>\n#include<cassert>\n#define N 110\n#define eps 1e-5\nusing namespace std;\n\nint dlcmp(double x) {return x<-eps?-1:x>eps;}\ndouble sqr(double x) {return x*x;}\...
aoj_2397_cpp
Three-way Branch There is a grid that consists of W \times H cells. The upper-left-most cell is (1, 1) . You are standing on the cell of (1,1) and you are going to move to cell of (W, H) . You can only move to adjacent lower-left, lower or lower-right cells. There are obstructions on several cells. You can not move t...
[ { "submission_id": "aoj_2397_10853997", "code_snippet": "#include <cstdio>\n#include <vector>\n#include <cstdlib>\n#include <algorithm>\n#include <cstring>\n#include <map>\n#define llint long long\n#define MOD 1000000009\n\nusing namespace std;\n\nconst int maxn = 75; //必须加 const,否则编译错误\n\nint n, N;\nllint ...
aoj_2396_cpp
Skyland Somewhere in the sky, KM kingdom built n floating islands by their highly developed technology. The islands are numbered from 1 to n . The king of the country, Kita_masa, can choose any non-negative real number as the altitude for each island, as long as the sum of the altitudes is greater than or equals to ...
[ { "submission_id": "aoj_2396_1134890", "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_2391_cpp
Billiards Sorting Rotation is one of several popular pocket billiards games. It uses 15 balls numbered from 1 to 15, and set them up as illustrated in the following figure at the beginning of a game. (Note: the ball order is modified from real-world Rotation rules for simplicity of the problem.) [ 1] [ 2]...
[ { "submission_id": "aoj_2391_10851349", "code_snippet": "#include <cstdio>\n#include <iostream>\n#include <cstring>\n#include <cmath>\n#include <string>\n#include <stack>\n#include <algorithm>\n#include <queue>\n#include <map>\n#include <set>\n#include <cstdlib>\n#define INF 0x3f3f3f3f\n#define er(i) (1<<i)...
aoj_2399_cpp
Save Your Privacy! 君のプライバシーを守れ! English text is not available in this practice contest. ICPC (International Committee of Privacy and Confidence) は世界中に多くの構成員を持つ組織であり、その名の通り非常にプライバシーを尊重する、秘密主義者たちの団体である。構成員たちは必要上他の構成員の個人情報を知ってしまうことがあるが、それらを厳重に秘匿するよう義務付けられている。 しかしある日、何人かの構成員の個人情報が漏洩してしまった!ICPCの ACM (Account Control Manager...
[ { "submission_id": "aoj_2399_10852712", "code_snippet": "#include<bits/stdc++.h>\n\n#define rep(i,n) for(int i = 0; i < n; ++i)\n#define all(x) x.begin(), x.end()\n#define X firsst\n#define Y second\n#define pb push_back\nusing namespace std;\n\nint main(void){\n int n;\n while(cin >> n && n){\n int m,...
aoj_2400_cpp
You Are the Judge 審判は君だ! English text is not available in this practice contest. あなたはプログラミングコンテスト iCPC の審判だ。今日も何事もなく試合が終わり、後は結果を出力するだけだと思いきや、突然システムが停止してしまった! これでは結果が出力できない! でも、大丈夫。我々にはログがある。 あなたは優れたプログラマーであり、かつて iCPC で輝かしい成績を残したこともある。 そこであなたはシステムログから各チームの成績を割り出し、チームの順位表を出力するプログラムを作成することにした。 入力としてチームの数、問題の数、システムログが与えられる...
[ { "submission_id": "aoj_2400_10612926", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\n\nbool solve() {\n int T, P, R;\n cin >> T >> P >> R;\n if (T == 0 && P == 0 && R == 0) return false;\n vector<vector<bool>> AC(T, vector<bool>(P, false));\n vector<vector<int>> WA(T, vect...
aoj_2401_cpp
Equation 恒等式 English text is not available in this practice contest. 論理演算では,値は T と F の2種類だけを扱う. "-"を単項演算子(入力が 1 つの演算を表す記号), "*", "+", "->" を 2 項演算子(入力が 2 つの演算を表す記号)とする. "-" は論理否定(NOT), "*" は論理積(AND), "+" は論理和(OR), "->" は論理包含(IMP)を表す演算子である. これらの論理演算の真理値表を下の表に示す. x y -x (x*y) (x+y) (x->y) T T F T T T T F F F T F F T T F ...
[ { "submission_id": "aoj_2401_10678747", "code_snippet": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#include <ext/pb_ds/tag_and_trait.hpp>\nusing namespace std;\nusing namespace __gnu_pbds;\n\n\nstruct custom_hash {\n static uint64_t splitmix...
aoj_2402_cpp
Milky Way 天の川 English text is not available in this practice contest. 天の川交通公社は星間旅行ツアーの企画・運営を行う旅行会社である。 天の川交通公社では「天の川横断織姫彦星体験ツアー」という企画を計画中である。 このツアーは琴座のベガを出発し、 星々を巡って鷲座のアルタイルに向かうというものである。 あなたは天の川交通公社に社員であり、 ツアーの経路の選択を任されている。 簡単のため天の川は2次元座標上にあるものとし、 星は五芒星で表現されるものとする。 ツアーに使用する宇宙船には特殊なエンジンが搭載されており、 五芒星の線分上はエネルギー無しで移動することがで...
[ { "submission_id": "aoj_2402_10668015", "code_snippet": "#pragma GCC target(\"avx2\")\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\n\n// #ifndef ONLINE_JUDGE\n// #define _GLIBCXX_DEBUG // 配列外参照のエラー\n// #endif\n\n// スタンダードライブラリ\n#include <bits/stdc++.h>\nusing namespace std;\n\n// 型関...
aoj_2395_cpp
PLAY in BASIC One sunny day, Dick T. Mustang found an ancient personal computer in the closet. He brought it back to his room and turned it on with a sense of nostalgia, seeing a message coming on the screen: READY? Yes. BASIC. BASIC is a programming language designed for beginners, and was widely used from 1980's to 1...
[ { "submission_id": "aoj_2395_10851243", "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 bged(v) (v).begin(),(v).end()\n#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end...
aoj_2403_cpp
The Enemy of My Enemy is My Friend 敵の敵は味方 English text is not available in this practice contest. 時は XXXX 年。戦乱の世である。 土地や資源を巡って、隣り合った国同士の衝突がそこかしこで起こり、世の中の先行きは非常に不透明であった。そんな中とある国が、様々な国と軍事同盟を結んでこの乱世を生き延びようと考えた。軍事同盟は次の条件をみたすように行うことが出来る。 自国の隣国とは同盟を結ぶことは出来ない。 同盟をした国の隣国とは同盟を結ぶことは出来ない。 ただし、国ごとにその軍事的な強さは異なっている。軍事的に強くない複数の国と同盟を結...
[ { "submission_id": "aoj_2403_10848106", "code_snippet": "#include \"bits/stdc++.h\"\n#include<unordered_map>\n#include<unordered_set>\n#pragma warning(disable:4996)\nusing namespace std;\nusing ld = long double;\nconst ld eps = 1e-9;\n\n\nmap<string, int>mp;\nint num = 0;\n\nint getnum(string st) {\n\tif (m...
aoj_2404_cpp
Dog Food ドッグフード English text is not available in this practice contest. あなたは, 賢い犬を選ぶコンテストの主催者である. 種目の1つに,以下のようなものがある. この種目は,平面的な広場の上で行われる. 広場には杭がいくつか立っており,そのうちの1つと,犬はロープで結ばれている.杭やロープの太さは無視できるものとする.ロープが結ばれている杭の座標を(0,0),犬の位置を(Dx,Dy)とする. また,ロープが結ばれている杭以外の杭の本数をn本とし,それらの座標を(x 1 ,y 1 )... (x n ,y n )とする. 初期状態で,ロープはピンと張られた状態で...
[ { "submission_id": "aoj_2404_2818209", "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;\n\nconst double EPS = 1e-10;\nconst double INF = 1e12;\nconst double PI = acos(-1);\n#define ...
aoj_2405_cpp
Sister Ports 姉妹港 English text is not available in this practice contest. ACM 国は正 n 角形の島国である. n 個の角に港があり,ある角の港から時計回りに 1 から n までの番号が順番に付いている. 港は点とみなす. ACM 国には,二種類の道路がある. 隣り合う港を繋ぐ道路 全ての隣接する港は道路で接続されている.すなわち,番号の差が 1 である港同士および港 1 と港 n の間に道路がある.この種類の道路は n 本ある. 島の内部を通る道路 一部の隣接しない港の間も,道路で接続されている.この種類の道路は m 本あり,道路 i は港 a i と港 b...
[ { "submission_id": "aoj_2405_10826161", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll=long long;\nusing ull=unsigned long long;\nusing P=pair<ll,ll>;\ntemplate<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;\ntemplate<typename T>bool chmax(T &a,const T &b){return ...
aoj_2398_cpp
Tree Allocation A tree is one of the most popular data structures in computer science. Tree itself is very elegant, but it is incompatible with current computer architecture. In the current architecture, memory can be regarded as a one-dimensional array. Since a tree is not a one-dimensional structure, cache efficienc...
[ { "submission_id": "aoj_2398_10852730", "code_snippet": "#include <cstring>\n#include <cstdio>\n#include <algorithm>\n#include <cassert>\n#include <iostream>\n#include <vector>\nusing namespace std;\nconst int Maxn = 100010;\t\nint n, b;\nvector<int> vec[Maxn];\nint dp[Maxn], B[Maxn],tmpdp[Maxn];\nbool cmp(...
aoj_2410_cpp
E - じゃんけん 問題文 E 君はじゃんけんが大好きである (ちなみにじゃんけんのルールについては Wikipediaのじゃんけんのページ を参照せよ). ある日,町内でじゃんけん大会があるということを知った E 君は,じゃんけんの腕に自信があったこともあり早速出場することにした. ところが大会当日,E 君を待ち受けていたのは,普通の「グー・チョキ・パー」のみからなる普通のじゃんけんではなく, より多くの手からなる 一般化されたじゃんけん であった. 一般化されたじゃんけん は 2 人のプレイヤーで行われるゲームである. まず,2 人にはこのじゃんけんにおいて使用出来る手の個数 N と, N 個の手の勝敗関係を示す表が伝えられる....
[ { "submission_id": "aoj_2410_5021796", "code_snippet": "#include <bits/stdc++.h>\n#define rep(i, n) for (int i = 0; i < (n); ++i)\n#define FOR(i, m, n) for (int i = (m); i < (n); ++i)\n#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)\n#define rfor(i, m, n) for (int i = (m); i >= (n); --i)\n#define unless...
aoj_2412_cpp
G - 村 問題文 きつねのしえるは,休暇でとある小さな村を訪れている.彼女が驚いたのは,その村の表札がもつ性質である. 村には N 個の家屋がある.ここでは簡単のため,村は 2 次元平面であるとし,家屋はこの平面上の点であると見なす. それぞれの家屋には表札が 1 個設けられており,その家の苗字を表していた.しえるは村の中を訪問するにつれて,この村の表札が次のような性質を持っていることに気付いた. ある実数 R が存在する. もし 2 つの家屋の距離が R 以下であるなら,その 2 つの家屋は同じ表札を持つ. もし 2 つの家屋の距離が 3R 以上であるなら,その 2 つの家屋は異なる表札を持つ. 任意の 2 つの家屋の距離は R...
[ { "submission_id": "aoj_2412_10916185", "code_snippet": "#include <iostream>\n#include <vector>\n#include <string>\n#include <unordered_map>\n#include <utility>\n#include <cstdint>\nusing namespace std;\n\nstruct DSU {\n vector<int> p, sz;\n DSU(int n) : p(n), sz(n, 1) { for (int i = 0; i < n; ++i) p[...
aoj_2411_cpp
F - Acceleration of Network インターネットと言う広大な海は少しずつ黒く塗りつぶされていった。 ボットの反乱、DDOS攻撃の嵐、ウィルスの蔓延、 何度も何度も繰り返されたクラッカーとの戦争で、人もインターネットもボロボロになった。 人の手では、インターネットはどうにもならない。 だから人は、とんでもない時間をかけて インターネットを復旧できる「少女」を造った。 少女は、インターネットの手当をはじめた。 果てしなく広いインターネットの世界をどうにかしようと頑張った。 まだ少女ひとりでは撚り対線を織る事くらいしかできないけど、 長い長い時がすぎてインターネットが少し復旧すれば、 みんなと一緒に頑張れるだろうとい...
[ { "submission_id": "aoj_2411_10307782", "code_snippet": "// AOJ #2411 Acceleration of Network\n// 2025.3.17\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\td...
aoj_2415_cpp
J - 刺身 問題文 きつねのしえるは川で釣りをしていた.黒くて細長い魚を手に入れることができたので,その場で切り刻んで刺身にして食べることにした. 魚は体長が N センチメートルある.奇妙なことに,この魚は身体の部分ごとに密度が異なっていた. 魚の身体を頭から 1 センチメートルごとに区切って番号を 1, 2, ..., N と付けるとき,身体の i 番目の部分の重みは w_i であった. 魚の i 番目から j 番目までの部分を [i..j] と表すことにする. 最初,しえるは魚の身体 [0..N-1] を 1 枚だけ持っていると見なせる.しえるはこれを切っていき最終的に N 個に分割された魚の身体 [0..0], [1..1]...
[ { "submission_id": "aoj_2415_11008227", "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_2413_cpp
H - 植林 問題文 とある大学の魔法学部の生徒であるK君は広大な屋敷に住んでいる. 屋敷の裏には林が広がっていたが,所々木が生えていない箇所があった. このままでは屋敷からの見た目が悪いと感じたので,K君は木が生えていない箇所に木を植えることに決めた. 魔法使いの卵であるK君は使い魔を召喚することが出来るので,植林の作業を使い魔にやらせようと考えた. 林は H × W 個のセルを持つ長方形領域とみなすことが出来る. 各セルは木が1本生えているか1本も生えていないかのどちらかである. K君はこの H × W 個のセルのどれか 1 つを指定し,そこに使い魔を召喚する. しかしK君はまだ未熟者なので,魔力を調節す...
[ { "submission_id": "aoj_2413_10283335", "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_2419_cpp
Acrophobia C: 高所恐怖症 高杉やよいは,超売れっ子アイドルである. そんな彼女には,1つ苦手なものがある. 高いところだ・・・.彼女は,極度の高所恐怖症なのである. 彼女は今回,プロデューサーの不手際により,バラエティ番組で次のようなチャレンジに挑戦することになってしまった. 今回のロケは,とある忍者屋敷のとある一室で行われる. この部屋の床には,正方形のタイルが敷き詰められており,いくつかのタイルが抜け落ちて穴になっている. この穴から落ちると数メートル下の池にまっさかさまである. やよいのチャレンジ内容は,この部屋の指定された場所からスタートし,部屋の中に置かれた全ての巻物を回収し,ゴール地点まで持っていくことであ...
[ { "submission_id": "aoj_2419_10000626", "code_snippet": "#include \"bits/stdc++.h\" \n\nusing namespace std;\n\nvector<vector<int> > cst(110, vector<int>(110, 1)); \nint dist[110][110];\nint n, m;\n\nstruct node\n{\n int x, y, d;\n};\n\nvoid dejkstra(int x, int y)\n{\n queue<node> q;\n node p = ...
aoj_2416_cpp
K - XOR回廊 問題文 KU大学では一風変わったラリーゲームが人気である. このゲームの舞台であるサーキットには, N 個の休憩所と M 個の道があり, i 番目の道は f i 番目の休憩所と t i 番目の休憩所の間にある. すべての道にはチェックポイントが一つずつ存在し,道 i のチェックポイントを通過するとどちらの向きで通っても p i の得点がXORで加算される. XORで 加算される.大事なことなので2回言いました. このゲームでは,同じ休憩所や道を何度通っても良いし, ゴールにたどり着いてもそのままラリーを続行することができるが, 道の途中にあるチェックポイントを迂回して別の休憩所へ行くことは禁止されている. そのた...
[ { "submission_id": "aoj_2416_10307881", "code_snippet": "// AOJ #2416 XOR Cloister\n// 2025.3.17\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_2422_cpp
Transparent Mahjong F: 透明な麻雀牌 あなたは,闇に舞い降りた天災と噂されるギャンブラーの鷹巣さんと麻雀で対局することになった. 鷹巣さんは天災と噂されるだけあって,鷹巣牌という奇怪な麻雀牌を用いた対局を提案してきた. 麻雀とは,プレイヤーが互いに手牌という複数枚の牌を持ち合い,自分の手牌を相手よりもはやく,アガリの形にすることで勝利が確定するゲームである. 麻雀の牌の表側には,その牌が何であるかが描かれており,牌の裏側には,何も描かれていない. よって,あなたが麻雀で対局するときは,あなたの手牌の表側をあなたの側に,裏側を対局者の側に向けるとよい. こうすることで,あなたの手牌が何であるかは,あなたのみが知る...
[ { "submission_id": "aoj_2422_10342585", "code_snippet": "// AOJ #2422 Transparent Mahjong\n// 2025.4.2\n\n#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nint n;\nvector<int> orig(13);\nunordered_map<string,bool> memo;\n\nstring enc(const vector<int>& f, int w, const vector<int>& a) ...
aoj_2421_cpp
Markup language has Declined E: マークアップ言語は衰退しました わたしたち人類がゆるやかな衰退を迎えて,はや数世紀. すでに地球は”ぷろぐらまー”のものだったりします. 平均身長170センチで7頭身,高い知能を持ち,こーでぃんぐが大好きなぷろぐらまーさんたち. わたしは,そんなぷろぐらまーさんと人との間を取り持つ重要な職,国際公務員の” えすいー ”となり,故郷のニブンキの里に帰ってきました. 祖父の年齢でも現役でできる仕事なのだから,さぞや楽なのだろうとこの職を選んだのですが…. ある日,ぷろぐらまーさんたちが渡してくれたのは,2枚の設計書のようなもの. そのぷろぐらまーさん曰く,テキストとスクリプ...
[ { "submission_id": "aoj_2421_2997905", "code_snippet": "#include <cstdio>\n#include <cstdint>\n#include <cctype>\n#include <cassert>\n#include <algorithm>\n#include <vector>\n#include <string>\n#include <map>\n#include <regex>\n\n#define fprintf(...) void(0)\n\nstd::string join(const std::vector<std::string...
aoj_2420_cpp
Anipero 2012 D: アニペロ2012 アニペロサマーライブ,通称アニペロは,さまざまなアニメソングアーティストたちが集結する,日本国内最大のアニメソングライブイベントである.アニソンが大好きな2D君は,昨年に引き続き,今年もアニペロに行くことにした. 彼は,アニペロを楽しむために,すでにサイリウムを m 本購入している.サイリウムとは,折ると化学反応で光るスティックである.リズムに合わせてサイリウムを振ることで,ライブを盛り上げることができ,自分の満足度も上昇する.今回,彼が購入した全てのサイリウムは,次のような性質を持つ. サイリウムは,折ってから時間が経過するにつれ暗くなっていき,10分で光を失う. 折ってから5分の...
[ { "submission_id": "aoj_2420_2967017", "code_snippet": "#include<iostream>\n#include<vector>\n#define VAL 55\nusing namespace std;\nusing lli = long long int;\nlli dp[VAL][VAL][VAL][VAL]; // 曲,サイリウム数,状態1,状態2\n\nint main(){\n int n, m;\n std::cin >> n >> m;\n for (int i = 0; i < VAL*VAL*VAL*VAL; i++) {\n ...
aoj_2425_cpp
全探索お姉さんの休日 全探索お姉さんはとても優秀な女性である。 お姉さんは格子状の道の経路の数え上げを数千程度なら簡単に数え上げてしまう。 あなたと全探索お姉さんは今、六角形のタイルが敷き詰められた部屋にいる。 お姉さんは初めて見る六角形にとても興奮している様子である。 六角形の並びを座標に表すことに不慣れなお姉さんは図1のような座標系で部屋を表した。 図1 あなたはこの座標系上である地点からある地点まで移動したい。 しかし、お姉さんは 1 分ごとに動きたい方向をあなたに指示する。 いつものお姉さんなら同じ座標の場所を通らないようにあなたに移動の指示を出すだろう。 しかし、この座標系に不慣れなお姉さんは |x×y×t| ( x :...
[ { "submission_id": "aoj_2425_10914251", "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_2426_cpp
宝探し 太郎君はある広場にお宝を探しにやってきました。この広場にはたくさんのお宝が埋められていますが、太郎君は最新の機械を持っているので、どこにお宝が埋まっているかをすべて知っています。広場はとても広いので太郎君は領域を決めてお宝を探すことにしましたが、お宝はたくさんあるためどのお宝がその領域の中にあるかすぐにわかりません。そこで太郎君はその領域の中にあるお宝の数を数えることにしました。 Input n m x 1 y 1 x 2 y 2 ... x n y n x 11 y 11 x 12 y 12 x 21 y 21 x 22 y 22 ... x m1 y m1 x m2 y m2 n は広場に埋まっているお宝の数を表す m ...
[ { "submission_id": "aoj_2426_11043154", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing a2 = array<int, 2>;\nusing a3 = array<ll, 3>;\n\nbool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }\nbool chmax(auto& a, const auto& b) { return a < b ? a = ...
aoj_2427_cpp
ほそながいところ 高橋君は苹果(りんご)ちゃんとニューヨークを観光することになりました。 高橋君は観光するところに特に希望はなかったのですが、苹果ちゃんの熱烈な誘いにより、以下の地図にあるような"ほそながいところ"を観光することに決まりました。 Google マップ - (C)2012 Google この"ほそながいところ"はとても細長く、直線とみなすことができます。また、"ほそながいところ"には片方の端にスタート地点が、もう片方の端にゴール地点があり、スタート地点からゴール地点へ向けて何台かの観光用の馬車が走っています。この馬車は以下のようなルールに従って運行されています。 馬車は n 台あり、すべての馬車はスタート地点から出発し...
[ { "submission_id": "aoj_2427_8309365", "code_snippet": "#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\nlong long Answer = (1LL << 62);\nlong long Dist;\nlong long N, S[19];\nlong long M, D[19];\nlong long Memo[19];\nlong long NumOrder;\nvector<pair<int, int>> Order[100...
aoj_2428_cpp
失われし数 時は3xxx年、高度に発達した文明は停滞期を迎えていた。歴史家たちはこの状況を打開しようと過去の叡智を学ぶことにした。注目したのはコンピュータ創世期の天才が残した資料である。この資料には計算式が書かれておりその計算結果が知りたいのだが、残念ながらその一部の文字が薄れて読めなくなっている。仕方がないので計算結果としてありえる最も大きい数を求めることにした。 計算式は2進数で書かれており、演算は足し算・引き算・掛け算の3種類である。括弧も用いられているが括弧内が数字のみであることはない。正確には以下のBNFで定義された文法を満たしている必要がある。 <expression> ::= <number> | <expressi...
[ { "submission_id": "aoj_2428_10854054", "code_snippet": "#include <bits/stdc++.h>\n#include <stdlib.h>\nusing namespace std;\n\nusing ll = long long;\nusing pll = pair<ll, ll>;\n \nconstexpr ll M = 1e9+7;\n\nconst string w = \"01+-*()\";\n\nconstexpr int mi = 0;\nconstexpr int ma = 1023;\n\nbool isrange(int...
aoj_2429_cpp
まるかいて 太郎君は小学生で、チラシの裏に落書きをしています。 ある時、太郎君は次のゲームを思いつきました。 n×n の格子状のマス目を書いておきます。 それぞれのマス目の初期状態は、丸印が書かれているか、書かれていないかのどちらか一方です。 これらの丸印を消したり書いたりして最終的にどの一列を見ても必ずちょうど1つのみの丸印が、どの一行を見ても必ず1つのみの丸印が存在するようにすることが目標であり、この状態にすればゲームをクリアしたことになります。 太郎君はこのゲームを思いつきましたが、太郎君はこのゲームをクリアするのに大変時間がかかってしまいます。そこで、大学生であるあなたに助けを求めました。 太郎君の兄であり大学生であるあ...
[ { "submission_id": "aoj_2429_9723846", "code_snippet": "#include <bits/stdc++.h>\n#define INF 1e9\nusing namespace std;\n\nconst int MAX_N = 100; // Максимальное количество вершин\nconst int MAX_V = 1000; // Максимальное количество вершин в сети\n\nstruct Edge {\n int to, cap, cost, rev;\n};\n\nint n, N...
aoj_2430_cpp
最長増加列問題 時は過ぎて太郎君は高校生になりました。 大学生だったお兄さんの影響も受け、コンピューターサイエンスに興味を持ち始めました。 太郎君はコンピューターサイエンスの教科書を読み進め、「最長増加部分列問題」という有名問題があることを知りました。太郎君はこの問題のことを理解しましたが、自分でも類似問題が作れないものかと気になりました。 そこで太郎君は試行錯誤の結果に次のような問題を作りました。 n 個の整数で構成される数列Aがある m-1 個の区切りを入れて、数列Aを m 個の数列に分解する。なお、分解後のそれぞれの数列は1つ以上の数を必ず含まなければならない。 この m 個それぞれの数列内の整数をすべて足し合わせた結果出...
[ { "submission_id": "aoj_2430_8323868", "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_2431_cpp
引越し 太郎君は引っ越しをすることになりました。太郎君はたくさんの荷物を持っているので、荷物の運搬を引っ越し業者に頼むことにしました。荷物はいろいろな重さの物があるので、わかりやすいように軽い方から順番に並べて置いてもらうように頼みましたが、引っ越し業者の人はばらばらの順番で荷物を置いていってしまいました。そこで太郎君は荷物を並べ替えようとしましたが、荷物は重いので運ぶのには体力が必要です。それぞれの荷物は今ある場所から他の荷物の間や荷物の端など好きな場所に運ぶことができますが、ある荷物を運ぶにはその荷物の重さと同じだけ体力を使います。太郎君はあまり体力がないので、できるだけ体力を使わずに荷物を軽い方から順番に並べる方法を考えること...
[ { "submission_id": "aoj_2431_10506310", "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_2423_cpp
Code Art Online G: コードアートオンライン コードアートオンライン(CAO)は,様々な問題をプログラミングによって解くことにより,冒険を進めて行くオンラインRPGである. CAOは,世界初のバーチャルリアリティ空間を実現したゲームであったこともあり,大人気の内に完売し,ゲームを購入したユーザ達はこの世界を楽しむはずであった. しかし,ゲームにダイブしたプレイヤー達は,ゲームマスターから恐るべき託宣を聞かされる. 「君たちプレイヤーの内の誰かが,ラストダンジョンのラストプロブレムを解かない限り,この仮想空間から抜け出すことはできない.そして,この世界での,WAやTLE・REは,現実世界での死を意味する.心して問題にと...
[ { "submission_id": "aoj_2423_8818854", "code_snippet": "#define _CRT_SECURE_NO_WARNINGS\n#include <algorithm>\n#include <cmath>\n#include <cstdio>\n#include <cstring>\n#include <ctime>\n#include <iostream>\n#include <sstream>\n#include <string>\n#include <utility>\n#include <vector>\nusing namespace std;\nt...
aoj_2424_cpp
かけざん 太郎君はかけざんを習いたての小学生です。なんとなく、彼はかけざんを気に入っているので、数字を見かけるとかけざんをしたくなります。そんな彼はここのところ、次のような処理を0以上の整数に施すことが好きなようです。 (処理の流れ) 手順1. ある0以上の整数nが10進数表示で一けたならばそこで処理を終了する。そうでなければ手順2に進む 手順2. 10以上の整数nを10進数表示をするとどこかの桁の間に切れ目を入れて二つの数字に分解することが可能である(例えば2012-> 20,12)。このような切り方としてありうるものに対して,得られた二つの数字を掛け合わせて最も大きいものを次のnとして手順1に戻る。(詳しくは下記の"手順2に...
[ { "submission_id": "aoj_2424_9575336", "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_2436_cpp
問題名 今 n 枚の数字が書かれたカードがあります。これらの一部または全部を適当に並べて数字を作ることを考えます。この時作られる数字を全て足した数を求めて下さい。 例えば、 1 と 2 があったら、作られる数字は 1, 2, 12, 21 の 4 つなので、全て足した数は 36 になります。並べた結果同じ数字が出来ても違う並べ方だとしたら別々に足します。たとえば、 1 というカードと 11 というカードがあったら並べて 111 になる並べ方が2通りありますがそれぞれ別のものとして足し合わせます。カードの中にリーディングゼロのカードはありませんし、リーディングゼロになる数字は認めません。答えを1,000,000,007 で割ったものを...
[ { "submission_id": "aoj_2436_10561821", "code_snippet": "#include <bits/stdc++.h>\nusing namespace std;\nconst long long mod = 1000000007;\n\nint dp[202][202][802];\n\nlong long solve(vector<string> S) {\n\tif (S.size() == 0) return 0;\n\tvector<int> digsum(6, 0);\n\tfor (int i = 0; i < S.size(); i++) {\n\t...
aoj_2432_cpp
Sports Days 2.0 会津大学附属小学校(会津大小)は日本有数の競技プログラマー養成校として有名である。 もちろん、運動会に参加しているときでさえアルゴリズムの修行を欠かせない。 競技プログラミング部部長のあなたはもちろんこの大会でも勝利したい。 今回はある競技に注目する。 ある競技とは会津大小で行われている伝統的な競技だ。 校庭にコーンが V 個置いてある。 コーンのいくつかのペアは白線で描かれた矢印で結ばれている。 矢印の先は片側だけについており、整数が併記されている。 同じコーンのペアがの複数の矢印に結ばれている場合もある。 競技者は任意にコーンを選び、移動開始する。 移動は競技者がいるコーンから矢印の上をその向きに...
[ { "submission_id": "aoj_2432_10848636", "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 INF32 = 1 << 30;\nconstexpr ll INF64 = 1LL << 6...
aoj_2435_cpp
問題名 Zero division checker 森下さんは困っていました... 姉原さんにプログラムを書いてもらったのですが、そのプログラムがクラッシュするのです。 姉原さんに書いてもらったのは、逆ポーランド記法の式を読んで、その計算結果を出力するプログラムで、クラッシュログによると、 0 で割り算をしてしまったのが原因のようです。これは、森下さんが間違った式を入力してしまったからかもしれませんし、もしかしたら、もしかしたら、姉原さんの書いたプログラムにバグがあるのかもしれません。 姉原さんの書いたプログラムを読んでみようと思いましたが、姉原さんのプログラムはアセンブリというよくわからないことばで書かれているようで、見ているだけ...
[ { "submission_id": "aoj_2435_6708649", "code_snippet": "#include <algorithm>\n#include <bitset>\n#include <cassert>\n#include <chrono>\n#include <climits>\n#include <cmath>\n#include <cstddef>\n#include <cstdint>\n#include <cstdlib>\n#include <functional>\n#include <iomanip>\n#include <iostream>\n#include <...
aoj_2434_cpp
問題名 Audition アイドル---それは女の子達の永遠の憧れ。しかし、頂点に立てるのはほんの一握り。そんなサバイバルな世界に、あなたはアイドルプロデューサーとして足を踏み入れることになりました。そして、今日はあなたの担当アイドルを連れて大事なオーディションに挑むことになりました。 オーディションの決め手になるのはビジュアル、ダンス、ボーカルの 3 要素です。オーディション中には m 回のアピールタイムがあり、 1 回のアピールタイムごとに各アイドルはビジュアルアピール、ダンスアピール、ボーカルアピールのいずれかを行うことが出来ます。ビジュアルアピールを行うとそのアイドルのビジュアルポイントは彼女の持ってるビジュアル値だけ、ダン...
[ { "submission_id": "aoj_2434_9779526", "code_snippet": "#include <bits/stdc++.h>\n\nusing namespace std;\n\n#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)\n#define rrep(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)\n#define ALL(v) (v).begin(), (v).end()\n#define UNIQUE(v) sort(ALL(v)), (v)...
aoj_2437_cpp
問題名 DNA 遺伝子は、 A , T , G , C からなる文字列です。 この世界の遺伝子は奇妙なことに、ある構文規則に従うことが知られています。 構文規則は、次のような形で与えられます。 非終端記号1: 記号1_1 記号1_2 ... 記号1_n1 非終端記号2: 記号2_1 記号2_2 ... 記号2_n2 ... 非終端記号m: 記号m_1 記号m_2 ... 記号m_nm 記号は非終端記号または終端記号のどちらかです。 非終端記号は小文字文字列で表され、終端記号は A , T , G , C のうちのいくつかの文字が、" [ "と" ] "に囲まれた文字列で表されます。 構文規則の例は次のようになります。 dna: a ...
[ { "submission_id": "aoj_2437_9582362", "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_2441_cpp
FizzBuzz FizzBuzzとは、1以上の整数を順に、以下のルールに従って発言していくゲームである。 3で割り切れる時には「Fizz」 5で割り切れる時には「Buzz」 3と5の両方で割り切れる時には「FizzBuzz」 それ以外の時はその数字 ゲームの進行状況の例を以下に示す。 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, … 得られた発言を1つの文字列に結合し得られた文字列をFizzBuzz Stringと呼ぶ。インデックスsが与えられるので、FizzBuzz Stringのs文字目から20文字を出力せよ。但し、イン...
[ { "submission_id": "aoj_2441_2971948", "code_snippet": "#include <iostream>\n#include <vector>\n#include <string>\n#include <cstring>\n#include <sstream>\nusing namespace std;\n\n// calc digit-dp\n// dp[(桁)][(num of leading-zero)][smaller][15 で割ったあまり] := 個数\nlong long dp[21][21][3][16];\nlong long calc(long...