Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
string
title
string
url
string
contest_id
int32
contest_name
string
contest_start_date
string
index
string
rating
int32
tags
list
time_limit_seconds
float64
memory_limit_mb
float64
is_interactive
bool
input_mode
string
description
string
input_format
string
output_format
string
interaction_format
string
note
string
examples
list
editorial
string
answer_type
string
checker_cpp
string
interactor_cpp
string
reference_cpp
string
gen_cpp
string
tests_txt
string
2183A
Binary Array Game
https://codeforces.com/contest/2183/problem/A
2,183
Hello 2026
2026-01-07
A
800
[ "games" ]
1
256
false
stdio
Alice and Bob are playing a game on an array $$$a$$$ of size $$$n$$$, containing only numbers `0` and `1`. Alice moves first, with each player alternating turns. In a player's turn, he or she chooses two integers $$$l$$$ and $$$r$$$ such that $$$1 \leq l \color{red}{ \lt } r \leq |a|$$$ (here, $$$|a|$$$ denotes the cu...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. The first line of each test case contains a positive integer $$$n$$$ ($$$3 \le n \le 100$$$), denoting the length of the array $$$a$$$. The second line o...
For each test case, output `Alice` if Alice wins, and `Bob` otherwise. You may output each character in any case. For example, the answers `Alice`, `alice`, `ALICE`, `AliCe` will all be interpreted the same.
null
In the first test case, Alice can win by choosing $$$l=2$$$ and $$$r=3$$$. Since $$$1-\operatorname{min}(a_2,a_3)=1$$$, the subarray $$$[1,0]$$$ is replaced with a single integer $$$1$$$, and $$$a$$$ becomes $$$[1,1]$$$. At this point, it is Bob's turn, and the only move he has is to choose $$$l=1$$$ and $$$r=2$$$. Sin...
[ { "input": "7\n3\n1 1 0\n3\n1 1 1\n3\n0 1 0\n4\n0 0 0 0\n5\n1 0 1 0 1\n6\n0 1 0 1 0 1\n6\n0 1 0 1 0 0\n", "output": "Alice\nAlice\nBob\nBob\nAlice\nAlice\nBob\n" } ]
Hint 1: If the sequence $$$a$$$ consists entirely of $$$1$$$s, what will Alice do? Hint 2: Consider discussing the values of $$$a_1$$$ and $$$a_n$$$. Solution: First, if the entire sequence consists of $$$1$$$s, Alice wins immediately by operating on the whole sequence. Note that the last operation must involve at ...
unique
#include "testlib.h" using namespace std; // Unique Alice/Bob per test case. Case-insensitive, as the statement allows. bool readAliceBob(InStream& st, TResult bad, const char* who, int tc) { string s = lowerCase(st.readToken()); if (s == "alice") return true; if (s == "bob") return false; st.quitf(b...
null
#include <bits/stdc++.h> using namespace std; // Editorial: Alice wins iff all ones, or a_1 = 1, or a_n = 1. int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int n; cin >> n; vector<int> a(n); bool allOne = true; for ...
#include "testlib.h" using namespace std; // One test file to stdout. // -t T number of test cases (1..100) // -n N length of every case, or max length when -vary 1 // -vary 0|1 if 1, each case length is uniform in 3..N // -mode NAME random|allones|allzeros|bothzero|firstone|lastone|al...
# minimum n, many tiny cases in one file -t 30 -n 3 -mode random -seed 1 -t 50 -n 3 -mode alternating -seed 2 # maximum constraints: t = 100, n = 100 each -t 100 -n 100 -mode random -seed 3 -t 100 -n 100 -mode ones -seed 4 # structured / extremes -t 1 -n 100 -mode allones -seed 5 -t 1 -n 100 -mode allzeros -seed 6 -t 1...
2183B
Yet Another MEX Problem
https://codeforces.com/contest/2183/problem/B
2,183
Hello 2026
2026-01-07
B
1,100
[ "constructive algorithms", "greedy" ]
1.5
256
false
stdio
You are given an array $$$a$$$ of length $$$n$$$, and an integer $$$k$$$. Let $$$f(l,r)$$$ be the value of $$$\operatorname{mex}(a_l,a_{l+1},\ldots,a_r)$$$$$$^{\text{∗}}$$$. You want to perform the following operation $$$n-k+1$$$ times: - Let the current length of the sequence be $$$|a|$$$. You need to find an interva...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains two positive integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 2 \cdot 10^5$$$). The second line of each test...
Output a single non-negative integer representing your answer.
null
In the first test case, we can select the interval $$$[1,3]$$$. Then, delete $$$a_2$$$ to obtain $$$[0,0]$$$. The process terminates, and the $$$\operatorname{mex}$$$ of the remaining elements is $$$1$$$. In the third test case, we can perform the following operations: - Select $$$i=1,j=3$$$. This is allowed because ...
[ { "input": "5\n3 3\n0 0 0\n4 2\n0 2 1 3\n5 3\n0 1 2 1 0\n6 2\n0 1 0 1 2 0\n7 5\n0 1 2 4 0 3 1\n", "output": "1\n1\n2\n1\n4\n" } ]
We find that the restriction of deleting one number from an interval is loose. We can easily transform the problem into selecting $$$k-1$$$ numbers from $$$n$$$ numbers to maximize their $$$\text{mex}$$$. The time complexity is $$$O(n)$$$.
unique
#include "testlib.h" using namespace std; int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); for (int tc = 1; tc <= t; tc++) { setTestCase(tc); long long jury = ans.readLong(); long long part = ouf.readLong(0, LLONG_MAX, "answer"); if (...
null
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int n, k; cin >> n >> k; vector<int> seen(k, 0); for (int i = 0; i < n; i++) { int x; cin >> x; ...
#include "testlib.h" using namespace std; // -t cases -n max n per case -sumn cap -k fixed k (0 = random) -mode -seed int main(int argc, char* argv[]) { registerGen(argc, argv, 1); int t = opt<int>("t"); int maxn = opt<int>("n"); int sumn = opt<int>("sumn", 200000); int fixedK = opt<int>("k", 0); ...
# min n, many tiny cases -t 10000 -n 2 -sumn 20000 -k 2 -mode all_zero -seed 1 # max t with sum n at limit -t 10000 -n 20 -sumn 200000 -mode random -seed 2 # max single array -t 1 -n 200000 -k 200000 -mode iota -seed 3 -t 1 -n 200000 -k 2 -mode random -seed 4 -t 1 -n 200000 -k 100000 -mode perm_small -seed 5 # mex > k-...
2183D1
Tree Coloring (Easy Version)
https://codeforces.com/contest/2183/problem/D1
2,183
Hello 2026
2026-01-07
D1
1,500
[ "constructive algorithms", "dfs and similar", "greedy", "trees" ]
2
512
false
stdio
**This is the Easy version of the problem. The difference between the versions is that in this version, you are only required to find the minimum number of operations. You can hack only if you solved all versions of this problem.** You are given a rooted tree$$$^{\text{∗}}$$$ consisting of $$$n$$$ vertices numbered fr...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) – the number of vertices in the tree. The $$$i$$$-th fo...
For each test case, output the minimum number of operations on a new line.
null
In the first test case, $$$d_1=1$$$ and $$$d_2=d_3=d_4=d_5=2$$$. We can show that we must perform at least $$$5$$$ operations because there are no two nodes that can be operated on simultaneously. In the second test case, we can show that the least number of operations required to color the full tree is $$$4$$$. One w...
[ { "input": "10\n5\n3 1\n1 2\n5 1\n4 1\n5\n3 2\n2 4\n2 5\n1 2\n5\n3 4\n4 1\n5 1\n1 2\n5\n2 5\n3 1\n2 1\n3 4\n5\n1 3\n1 5\n4 3\n2 4\n13\n2 1\n3 2\n4 2\n5 4\n6 3\n7 1\n8 5\n9 6\n10 4\n11 7\n12 8\n13 10\n10\n5 7\n8 1\n1 10\n2 8\n8 4\n9 4\n6 1\n5 3\n7 8\n10\n7 6\n3 7\n6 9\n7 1\n9 8\n5 1\n3 10\n9 2\n1 4\n10\n10 6\n2 ...
:::info[Hint 1] Consider which points cannot be colored in the same operation. ::: :::info[Hint 2] Find a lower bound for the number of operations. ::: Suppose the number of points at depth $$$i$$$ is $$$t_i$$$. First, points at the same depth cannot be colored simultaneously, so the lower bound for the answer is $$$...
unique
#include "testlib.h" using namespace std; int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); for (int tc = 1; tc <= t; tc++) { setTestCase(tc); long long jury = ans.readLong(); long long part = ouf.readLong(LLONG_MIN, LLONG_MAX, "answer"); ...
null
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int n; cin >> n; vector<vector<int>> g(n + 1); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; ...
#include "testlib.h" using namespace std; // One test to stdout. // -preset pathkill|depthkill|childkill|wide|fork // Otherwise: -t -n max n -sumn (default 200000) -nmode first|exact|uniform // -tree random|path|star|binary|deep|broom|cat|fork // -seed only perturbs the RNG. static void preset_or_die(const string& pr...
# minimum n, many tiny cases -t 10000 -n 2 -sumn 20000 -nmode uniform -tree random -seed 1 -t 500 -n 20 -sumn 10000 -tree random -seed 2 # max single tree and max sum n -t 1 -n 200000 -sumn 200000 -nmode exact -tree star -seed 3 -t 1 -n 200000 -sumn 200000 -nmode exact -tree path -seed 4 -t 1 -n 200000 -sumn 200000 -nm...
2183D2
Tree Coloring (Hard Version)
https://codeforces.com/contest/2183/problem/D2
2,183
Hello 2026
2026-01-07
D2
2,100
[ "combinatorics", "constructive algorithms", "data structures", "dfs and similar", "greedy", "implementation", "trees" ]
2
512
false
stdio
**This is the Hard version of the problem. The difference between the versions is that in this version, you must find the minimum number of operations and find a way to color the tree using that many operations. You can hack only if you solved all versions of this problem.** You are given a rooted tree$$$^{\text{∗}}$$...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) – the number of vertices in the tree. The $$$i$$$-th fo...
For each test case: - Output your number of operations $$$k$$$ on the first line ($$$1 \leq k \leq n$$$). - Then, output $$$k$$$ lines. Each line should begin with an integer $$$m$$$ representing the size of the operation's set ($$$0 \leq m \leq n$$$). After that, there should be $$$m$$$ numbers $$$u_1,u_2,\ldots,u_m$...
null
In the first test case, $$$d_1=1$$$ and $$$d_2=d_3=d_4=d_5=2$$$. We can show that we must perform at least $$$5$$$ operations because there are no two nodes that can be operated on simultaneously. In the second test case, we can show that the least number of operations required to color the full tree is $$$4$$$. The e...
[ { "input": "10\n5\n3 1\n1 2\n5 1\n4 1\n5\n3 2\n2 4\n2 5\n1 2\n5\n3 4\n4 1\n5 1\n1 2\n5\n2 5\n3 1\n2 1\n3 4\n5\n1 3\n1 5\n4 3\n2 4\n13\n2 1\n3 2\n4 2\n5 4\n6 3\n7 1\n8 5\n9 6\n10 4\n11 7\n12 8\n13 10\n10\n5 7\n8 1\n1 10\n2 8\n8 4\n9 4\n6 1\n5 3\n7 8\n10\n7 6\n3 7\n6 9\n7 1\n9 8\n5 1\n3 10\n9 2\n1 4\n10\n10 6\n2 ...
:::info[Hint 3] When can the minimum number of operations reach $$$\max t_i$$$? How much more than $$$\max t_i$$$ can it be at most? ::: We claim the maximum number of operations is $$$\max t_i + 1$$$. Consider the following constructive proof. Let $$$S_i$$$ denote the set of points for the $$$i$$$th operation. With...
multiple
#include "testlib.h" #include <vector> using namespace std; static vector<vector<int>> g; static vector<int> dist_, fa_; static void buildTree(int n) { g.assign(n + 1, {}); dist_.assign(n + 1, 0); fa_.assign(n + 1, 0); for (int i = 0; i < n - 1; i++) { int u = inf.readInt(1, n, "u"); i...
null
#include <bits/stdc++.h> using namespace std; static vector<vector<int>> g; static vector<int> dist_, fa_; static vector<vector<int>> layer; static void dfs(int u, int p) { dist_[u] = p ? dist_[p] + 1 : 1; fa_[u] = p; layer[dist_[u]].push_back(u); for (int v : g[u]) if (v != p) dfs(v, u); } s...
#include "testlib.h" using namespace std; // -preset star5|sameparent|chain|maxt // Otherwise: -t -n max n -sumn (default 200000) -nmode first|exact|uniform // -tree random|path|star|binary|deep|broom|cat|fork // -seed only perturbs the RNG. static void writeCase(int n, const vector<pair<int, int>>& edges) { prin...
-preset star5 -preset sameparent -t 1 -n 2 -nmode exact -tree path -t 5 -n 5 -nmode uniform -tree random -t 10 -n 8 -nmode uniform -tree star -t 3 -n 50 -nmode exact -tree path -t 3 -n 50 -nmode exact -tree star -t 2 -n 500 -nmode exact -tree random -t 1 -n 5000 -nmode exact -tree broom -t 1 -n 200000 -nmode exact -tre...
2183E
LCM is Legendary Counting Master
https://codeforces.com/contest/2183/problem/E
2,183
Hello 2026
2026-01-07
E
2,100
[ "dp", "math", "number theory" ]
3
512
false
stdio
You are given a sequence $$$a$$$ of length $$$n$$$ and a positive integer $$$m$$$. Each element of $$$a$$$ is an integer in the range $$$[0, m]$$$. A sequence $$$a$$$ is considered **good** if and only if the following two conditions hold: - $$$a_1 \lt a_2 \lt a_3 \lt \ldots \lt a_n$$$, and - $$$\frac{1}{\operatornam...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n\le m \le 3000$$$). The second line of each test case contains $$$...
For each test case, output a single integer — the number of ways to complete the sequence so that it becomes good, modulo $$$998\,244\,353$$$.
null
In the first test case, there are $$$2$$$ ways to replace the zeros such that the sequence becomes good: - $$$[1, 2, 3, 6]$$$: The sum is $$$\frac{1}{\operatorname{lcm}(1, 2)} + \frac{1}{\operatorname{lcm}(2, 3)} + \frac{1}{\operatorname{lcm}(3, 6)} + \frac{1}{\operatorname{lcm}(6, 1)} = \frac{1}{2} + \frac{1}{6} + \f...
[ { "input": "5\n4 6\n1 0 0 6\n2 2\n2 1\n5 24\n0 0 4 0 0\n5 6\n0 0 6 0 0\n20 2000\n1 0 0 0 0 14 0 0 0 0 0 0 0 0 0 514 0 0 0 0\n", "output": "2\n0\n10\n0\n973702700\n" } ]
## [E. LCM is Legendary Counting Master]() :::info[Hint 1] Consider the term $$$\frac{1}{\operatorname{lcm}(a_i,a_{i+1})}$$$. What properties can you derive if $$$a_i \lt a_{i+1}$$$? ::: :::info[Hint 2] Recall that $$$\frac{1}{\operatorname{lcm}(a_i,a_{i+1})} = \frac{\gcd(a_i,a_{i+1})}{a_i a_{i+1}}$$$. Notice that ...
unique
#include "testlib.h" using namespace std; int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); for (int tc = 1; tc <= t; tc++) { setTestCase(tc); long long jury = ans.readLong(); long long part = ouf.readLong(); if (part != jury) ...
null
#include <bits/stdc++.h> using namespace std; static const int MOD = 998244353; int addmod(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int n, m; cin >> n >> m; ...
#include "testlib.h" using namespace std; // -t cases -n length -m max value (exact m for each case unless -varym) // -sumM cap on sum of m over cases (default 3000) // -zeros all|random|none|half -seed int main(int argc, char* argv[]) { registerGen(argc, argv, 1); int t = opt<int>("t"); int n = opt<int>("...
# min sizes, many tiny cases -t 50 -n 2 -m 2 -zeros random -seed 1 -t 100 -n 2 -m 3 -sumM 300 -zeros random -seed 2 # kill wrong_no_first_one: free first element -t 1 -n 2 -m 6 -zeros all -seed 3 # kill wrong_consecutive_only -t 1 -n 3 -m 8 -zeros all -seed 4 -t 1 -n 4 -m 12 -zeros half -seed 5 # fixed violations -> 0 ...
2183F
Jumping Man
https://codeforces.com/contest/2183/problem/F
2,183
Hello 2026
2026-01-07
F
2,500
[ "brute force", "combinatorics", "dfs and similar", "dp", "trees" ]
3
1,024
false
stdio
You have a tree rooted at node $$$1$$$ with $$$n$$$ nodes. Each node has a lowercase English letter written on it. For each integer $$$i$$$ from $$$1$$$ to $$$n$$$, please solve the following problem independently: - Consider the set of strings formed by the following process: - Choose any node $$$u$$$ that is i...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows. For each test case, the first line contains an integer $$$n$$$ ($$$1 \le n \le 5000$$$). The next line is a string of length $$$n$$$ containing only low...
For each test case, output $$$n$$$ numbers on a new line: the answer for $$$i=1,2,\ldots,n$$$, modulo $$$998\,244\,353$$$.
null
For the first test case: - For nodes $$$2$$$ and $$$3$$$, the only string that is possible to get from the process is `b`. Therefore, the answer is $$$1$$$ for both. - For node $$$1$$$, the possible strings are `a`, `ab`, `ab`, `b`, and `b`. Overall, `a` is obtainable in one way, while `ab` and `b` are obtainable in t...
[ { "input": "5\n3\nabb\n1 2\n1 3\n2\naa\n1 2\n4\nccbb\n1 2\n2 3\n2 4\n4\naaaa\n1 4\n4 2\n2 3\n10\ncacbcccbac\n1 2\n2 3\n3 4\n2 5\n1 6\n2 7\n3 8\n4 9\n8 10\n", "output": "9 1 1 \n5 1 \n29 9 1 1 \n69 5 1 19 \n185 65 19 3 1 1 1 3 1 1 \n" } ]
:::info[Hint 1] Calculating the sum of squares of counts is difficult. ::: :::info[Hint 2] Calculating the sum of squares of counts is difficult, so we consider transforming it into the number of ways to choose two identical strings. ::: :::info[Hint 3] Try dynamic programming. ::: :::info[Hint 4] The transfe...
unique
#include "testlib.h" using namespace std; static const long long MOD = 998244353; int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); inf.readEoln(); for (int tc = 1; tc <= t; tc++) { setTestCase(tc); int n = inf.readInt(1, 5000, "n"); inf....
null
#include <bits/stdc++.h> using namespace std; static const int MOD = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int n; cin >> n; string s; cin >> s; vector<vector<int>> g(n); for (int i = 0; ...
#include "testlib.h" using namespace std; // Writes one full test (multiple test cases) to stdout. // -t cases -n max n per case -sumn total n cap (default 5000) // -nmode first|exact|uniform|one // -tree random|path|star|binary|broom // -chars random|all|alt|single:<c> // -preset maxn|maxt|min|sampleshape // -seed on...
# minimum / tiny -preset min # samples-shaped (not identical to bundled samples) -preset sampleshape # many tiny cases in one file -t 40 -n 3 -sumn 120 -nmode uniform -tree random -chars random -seed 1 # single max n -preset maxn -tree path -chars all -preset maxn -tree random -chars random -seed 2 -preset maxn -tree s...
2208C
Stamina and Tasks
https://codeforces.com/contest/2208/problem/C
2,208
Codeforces Round 1086 (Div. 2)
2026-03-14
C
1,300
[ "dp", "greedy", "math" ]
2
256
false
stdio
There are $$$n$$$ tasks for you. Task $$$i$$$ has an integer value of $$$c_i$$$ and a difficulty of $$$p_i$$$. Also, you have an initial stamina of $$$1$$$, which is denoted as $$$S$$$. You should process the tasks from task $$$1$$$ to task $$$n$$$. For each task, you have two choices. - Give up the task. This way, no...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The description of the test cases follows. The first line of each test cases contain an integer $$$n$$$ ($$$1\le n\le10^5$$$) denoting the number of tasks. The following $$$n$$$ lines contain two...
For each test case, output a single real number — the maximum possible points you can get. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a−b|}{\m...
null
In the first test case, it's optimal to complete task $$$1$$$ and $$$2$$$ in order, gaining points of $$$10+20=30$$$. In the second test case, it's optimal to complete task $$$1$$$, give up task $$$2$$$, and complete task $$$3$$$. Before completing task $$$3$$$, your stamina has dropped to $$$1-\frac{5}{100}=0.95$$$. ...
[ { "input": "2\n2\n10 0\n20 5\n3\n10 5\n10 80\n20 5\n", "output": "30.0000000000\n29.0000000000\n" } ]
Notice that the value of $$$S$$$ does not affect your decision. This meant for integer $$$i\in[1,n-1]$$$ the decision of tasks $$$[1,i]$$$ does not affect the decision of tasks $$$[i+1,n]$$$. Let $$$f_i$$$ be the answer for considering tasks $$$[i,n]$$$ only and assuming that $$$S=1$$$. It holds that $$$f_i=\max(f_{i-...
real
#include "testlib.h" using namespace std; // Accepted iff |a - b| / max(1, |b|) <= 1e-6 (statement's formal condition). const double EPS = 1e-6; int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); for (int tc = 1; tc <= t; tc++) { setTestCase(tc); doub...
null
#include <bits/stdc++.h> using namespace std; // Editorial: f_i = max(f_{i+1}, f_{i+1} * (1 - p_i/100) + c_i), processed from the back. int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); vector<int> c(n), p(n); for (int i = 0; i < n; i++) scanf("%d %d...
#include "testlib.h" using namespace std; // -t cases -n max n per case -sumn total cap -exact 1 (every case gets n) // -minc -maxc -minp -maxp ranges; -pzero / -pfull: percent chance p forced to 0 / 100 // -mode random|incc|decc (c sorted ascending / descending) -seed (only perturbs the RNG) int main(int argc, char* ...
# minimum: n = 1, smallest values, many tiny cases -t 1 -n 1 -minc 1 -maxc 1 -minp 0 -maxp 0 -seed 1 -t 1 -n 1 -minc 1 -maxc 1 -minp 100 -maxp 100 -seed 2 -t 1000 -n 1 -exact 1 -sumn 1000 -seed 3 -t 1000 -n 5 -exact 1 -sumn 5000 -seed 4 -t 1000 -n 100 -exact 1 -sumn 100000 -seed 5 # maximum single case, random -t 1 -n ...
2218G
The 67th Iteration of "Counting is Fun"
https://codeforces.com/contest/2218/problem/G
2,218
Codeforces Round 1090 (Div. 4)
2026-04-04
G
1,800
[ "implementation", "math" ]
2
256
false
stdio
*Macaque has taken you to his habitat, shown you his job, and even forced you to do his homework for him. While it might have not been easy for you, Macaque has grown to like you and even, possibly, harbour some gratitude towards you. However, all is not finished, for Macaque has to solve his most difficult problem yet...
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of each test case follows: - The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m \le n \le 2 \cdot 10^5$$$) — the number of people and the total duration of the process. - The second line c...
For each test case, output a single integer — the number of distinct arrays $$$a$$$ that result in the given array $$$b$$$, modulo $$${\color{red}{676767677}}$$$.
null
In the first test case, the only 2 valid arrays are $$$[0, 1, 3, 0]$$$ and $$$[0, 2, 3, 0]$$$. At time $$$0$$$, the $$$1$$$-st and $$$4$$$-th people sit down. Then person $$$2$$$ sits down at time $$$1$$$. If $$$a_2$$$ were $$$0$$$, person $$$2$$$ would have sat down at time $$$0$$$, and if $$$a_2$$$ were greater than ...
[ { "input": "7\n4 3\n0 1 2 0\n8 4\n0 1 2 3 1 2 0 1\n9 5\n1 0 1 3 4 3 2 1 0\n15 14\n3 0 1 2 3 4 5 6 7 8 9 10 11 12 13\n5 5\n4 3 0 1 2\n5 2\n0 1 1 1 0\n3 2\n0 1 1\n", "output": "2\n0\n1920\n138007136\n8\n0\n0\n" } ]
**Hint 1** When is there no valid $$$a$$$? **Hint 2** Remember for a person $$$i$$$ with $$$b_i \gt 0$$$ to be able to sit down, one of their neighbours already needs to be sat down. **Hint 3** What do you notice about people where $$$b_i = 0$$$? **Hint 4** If $$$b_i = 0$$$, then $$$a_i$$$ must also equal $$$0$$...
unique
#include "testlib.h" using namespace std; int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); for (int tc = 1; tc <= t; tc++) { setTestCase(tc); long long jury = ans.readLong(); long long part = ouf.readLong(LLONG_MIN, LLONG_MAX, "answer"); ...
null
#include <bits/stdc++.h> using namespace std; static const long long MOD = 676767677LL; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<int> b(n); vector<int> cnt(m, 0); for (int...
#include "testlib.h" #include <numeric> using namespace std; static void ensureAllValues(vector<int>& b, int m) { int n = (int)b.size(); for (int v = 0; v < m; v++) b[v % n] = v; } // -t cases -n max n per case -sumn total n cap -m max m (optional, defaults to n) // -mode random|max|min|invalid|spread|chain|c...
# minimum and tiny -t 1 -n 1 -sumn 1 -mode min -seed 1 -t 10 -n 3 -sumn 30 -mode random -seed 2 -t 50 -n 4 -sumn 200 -mode random -seed 3 # sample-shaped -t 7 -n 15 -sumn 60 -mode spread -seed 4 # maximum n single case -t 1 -n 200000 -sumn 200000 -m 200000 -mode spread -seed 5 -t 1 -n 200000 -sumn 200000 -m 50000 -mode...
2219A
Grid L
https://codeforces.com/contest/2219/problem/A
2,219
Codeforces Round 1093 (Div. 1)
2026-04-13
A
1,400
[ "brute force", "constructive algorithms", "math", "number theory" ]
2
256
false
stdio
Roger has $$$p$$$ unit-length segments and $$$q$$$ L-shaped pieces, each formed by joining two unit-length segments at a right angle. ![](https://espresso.codeforces.com/0cbf71a5c455440918b2789177b20f6f676173c2.png) He wants to use all of these pieces, with no piece left unused, to form a grid of dimensions $$$n \tim...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows. The first line of each test case contains two integers $$$p$$$ and $$$q$$$ ($$$1 \le p, q \le 10^8$$$).
For each test case, print any valid $$$n$$$ and $$$m$$$ such that it's possible to construct $$$n \times m$$$ using all pieces. If there are no such $$$n$$$ and $$$m$$$, print $$$-1$$$.
null
Here are the constructions for examples 2, 3, and 4. We use a different color for different L-shaped pieces, black for all unit-length segments. ![](https://espresso.codeforces.com/188cc89f1253f1c7fdb045e6a75db169eb725a05.png)
[ { "input": "7\n1 2\n1 3\n5 1\n2 5\n2 10\n100000000 100000000\n1 1\n", "output": "-1\n1 2\n1 2\n2 2\n2 4\n-1\n-1\n" } ]
The following is the key observation of the problem. **Claim.** We can fill an $$$m\times n$$$ grid using $$$p$$$ segments and $$$q$$$ L's if and only if $$$p+2q = m(n+1)+n(m+1)$$$ and $$$p \ge \vert m-n\vert$$$. Proof. Necessity is clear: $$$p+2q = m(n+1)+n(m+1)$$$ follows from looking at the total number of edges, ...
multiple
#include "testlib.h" using namespace std; using i128 = __int128_t; static i128 gridEdges(long long n, long long m) { return (i128)m * (n + 1) + (i128)n * (m + 1); } static bool pairValid(long long p, long long q, long long n, long long m) { if (n < 1 || m < 1) return false; if (gridEdges(n, m) != (i128)p...
null
#include <bits/stdc++.h> using namespace std; // Editorial: iterate n = 1 .. floor(sqrt(p/2 + q)), m = (p+2q-n)/(2n+1). int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { long long p, q; cin >> p >> q; long long s = p + 2 * q; ...
#include "testlib.h" #include <optional> using namespace std; // -t cases -maxp -maxq -mode random|impossible|valid|edge|max // impossible: force p+2q with no (n,m) solution // valid: force at least one valid pair from small brute enumeration // edge: p near |m-n| bound // max: p=q=1e8 // -se...
# minimum t and values -t 1 -maxp 1 -maxq 1 -seed 1 -t 100 -maxp 1 -maxq 1 -seed 2 -t 1 -maxp 1 -maxq 2 -seed 3 -t 1 -maxp 1 -maxq 3 -seed 4 # sample-like -t 1 -maxp 5 -maxq 1 -mode valid -seed 5 -t 1 -maxp 2 -maxq 5 -mode valid -seed 6 -t 1 -maxp 2 -maxq 10 -mode valid -seed 7 # impossible cases -t 10 -mode impossible...
2219B1
Unique Values (Easy version)
https://codeforces.com/contest/2219/problem/B1
2,219
Codeforces Round 1093 (Div. 1)
2026-04-13
B1
1,900
[ "binary search", "constructive algorithms", "divide and conquer", "interactive", "math" ]
2
256
true
stdio
**The difference between the easy version and hard version is the maximum number of queries allowed. In this version, it is 66.** There is a secret array $$$a$$$ of length $$$2n+1$$$, whose elements are integers from $$$1$$$ to $$$n$$$. Each value appears exactly twice, except for one value, which appears exactly thre...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$). The array $$$a$$$ is fixed for the test case and does not ch...
null
For each test case, first read a single integer $$$n$$$. You may ask up to $$$66$$$ queries in each test case. To ask a query, print a line in the format: - ? $$$k$$$ $$$s_1$$$ $$$s_2$$$ $$$\ldots$$$ $$$s_k$$$ ($$$s_i \neq s_j$$$ for $$$i \neq j$$$, $$$1 \le s_i \le 2 \cdot n + 1$$$) As a response to the query, you...
The secret array is $$$a = [1, 1, 1, 2, 2]$$$. In the first query, we ask for the number of values that appear exactly once in $$$[a_1, a_2] = [1, 1]$$$, since value 1 is repeated, the answer is 0. In the second query, we ask for the number of values that appear exactly once in $$$[a_1, a_4] = [1, 2]$$$, since values...
[ { "input": "1\n2\n\n0\n\n2\n\n2\n\n0\n\n1\n", "output": "? 2 1 2\n\n? 2 1 4\n\n? 2 1 5\n\n? 5 1 2 3 4 5\n\n? 4 1 2 3 4\n\n! 1 2 3\n" } ]
There are many solutions that use $$$6 \cdot \log_2(2 \cdot n + 1)$$$ queries. Here is one: Notice that if we query for the set $$$S$$$ and its complement $$$T$$$ (i.e. $$$T = \{1, 2, \ldots, 2 \cdot n + 1\} \setminus S$$$) we can know how many of the three special indices are in $$$S$$$ and how many in $$$T$$$. If t...
interactive
#include "testlib.h" // Interactive problem: the verdict comes from interactor.cpp. Required by the harness build. int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); quitf(_ok, "interactive problem, judged by the interactor"); }
#include "testlib.h" #include <bits/stdc++.h> using namespace std; // Non-adaptive: array a is read from the test. Per test case at most 66 queries // "? k s1 ... sk" (distinct indices in [1, 2n+1], k >= 1). Response = count of // distinct values that appear exactly once among the selected elements. // Final answer "!...
#include <bits/stdc++.h> using namespace std; // Official shuffle + parity binary search (CF2219B2 editorial / gym scoring solution). // chk(x,k) is true when query answer parity differs from k — then shrink left. int n, w[2005]; int ask(int k, const function<void()>& printIdx) { cout << "? " << k; printIdx(...
#include "testlib.h" #include <bits/stdc++.h> using namespace std; // -t cases, -n max n per case, -sumn cap on total n (default 20000), // -fixed 1: every case has exactly n (as long as budget allows), // -triple V: value that appears three times (0 = random per case), // -shuffle 0: keep sorted-by-value layout, // -...
# minimum n=2 and many tiny cases -t 1 -n 2 -triple 1 -shuffle 0 -t 500 -n 2 -fixed 1 -shuffle 1 -seed 1 -t 200 -n 3 -fixed 1 -seed 2 -t 100 -n 5 -fixed 1 -seed 3 # kills wrong_guess when triple is not at 1,2,3 -t 1 -n 10 -triple 5 -shuffle 1 -seed 4 -t 1 -n 50 -triple 17 -shuffle 1 -seed 5 -t 1 -n 100 -triple 42 -shuf...
2219B2
Unique Values (Hard version)
https://codeforces.com/contest/2219/problem/B2
2,219
Codeforces Round 1093 (Div. 1)
2026-04-13
B2
2,000
[ "binary search", "bitmasks", "constructive algorithms", "interactive" ]
2
256
true
stdio
**The difference between the easy version and hard version is the maximum number of queries allowed. In this version, it is 33.** There is a secret array $$$a$$$ of length $$$2n+1$$$, whose elements are integers from $$$1$$$ to $$$n$$$. Each value appears exactly twice, except for one value, which appears exactly thre...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$). The array $$$a$$$ is fixed for the test case and does not ch...
null
For each test case, first read a single integer $$$n$$$. You may ask up to $$$33$$$ queries in each test case. To ask a query, print a line in the format: - ? $$$k$$$ $$$s_1$$$ $$$s_2$$$ $$$\ldots$$$ $$$s_k$$$ ($$$s_i \neq s_j$$$ for $$$i \neq j$$$, $$$1 \le s_i \le 2 \cdot n + 1$$$) As a response to the query, you...
The secret array is $$$a = [1, 1, 1, 2, 2]$$$. In the first query, we ask for the number of values that appear exactly once in $$$[a_1, a_2] = [1, 1]$$$, since value 1 is repeated, the answer is 0. In the second query, we ask for the number of values that appear exactly once in $$$[a_1, a_4] = [1, 2]$$$, since values...
[ { "input": "1\n2\n\n0\n\n2\n\n2\n\n0\n\n1\n", "output": "? 2 1 2\n\n? 2 1 4\n\n? 2 1 5\n\n? 5 1 2 3 4 5\n\n? 4 1 2 3 4\n\n! 1 2 3\n" } ]
Consider an array $$$b$$$ from $$$a$$$ where $$$b_i = 1$$$ iff $$$a_i$$$ is the first appearance in $$$a$$$ of that value, $$$b_i = -1$$$ iff $$$a_i$$$ is the second appearance in $$$a$$$ of that value and $$$b_i = 0$$$ iff $$$a_i$$$ is the third appearance in $$$a$$$ of that value. Notice that querying $$$S = \{1, 2,...
interactive
#include "testlib.h" // Interactive problem: the verdict comes from interactor.cpp. Required by the harness build. int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); quitf(_ok, "interactive problem, judged by the interactor"); }
#include "testlib.h" #include <bits/stdc++.h> using namespace std; // Non-adaptive: array a is read from the hack-format test. Per test case at most 33 queries // "? k s1 ... sk" (distinct indices in [1, 2n+1]) answered with the count of values that // appear exactly once among the selected elements. Final "! x y z" m...
#include <bits/stdc++.h> using namespace std; // Editorial (B2): parity of prefix unique-count vs prefix length detects a triple value in // the queried set. Three binary searches find the last, middle, and first occurrences. // At most 3 * ceil(log2(2n+1)) <= 33 queries per test case. static int n; int ask(const ve...
#include "testlib.h" #include <bits/stdc++.h> using namespace std; // Hack-format generator. Options: // -t cases, -n max n per case, -sumn cap on total n (default 20000), // -fixed 1: every case uses n = min(maxn, remaining budget), // -triple v: force triple value (0 = random each case), // -mode random|sort...
# bundled sample (manual/01_sample.in) -t 1 -n 2 -mode sampleish -triple 1 # tiny and many small cases -t 1 -n 2 -mode random -seed 1 -t 5 -n 3 -mode random -seed 2 -t 10 -n 4 -mode random -seed 3 -t 30 -n 5 -mode random -seed 4 -t 1 -n 2 -mode sorted -triple 2 -t 1 -n 3 -mode spread -triple 1 -t 1 -n 4 -mode spread -t...
2219D
MEX Replacement on Tree
https://codeforces.com/contest/2219/problem/D
2,219
Codeforces Round 1093 (Div. 1)
2026-04-13
D
2,700
[ "data structures", "implementation", "math", "trees" ]
3.5
256
false
stdio
You are given a tree rooted at $$$1$$$ with $$$n$$$ vertices and a permutation $$$p$$$ of length $$$n$$$ consisting of integers $$$0, 1, \ldots, n - 1$$$, where $$$p_v$$$ represents the weight of vertex $$$v$$$. Let $$$S_v$$$ denote the set of weights written on the vertices belonging to the path from $$$1$$$ to $$$v$...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of vertices of the tree. The se...
For each test case, output a single line containing an integer: the maximum value of $$$\sum\limits_{v = 1}^n f(v)$$$ after performing the above operation no more than once (possibly zero).
null
In the first example, not doing any operation is optimal, so the answer is $$$1$$$. In the second example, we have - $$$f(1) = \mathrm{MEX}(\{p_1\}) = \mathrm{MEX}(\{1\}) = 0$$$ - $$$f(2) = \mathrm{MEX}(\{p_1, p_2\}) = \mathrm{MEX}(\{1, 0\}) = 2$$$ - $$$f(3) = \mathrm{MEX}(\{p_1, p_3\}) = \mathrm{MEX}(\{1, 2\}) = 0$$...
[ { "input": "7\n1\n0\n3\n1 0 2\n1 2\n1 3\n6\n1 4 5 2 0 3\n1 4\n1 5\n6 2\n2 5\n2 3\n5\n1 2 3 0 4\n1 2\n2 3\n3 4\n4 5\n10\n9 8 7 1 3 2 5 4 6 0\n6 10\n3 1\n8 7\n4 2\n2 8\n7 5\n10 9\n3 9\n6 4\n9\n8 4 0 6 5 7 3 1 2\n8 3\n4 2\n4 6\n9 3\n7 6\n1 5\n8 5\n9 2\n7\n1 5 2 3 6 0 4\n7 6\n4 3\n7 2\n5 1\n2 4\n6 5\n", "output...
Root out the simple case: It's obvious that applying the operation on $$$v$$$ where $$$p_v \lt f(v)$$$ is useless, since it would decrease $$$f(x)$$$ for every $$$x$$$ in $$$v$$$'s subtree. So from now on, we assume $$$p_v \gt f(v)$$$. Rephrase of operation (kind of) : To understand how the $$$f(x)$$$ would cha...
unique
#include "testlib.h" using namespace std; int main(int argc, char* argv[]) { registerTestlibCmd(argc, argv); int t = inf.readInt(); for (int tc = 1; tc <= t; tc++) { setTestCase(tc); long long jury = ans.readLong(); long long part = ouf.readLong(LLONG_MIN, LLONG_MAX, "answer"); ...
null
#include <bits/stdc++.h> using namespace std; using ll = long long; namespace atcoder { namespace internal { unsigned int bit_ceil(unsigned int n) { unsigned int x = 1; while (x < (unsigned int)(n)) x *= 2; return x; } int countr_zero(unsigned int n) { return __builtin_ctz(n); } } // namespace interna...
#include "testlib.h" #include <bits/stdc++.h> using namespace std; // -t cases -n max n -sumn total cap (default 200000) -fixed 1: every case uses max allowed n // -type random|deep|prufer|path|star|starn|caterpillar|broom|spider|binary // -k depth window (deep) or leg count (spider) // -perm random|sorted|rev|identit...
# many tiny cases -t 200 -n 5 -sumn 500 -type random -perm random -seed 1 # single n=1 -t 50 -n 1 -sumn 50 -type star -perm random -seed 2 # small stars and paths -t 30 -n 12 -sumn 360 -type star -perm random -seed 3 -t 30 -n 12 -sumn 360 -type path -perm rev -seed 4 # structured trees -t 15 -n 80 -sumn 1200 -type b...
2220A
Blocked
https://codeforces.com/contest/2220/problem/A
2,220
Codeforces Round 1093 (Div. 2)
2026-04-13
A
800
[ "greedy", "sortings" ]
1
256
false
stdio
Given an array $$$a$$$ of integers of size $$$n$$$, we say that a position $$$1 \le i \le n$$$ is *blocked* if $$$a_i$$$ can be expressed as the sum of a subset of $$$a_1, a_2, \ldots, a_{i-1}$$$ (i.e. there exist $$$1 \le j_1 \lt j_2 \lt \ldots \lt j_k \le i-1$$$ such that $$$a_{j_1} + a_{j_2} + \ldots + a_{j_k}...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 400$$$). The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 200$$$). The second line contains $$$n$$$ integers, denoting the array $$$a$...
For each test case, print any order of $$$a$$$ such that no position is blocked if it exists, otherwise print $$$-1$$$.
null
In the third test case, the array [$$$3, 1, 2$$$] has no position blocked: Position $$$1$$$ is not blocked since $$$3$$$ can't be expressed as the sum of a subset of []. Position $$$2$$$ is not blocked since $$$1$$$ can't be expressed as the sum of a subset of [$$$3$$$]. Position $$$3$$$ is not blocked since $$$2$$$...
[ { "input": "4\n3\n1 5 9\n4\n1 3 3 2\n3\n1 2 3\n1\n1\n", "output": "5 9 1\n-1\n3 1 2\n1\n" } ]
Author: [misteg168](https://codeforces.com/profile/misteg168) Preparation: [misteg168](https://codeforces.com/profile/misteg168) **Hint1** What happens when there are two equal elements? **Solution** Tutorial is loading... **Code** ``` #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> ...
multiple
#include "testlib.h" #include <vector> using namespace std; static bool isBlocked(const vector<int>& a) { int n = (int)a.size(); for (int i = 0; i < n; i++) { int target = a[i]; vector<char> dp(target + 1); dp[0] = 1; for (int j = 0; j < i; j++) { int v = a[j]; ...
null
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (auto& x : a) cin >> x; sort(a.rbegin(), a.rend()); for (int i = 0; i < n - 1; i++) if (a[i] == a[i + 1]) { cout << "-1\n"; return; } for (auto x : ...
#include "testlib.h" using namespace std; // Options: -t, -maxn (default 200), -mode, -seed // Modes: // random random arrays, 1 <= n <= maxn // max_t t test cases each with n = maxn // distinct all elements distinct (sorted unique values then shuffled) // dup force at least one dupli...
# minimum and tiny multi-case files -t 400 -maxn 1 -mode tiny -seed 1 -t 50 -maxn 3 -mode corners -seed 2 -t 30 -maxn 5 -mode random -seed 3 # duplicates -> -1 -t 25 -maxn 50 -mode dup -seed 4 -t 20 -maxn 200 -mode dup -seed 5 -t 15 -maxn 200 -mode all_equal -seed 6 # all distinct -> always solvable -t 25 -maxn 200 -mo...
2220B
OIE Excursion
https://codeforces.com/contest/2220/problem/B
2,220
Codeforces Round 1093 (Div. 2)
2026-04-13
B
1,200
[ "greedy" ]
1
256
false
stdio
Hector is on an excursion with the Spanish Olympiad in Informatics, visiting A Coruña, but he is desperate to sneak away to meet his friends Gustavo, Esomer, and Dani. To do so, he must cross a path guarded by $$$n$$$ volunteers standing in a row, numbered from $$$1$$$ to $$$n$$$; the $$$i$$$-th volunteer watches over ...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. Each test case consists of two lines: - The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$2 \le m \le 10^9$$$...
For each test case, print a line containing either "`YES`" or "`NO`", representing whether Hector can escape. You can output the answer in any case (upper or lower). For example, the strings "`yEs`", "`yes`", "`Yes`", and "`YES`" will be recognized as positive responses.
null
- Case 1: Hector can move right every second without waiting or moving left and escape, because there is no $$$i$$$ such that $$$(a_i + i) \pmod m = 0$$$. - Case 2: One possible strategy is to wait for one second at the starting position and then move right every second without further waiting or moving left.
[ { "input": "6\n8 5\n0 4 0 2 1 0 0 3\n6 2\n1 0 1 0 1 0\n6 2\n1 1 1 1 0 1\n2 10\n6 9\n2 2\n0 1\n5 1000000000\n1 2 3 4 999999999\n", "output": "YES\nYES\nNO\nYES\nYES\nYES\n" } ]
If there exists a contiguous subarray of equal values with length ≥ m, it is impossible to escape. This is because crossing such a block requires at least m seconds, and each position will look in direction 0 at least once in any m consecutive seconds. Otherwise, escape is possible. We can think of the array as consec...
unique
#include "testlib.h" using namespace std; // Unique YES/NO per test. Codeforces accepts any letter case. bool readYesNo(InStream& st, TResult bad, const char* who) { st.maxTokenLength = 32; string s = lowerCase(st.readToken("[A-Za-z]{1,8}", "answer")); if (s == "yes") return true; if (s == "no") return...
null
#include <bits/stdc++.h> using namespace std; // Editorial: impossible iff some contiguous block of equal a_i has length >= m. static bool can_escape(int n, long long m, const vector<int>& a) { for (int i = 0; i < n;) { int j = i + 1; while (j < n && a[j] == a[i]) j++; if (j - i >= m) retur...
#include "testlib.h" using namespace std; // -t cases -n max n per case -sumn cap -m max m (or exact when -fixm 1) // -mode random|constant|alternating|bad_run|good_run|sample_shape|max_vals // -seed (perturbs RNG only) static vector<int> make_array(int n, long long m, const string& mode) { vector<int> a(n); ...
# wrong_always_yes: NO cases with bad_run -t 1 -n 6 -fixn 1 -m 3 -fixm 1 -mode bad_run -seed 1 -t 1 -n 10 -fixn 1 -m 5 -fixm 1 -mode constant -seed 2 # wrong_run_ge_n: m <= n but run length in [m, n) -t 1 -n 20 -fixn 1 -m 5 -fixm 1 -mode bad_run -seed 3 -t 1 -n 50 -fixn 1 -m 7 -fixm 1 -mode bad_run -seed 4 # wrong_rush...
2225A
A Number Between Two Others
https://codeforces.com/contest/2225/problem/A
2,225
Educational Codeforces Round 189 (Rated for Div. 2)
2026-04-21
A
800
[ "greedy", "math" ]
2
512
false
stdio
You are given two integers $$$x$$$ and $$$y$$$ such that $$$y \gt x$$$ and $$$y \bmod x = 0$$$ (that is, $$$y$$$ is divisible by $$$x$$$). Your task is to determine whether there exists an integer $$$z$$$ such that - $$$z$$$ lies between $$$x$$$ and $$$y$$$ (that is, $$$x \lt z \lt y$$$); - $$$z$$$ is divisible...
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. Each test case consists of a single line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x \lt y \le 10^{18}$$$; $$$y \bmod x = 0$$$).
For each test case, print the answer as follows: if the required number $$$z$$$ exists, print `YES`; otherwise, print `NO`. You may print each letter in any case.
null
In the second test case of the example, you can use $$$z = 2$$$. In the third test case of the example, you can use $$$z = 7407407340$$$.
[ { "input": "5\n1 2\n1 3\n1234567890 12345678900\n2 8\n7 84\n", "output": "NO\nYES\nYES\nYES\nYES\n" } ]
There are several different ways to solve this problem. **Solution $$$1$$$ (brute force)** Let us iterate over $$$z$$$ among the numbers $$$2x, 3x, 4x, \dots, y-x$$$ and stop as soon as we find a suitable $$$z$$$ (or run out of numbers). Why does this work fast? If an answer exists, it will always be found among rou...
unique
#include "testlib.h" using namespace std; // Unique YES/NO per test. Codeforces accepts any letter case. bool readYesNo(InStream& st, TResult bad, const char* who) { st.maxTokenLength = 32; string s = lowerCase(st.readToken("[A-Za-z]{1,8}", "answer")); if (s == "yes") return true; if (s == "no") return...
null
#include <bits/stdc++.h> using namespace std; using int128 = __int128_t; // Editorial: z exists iff y != 2x (equivalently y/x != 2). int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { long long x, y; cin >> x >> y; bool ok = (int128)y ...
#include "testlib.h" using namespace std; using int128 = __int128_t; // -t cases (1..10000) // -mode random|no|yes|k2|k3|max|large|wide|intoverflow // -xmax upper bound on x (default 1e18) // -kmax upper bound on multiplier k with y = k*x (default 1e6) // -seed accepted; only perturbs randomness static long long pick...
# minimum and sample-shaped -t 1 -mode k2 -xmax 1 -seed 1 -t 1 -mode k3 -xmax 1 -seed 2 -t 1 -mode yes -xmax 1234567890 -kmax 10 -seed 3 -t 1 -mode k2 -xmax 2 -seed 4 -t 1 -mode yes -xmax 7 -kmax 12 -seed 5 # kill wrong_always_yes / wrong_strict_gt -t 50 -mode k2 -xmax 1000000 -seed 6 -t 50 -mode no -xmax 1000000 -seed...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
19