contest_id stringlengths 1 4 | index stringclasses 43
values | title stringlengths 2 63 | statement stringlengths 51 4.24k | tutorial stringlengths 19 20.4k | tags listlengths 0 11 | rating int64 800 3.5k ⌀ | code stringlengths 46 29.6k ⌀ |
|---|---|---|---|---|---|---|---|
1315 | C | Restoring Permutation | You are given a sequence $b_1, b_2, \ldots, b_n$. Find the lexicographically minimal permutation $a_1, a_2, \ldots, a_{2n}$ such that $b_i = \min(a_{2i-1}, a_{2i})$, or determine that it is impossible. | This problem has a greedy solution. As you know the $b_i$, which is equal to $\min(a_{2i-1}, a_{2i})$, then one of $a_{2i-1}, a_{2i}$ should be equal to $b_i$. Which one? Of course, $a_{2i-1}$, because we want to get the lexicographically minimal answer, and we want to place a smaller number before the larger number. S... | [
"greedy"
] | 1,200 | null |
1316 | A | Grade Allocation | $n$ students are taking an exam. The highest possible score at this exam is $m$. Let $a_{i}$ be the score of the $i$-th student. You have access to the school database which stores the results of all students.
You can change each student's score as long as the following conditions are satisfied:
- All scores are inte... | Since the average score of the class must remain same ,this means the sum of the scores of all students in the class must remain same. We want to maximize the score of the first student and since the minimum score of each student can be zero we can add the scores of the rest of students to the first student as long as ... | [
"implementation"
] | 800 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll test;
cin>>test;
while(test--)
{
ll n,m;
cin>>n>>m;
ll s=0;
for(ll i=1;i<=n;i++)
{
ll x;
cin>>x;
s=s+x;
}
cout<<min(s,m)<<"\n";
}
return 0;
} |
1316 | B | String Modification | Vasya has a string $s$ of length $n$. He decides to make the following modification to the string:
- Pick an integer $k$, ($1 \leq k \leq n$).
- For $i$ from $1$ to $n-k+1$, reverse the substring $s[i:i+k-1]$ of $s$. For example, if string $s$ is qwer and $k = 2$, below is the series of transformations the string goes... | Let the input string $s$ be $s_{1}s_{2}..s_{n}$. We observe the sequence of modifications that the string goes through for some value of $k$. After reversing the first sub-string of length $k$, the string becomes $s_{k}s_{k-1}..s_{1}s_{k+1}s_{k+2}..s_{n}$. Notice that the first character of this string will not be part... | [
"brute force",
"constructive algorithms",
"implementation",
"sortings",
"strings"
] | 1,400 | #include <bits/stdc++.h>
using namespace std;
string modified(string& s, int n, int k) {
string result_prefix = s.substr(k - 1, n - k + 1);
string result_suffix = s.substr(0, k - 1);
if (n % 2 == k % 2)
reverse(result_suffix.begin(), result_suffix.end());
return result_prefix + result_suffix;
}
int main () {
... |
1316 | C | Primitive Primes | It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials $f(x) = a_0 + a_1x + \dots + a_{n-1}x^{n-1}$ and $g(x) = b_0 + ... | We will prove a simple result thereby giving one of the power that satisfies the constraint: We know that cumulative gcd of coefficients is one in both cases. Hence no prime divides all the coefficients of the polynomial. We call such polynomials primitive polynomials. This question in a way tells us that the product o... | [
"constructive algorithms",
"math",
"ternary search"
] | 1,800 | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n,i,m,x,a,p,fir,sec;
cin >> n >> m >> p;
a=0;
for(i=0;i<n;i++)
{
cin >> x;
if(x%p && !a)
{
a=1;
fir=i;
}
}
a=0;
for(i=0;i<m;i++)
{
cin >> x;
if... |
1316 | D | Nash Matrix | Nash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands.
This board game is played on the $n\times n$ board. Rows and columns of this board are numbered from $1$ to $n$. The cell on the intersection of the $r$-th ... | If there exists a valid board satisfying the input matrix, one can notice two types of clusters in the input matrix, first, a cluster of connected cells having the same stopping point and second, a cluster of connected cells which do not have any stopping point, i.e., all having pair $(-1,-1)$ . Among the cells, having... | [
"constructive algorithms",
"dfs and similar",
"graphs",
"implementation"
] | 2,000 | #include<bits/stdc++.h>
using namespace std;
const int M = (1<<10)+5;
char mat[M][M];
int x[M][M],y[M][M];
int n;
bool connect(int p,int q,int r,int s,char d1,char d2)
{
if(x[r][s] == -1)
{
mat[p][q] = d1;
if(mat[r][s] == '\0') mat[r][s] = d2;
return 1;
}
else
return 0;
}
void dfs(int p,int q,char d)
{
... |
1316 | E | Team Building | Alice, the president of club FCB, wants to build a team for the new volleyball tournament. The team should consist of $p$ players playing in $p$ different positions. She also recognizes the importance of audience support, so she wants to select $k$ people as part of the audience.
There are $n$ people in Byteland. Alic... | Idea is DP(bitmask) First sort the people in non-increasing order of $a_{i}$. let $dp[i][mask]$ = maximum strength of the club if we choose players from $1 \ldots i$, mask tells us about the positions in the team which have been covered. Don't worry about the audience part as of now, we will see how it is handled durin... | [
"bitmasks",
"dp",
"greedy",
"sortings"
] | 2,300 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll M=1e5+5;
ll dp[M][(1<<7)+1],skill[M][7];
ll ind[M],a[M];
bool cmp(ll p,ll q)
{
return a[p]>a[q];
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n,p,k;
cin>>n>>p>>k;
memset(dp,-1,sizeof(dp));
for(ll i=1;i<=n;i++... |
1316 | F | Battalion Strength | There are $n$ officers in the Army of Byteland. Each officer has some power associated with him. The power of the $i$-th officer is denoted by $p_{i}$. As the war is fast approaching, the General would like to know the strength of the army.
The strength of an army is calculated in a strange way in Byteland. The Genera... | First lets try to find the initial strength of the army. Let $p_1,p_2,\ldots,p_n$ be the powers of officers in sorted order. . Consider a pair ($i,j$) ($i < j$) and find how much it contributes to the answer, the term $p_i \cdot p_j$ will be present in the strength of the subsets in which both $i$ and $j$ are present a... | [
"data structures",
"divide and conquer",
"probabilities"
] | 2,800 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const ll M=6e5+6;
const ll mod=1e9+7;
ll val[4*M],lt[4*M],rt[4*M];
int no[4*M];
ll pw[M],ipw[M];
int P[M],idx[M],qr[M],n,q;
vector<... |
1320 | A | Journey Planning | Tanya wants to go on a journey across the cities of Berland. There are $n$ cities situated along the main railroad line of Berland, and these cities are numbered from $1$ to $n$.
Tanya plans her journey as follows. First of all, she will choose some city $c_1$ to start her journey. She will visit it, and after that go... | Let's rewrite the equality given in the statement as $c_{i + 1} - b_{c_{i + 1}} = c_i - b_{c_i}$. It means that all cities in our path will have the same value of $i - b_i$; furthermore, all cities with the same such value can always be visited in ascending order. So we may group cities by $i - b_i$, compute the sum in... | [
"data structures",
"dp",
"greedy",
"math",
"sortings"
] | 1,400 | null |
1320 | B | Navigation System | The map of Bertown can be represented as a set of $n$ intersections, numbered from $1$ to $n$ and connected by $m$ one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traver... | Let $d_v$ be the length of the shortest path from $v$ to $t$. If we move from vertex $v$ to vertex $u$ on our path, then: the rebuild will definitely occur if $d_u > d_v - 1$; the rebuild may occur if there exists at least one vertex $w \ne u$ such that $d_w = d_v - 1$ (the navigation system could have built a path thr... | [
"dfs and similar",
"graphs",
"shortest paths"
] | 1,700 | null |
1320 | C | World of Darkraft: Battle for Azathoth | Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.
Roma has a choice to buy \textbf{exactly one} of $n$ different weapons and \textbf{exactly one} of $m$ different armor sets. Weapon $i$ has attack modifier $a_i$ and is worth $ca_i$ coins,... | Let $S_a$ be the set of monsters which may be defeated with a weapon having attack $a$. Then the profit we get, if we use weapon $i$ with attack $a$ and armor $j$ with defense $b$, is $-ca_i-cb_j+( \textrm{the sum of $z_k$ over all monsters $k$ from the set $S_a$ having $y_k < b$})$. We will iterate on weapons in non-d... | [
"brute force",
"data structures",
"sortings"
] | 2,000 | null |
1320 | D | Reachable Strings | In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ starting from the $l$-th character and ending with the $r$-th character as ... | How to determine if two strings can be transformed into each other? Obviously, the number of ones in both strings should be the same. Also the following invariant holds: if all pairs of consecutive ones are deleted, the positions of remaining ones are not affected by any operations. We can prove that these conditions a... | [
"data structures",
"hashing",
"strings"
] | 2,500 | null |
1320 | E | Treeland and Viruses | There are $n$ cities in Treeland connected with $n - 1$ bidirectional roads in such that a way that any city is reachable from any other; in other words, the graph of cities and roads is a tree. Treeland is preparing for a seasonal virus epidemic, and currently, they are trying to evaluate different infection scenarios... | When processing a query, the key idea is to build a compressed version of the tree containing only some important vertices. We are not interested in vertices not belonging to any path between some $v_i$ and $u_i$. Furthermore, we can compress all chains in the tree by deleting all vertices with degree $< 2$ not listed ... | [
"data structures",
"dfs and similar",
"dp",
"shortest paths",
"trees"
] | 3,000 | null |
1320 | F | Blocks and Sensors | Polycarp plays a well-known computer game (we won't mention its name). Every object in this game consists of three-dimensional blocks — axis-aligned cubes of size $1 \times 1 \times 1$. These blocks are unaffected by gravity, so they can float in the air without support. The blocks are placed in cells of size $1 \times... | Initially fill each cell with a colorless block, and then try to paint blocks and delete them if they definitely contradict the sensor data. We have to delete a block if: it is observed by a sensor which should see no blocks; it is observed by at least two sensors that report different block types. In any of these case... | [
"brute force"
] | 3,500 | null |
1321 | A | Contest for Robots | Polycarp is preparing the first programming contest for robots. There are $n$ problems in it, and a lot of robots are going to participate in it. Each robot solving the problem $i$ gets $p_i$ points, and the score of each robot in the competition is calculated as the sum of $p_i$ over all problems $i$ solved by it. For... | Score distribution for problems having $r_i = b_i$ is irrelevant (we can make $p_i = 1$ for all of them). Let's consider the remaining problems. Suppose we have $x$ problems solved by the first robot (and not solved by the second one), and $y$ problems solved by the second robot (and not solved by the first one). If $x... | [
"greedy"
] | 900 | null |
1321 | C | Remove Adjacent | You are given a string $s$ consisting of lowercase Latin letters. Let the length of $s$ be $|s|$. You may perform several operations on this string.
In one operation, you can choose some index $i$ and \textbf{remove} the $i$-th character of $s$ ($s_i$) if \textbf{at least one} of its adjacent characters is the previou... | The optimal answer can be obtained by the following algorithm: choose the maximum possible (alphabetically) letter we can remove and remove it. We can do it naively and it will lead to $O(n^2)$ time complexity. Why is it always true? Suppose we remove the maximum letter $i$ that can be used to remove some other letter ... | [
"brute force",
"constructive algorithms",
"greedy",
"strings"
] | 1,600 | null |
1322 | A | Unusual Competitions | A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher gave Dmitry's class a very strange task — she asked every student... | Obviously, if the number of opening brackets is not equal to the number of closing ones, then since the described operation does not change their number, it will be impossible to get the correct sequence. Otherwise, if their numbers are equal, you can take the entire string and rearrange its $n$ characters so that the ... | [
"greedy"
] | 1,300 | null |
1322 | B | Present | Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realiz... | Let's calculate each bit in the answer separately. Suppose we want to know the value of $k$-th (in 0-indexation) bit in the answer. Then we can notice that we are only interested in bits from $0$-th to $k$-th, which means that we can take all numbers modulo $2^{k+1}$. After that, the sum of the two numbers can't exceed... | [
"binary search",
"bitmasks",
"constructive algorithms",
"data structures",
"math",
"sortings"
] | 2,100 | null |
1322 | C | Instant Noodles | Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You are given a bipartite graph with positive integers in all vertices of the \textbf{right} half. For a subset $S$ of vertices of ... | Let's split vertices of right half of graph in groups in such a way that group consists of vertices with same neighboring set. Then answer equals to $gcd$ of sums of numbers in all groups except the group with empty neighboring set. Let's prove it. If there are some vertices with same list of neighbors then they will b... | [
"graphs",
"hashing",
"math",
"number theory"
] | 2,300 | null |
1322 | D | Reality Show | A popular reality show is recruiting a new cast for the third season! $n$ candidates numbered from $1$ to $n$ have been interviewed. The candidate $i$ has aggressiveness level $l_i$, and recruiting this candidate will cost the show $s_i$ roubles.
The show host reviewes applications of all candidates from $i=1$ to $i=n... | First of all, we will notice that the order of entering doesn't affect the answer. Let's reverse the sequence. We will add people in the non-decreasing order. Let's use dynamic programming: $dp[i][k][cnt]$ is the answer if we processed first $i$ candidates with the maximum value less or equal $k$ and total number of pe... | [
"bitmasks",
"dp"
] | 2,800 | null |
1322 | E | Median Mountain Range | Berland — is a huge country with diverse geography. One of the most famous natural attractions of Berland is the "Median mountain range". This mountain range is $n$ mountain peaks, located on one straight line and numbered in order of $1$ to $n$. The height of the $i$-th mountain top is $a_i$.
"Median mountain range" ... | Let's assume that $1 \le a_i \le 2$. We can notice that if for some $i$ $a_i = a_{i + 1}$, than on $i$-th and $(i+1)$-th positions numbers will stay the same forever. So the only changes will happen to segments of consecutive alternating $1$ and $2$. Now let's look what will happen to such segments after first alignmen... | [
"data structures"
] | 3,300 | null |
1322 | F | Assigning Fares | Mayor of city M. decided to launch several new metro lines during 2020. Since the city has a very limited budget, it was decided not to dig new tunnels but to use the existing underground network.
The tunnel system of the city M. consists of $n$ metro stations. The stations are connected with $n - 1$ bidirectional tun... | Let's assume $c_v$ is the color of vertex v. So, we need to find a coloring of tree, where $c_v$ strictly increases along every path. First of all, if coloring exists, we can renumerate colors so that they will be in range [1, $n$]. Secondly, we can always revert our coloring, make $c_v \rightarrow k + 1 - c_v$. Also, ... | [
"dp",
"trees"
] | 3,500 | null |
1323 | A | Even Subset Sum Problem | You are given an array $a$ consisting of $n$ positive integers. Find a \textbf{non-empty} subset of its elements such that their sum is \textbf{even} (i.e. divisible by $2$) or determine that there is no such subset.
Both the given array and required subset may contain equal values. | If there is an even element in array there is an answer consisting of only it. Otherwise if there is at least two odd elements in array there is an answer consisting of this two elements. Otherwise array is only one odd element and there is no answer. | [
"brute force",
"dp",
"greedy",
"implementation"
] | 800 | null |
1323 | B | Count Subrectangles | You are given an array $a$ of length $n$ and array $b$ of length $m$ both consisting of only integers $0$ and $1$. Consider a matrix $c$ of size $n \times m$ formed by following rule: $c_{i, j} = a_i \cdot b_j$ (i.e. $a_i$ multiplied by $b_j$). It's easy to see that $c$ consists of only zeroes and ones too.
How many s... | Rectangle $[x1; x2][y1; y2]$ consists of only ones iff subsegment $[x1; x2]$ consists of only ones in $a$ and subsegment $[y1; y2]$ consists of only ones in $b$. Let's iterate over divisors of $k$. Let the current divisor be $p$ (i.e. $k = p \cdot q$), so we are interested in number of subsegments consisting of ones of... | [
"binary search",
"greedy",
"implementation"
] | 1,500 | #include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
vector<ll> gao(vector<int> a) {
int n = a.size();
vector<ll> res(n + 1);
int i = 0;
while (i < n) {
if (a[i] == 0) {
i++;
continue;
}
... |
1324 | A | Yet Another Tetris Problem | You are given some Tetris field consisting of $n$ columns. The initial height of the $i$-th column of the field is $a_i$ blocks. On top of these columns you can place \textbf{only} figures of size $2 \times 1$ (i.e. the height of this figure is $2$ blocks and the width of this figure is $1$ block). Note that you \textb... | The answer is "YES" only if all $a_i$ have the same parity (i.e. all $a_i$ are odd or all $a_i$ are even). That's because placing the block doesn't change the parity of the element and the $-1$ operation changes the parity of all elements in the array. | [
"implementation",
"number theory"
] | 900 | for i in range(int(input())):
n = int(input())
cnto = sum(list(map(lambda x: int(x) % 2, input().split())))
print('YES' if cnto == 0 or cnto == n else 'NO') |
1324 | B | Yet Another Palindrome Problem | You are given an array $a$ consisting of $n$ integers.
Your task is to determine if $a$ has some \textbf{subsequence} of length at least $3$ that is a palindrome.
Recall that an array $b$ is called a \textbf{subsequence} of the array $a$ if $b$ can be obtained by removing some (possibly, zero) elements from $a$ (not ... | The first observation is that we can always try to find the palindrome of length $3$ (otherwise, we can remove some characters from the middle until its length becomes $3$). The second observation is that the palindrome of length $3$ is two equal characters and some other (maybe, the same) character between them. Now t... | [
"brute force",
"strings"
] | 1,100 | for i in range(int(input())):
n = int(input())
s = list(map(int, input().split()))
ok = False
for i in range(n):
for j in range(i + 2, n):
if s[i] == s[j]: ok = True
print('YES' if ok else 'NO') |
1324 | C | Frog Jumps | There is a frog staying to the left of the string $s = s_1 s_2 \ldots s_n$ consisting of $n$ characters (to be more precise, the frog initially stays at the cell $0$). Each character of $s$ is either 'L' or 'R'. It means that if the frog is staying at the $i$-th cell and the $i$-th character is 'L', the frog can jump o... | The only observation we need is that we don't need to jump left at all. This only decreases our position so we have less freedom after the jump to the left. Then, to minimize $d$, we only need to jump between the closest 'R' cells. So, if we build the array $b = [0, r_1, r_2, \dots, r_k, n + 1]$, where $r_i$ is the pos... | [
"binary search",
"data structures",
"dfs and similar",
"greedy",
"implementation"
] | 1,100 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
vector<int> pos;
pos.push_back(0);
for (int i = 0; i < int(s.size()); ++i) {
if (s[i] == 'R') p... |
1324 | D | Pair of Topics | The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called \textbf{good} if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your tas... | Let's rewrite the inequality from $a_i + a_j > b_i + b_j$ to $(a_i - b_i) + (a_j - b_j) > 0$. This looks much simpler. Let's build the array $c$ where $c_i = a_i - b_i$ and sort this array. Now our problem is to find the number of pairs $i < j$ such that $c_i + c_j > 0$. Let's iterate over all elements of $c$ from left... | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | 1,400 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<int> a(n), b(n);
for (auto &it : a) cin >> it;
for (auto &it : b) cin >> it;
vector<int> c(n);
for (int i = 0; i < n; ++i) {
c[i]... |
1324 | E | Sleeping Schedule | Vova had a pretty weird sleeping schedule. There are $h$ hours in a day. Vova will sleep exactly $n$ times. The $i$-th time he will sleep exactly after $a_i$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is $0$). Each time Vova sleeps \textbf{e... | This is a very standard dynamic programming problem. Let $dp_{i, j}$ be the maximum number of good sleeping times if Vova had a sleep $i$ times already and the number of times he goes to sleep earlier by one hour is exactly $j$. Then the value $\max\limits_{j=0}^{n} dp_{n, j}$ will be the answer. Initially, all $dp_{i,... | [
"dp",
"implementation"
] | 1,700 | #include <bits/stdc++.h>
using namespace std;
bool in(int x, int l, int r) {
return l <= x && x <= r;
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, h, l, r;
cin >> n >> h >> l >> r;
vector<int> a(n);
for (auto &it : a) cin >> it;
vector<v... |
1324 | F | Maximum White Subtree | You are given a tree consisting of $n$ vertices. A tree is a connected undirected graph with $n-1$ edges. Each vertex $v$ of this tree has a color assigned to it ($a_v = 1$ if the vertex $v$ is white and $0$ if the vertex $v$ is black).
You have to solve the following problem for each vertex $v$: what is the maximum d... | This problem is about the "rerooting" technique. Firstly, let's calculate the answer for some fixed root. How can we do this? Let $dp_v$ be the maximum possible difference between the number of white and black vertices in some subtree of $v$ (yes, the subtree of the rooted tree, i.e. $v$ and all its direct and indirect... | [
"dfs and similar",
"dp",
"graphs",
"trees"
] | 1,800 | #include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<int> dp;
vector<int> ans;
vector<vector<int>> g;
void dfs(int v, int p = -1) {
dp[v] = a[v];
for (auto to : g[v]) {
if (to == p) continue;
dfs(to, v);
dp[v] += max(dp[to], 0);
}
}
void dfs2(int v, int p = -1) {
ans[v] = dp[v];
for (auto ... |
1325 | A | EhAb AnD gCd | You are given a positive integer $x$. Find \textbf{any} such $2$ positive integers $a$ and $b$ such that $GCD(a,b)+LCM(a,b)=x$.
As a reminder, $GCD(a,b)$ is the greatest integer that divides both $a$ and $b$. Similarly, $LCM(a,b)$ is the smallest integer such that both $a$ and $b$ divide it.
It's guaranteed that the ... | $a=1$ and $b=x-1$ always work. | [
"constructive algorithms",
"greedy",
"number theory"
] | 800 | "#include <bits/stdc++.h>\nusing namespace std;\nint main()\n{\n int t;\n scanf(\"%d\",&t);\n while (t--)\n {\n \tint x;\n \tscanf(\"%d\",&x);\n \tprintf(\"1 %d\\n\",x-1);\n }\n}" |
1325 | B | CopyCopyCopyCopyCopy | Ehab has an array $a$ of length $n$. He has just enough free time to make a new array consisting of $n$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?
A sequence $a$ is a subsequence of an array $b$ if $a$ can be obtained from $b$ by deletion o... | Let the number of distinct elements in $a$ be called $d$. Clearly, the answer is limited by $d$. Now, you can construct your subsequence as follows: take the smallest element from the first copy, the second smallest element from the second copy, and so on. Since there are enough copies to take every element, the answer... | [
"greedy",
"implementation"
] | 800 | "#include <bits/stdc++.h>\nusing namespace std;\nint main()\n{\n int t;\n scanf(\"%d\",&t);\n while (t--)\n {\n \tint n;\n \tscanf(\"%d\",&n);\n \tset<int> s;\n \twhile (n--)\n \t{\n \t\tint a;\n \t\tscanf(\"%d\",&a);\n \t\ts.insert(a);\n \t}\n \tprintf(\"%d\\n\",s.size());\n ... |
1325 | C | Ehab and Path-etic MEXs | You are given a tree consisting of $n$ nodes. You want to write some labels on the tree's edges such that the following conditions hold:
- Every label is an integer between $0$ and $n-2$ inclusive.
- All the written labels are distinct.
- The largest value among $MEX(u,v)$ over all pairs of nodes $(u,v)$ is as small a... | Notice that there will be a path that passes through the edge labeled $0$ and the edge labeled $1$ no matter how you label the edges, so there's always a path with $MEX$ $2$ or more. If any node has degree 3 or more, you can distribute the labels $0$, $1$, and $2$ to edges incident to this node and distribute the rest ... | [
"constructive algorithms",
"dfs and similar",
"greedy",
"trees"
] | 1,500 | "#include <bits/stdc++.h>\nusing namespace std;\nvector<int> v[100005];\nint ans[100005];\nint main()\n{\n\tint n;\n\tscanf(\"%d\",&n);\n\tfor (int i=1;i<n;i++)\n\t{\n\t\tint a,b;\n\t\tscanf(\"%d%d\",&a,&b);\n\t\tv[a].push_back(i);\n\t\tv[b].push_back(i);\n\t\tans[i]=-1;\n\t}\n\tpair<int,int> mx(0,0);\n\tfor (int i=1;i... |
1325 | D | Ehab the Xorcist | Given 2 integers $u$ and $v$, find the shortest array such that bitwise-xor of its elements is $u$, and the sum of its elements is $v$. | First, let's look at some special cases. If $u>v$ or $u$ and $v$ have different parities, there's no array. If $u=v=0$, the answer is an empty array. If $u=v \neq 0$, the answer is $[u]$. Now, the length is at least 2. Let $x=\frac{v-u}{2}$. The array $[u,x,x]$ satisfies the conditions, so the length is at most 3. We j... | [
"bitmasks",
"constructive algorithms",
"greedy",
"number theory"
] | 1,700 | "#include <bits/stdc++.h>\nusing namespace std;\nint main()\n{\n\tlong long u,v;\n\tscanf(\"%I64d%I64d\",&u,&v);\n\tif (u%2!=v%2 || u>v)\n\t{\n\t\tprintf(\"-1\");\n\t\treturn 0;\n\t}\n\tif (u==v)\n\t{\n\t\tif (!u)\n\t\tprintf(\"0\");\n\t\telse\n\t\tprintf(\"1\\n%I64d\",u);\n\t\treturn 0;\n\t}\n\tlong long x=(v-u)/2;\n\... |
1325 | E | Ehab's REAL Number Theory Problem | You are given an array $a$ of length $n$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.
A sequence $a$ is a subsequence of an array $b$ if $a$ can be obtained from $b$ b... | Notice that for each element in the array, if some perfect square divides it, you can divide it by that perfect square, and the problem won't change. Let's define normalizing a number as dividing it by perfect squares until it doesn't contain any. Notice than any number that has 3 different prime divisors has at least ... | [
"brute force",
"dfs and similar",
"graphs",
"number theory",
"shortest paths"
] | 2,600 | "#include <bits/stdc++.h>\nusing namespace std;\n#define MX 1000000\nint lp[MX+5],dist[MX+5];\nvector<int> d[MX+5],v[MX+5],pr;\nvector<vector<int> > e;\nint main()\n{\n pr.push_back(1);\n\tfor (int i=2;i<=MX;i++)\n\t{\n\t\tif (!lp[i])\n\t\t{\n\t\t pr.push_back(i);\n\t\t\tfor (int j=i;j<=MX;j+=i)\n\t\t\tlp[j]=i;\n... |
1325 | F | Ehab's Last Theorem | It's the year 5555. You have a graph, and you want to find a long cycle and a huge independent set, just because you can. But for now, let's just stick with finding either.
Given a connected graph with $n$ vertices, you can choose to either:
- find an independent set that has \textbf{exactly} $\lceil\sqrt{n}\rceil$ v... | Let $sq$ denote $\lceil\sqrt{n}\rceil$. If you're not familiar with back-edges, I recommend reading this first. Let's take the DFS tree of our graph. Assume you're currently in node $u$ in the DFS. If $u$ has $sq-1$ or more back-edges, look at the one that connects $u$ to its furthest ancestor. It forms a cycle of leng... | [
"constructive algorithms",
"dfs and similar",
"graphs",
"greedy"
] | 2,500 | "#include <bits/stdc++.h>\nusing namespace std;\nset<pair<int,int> > s;\nvector<int> v[100005];\nbool del[100005];\nint deg[100005],occ[100005];\nvoid remove(int node)\n{\n if (del[node])\n return;\n\ts.erase({deg[node],node});\n\tdel[node]=1;\n\tfor (int u:v[node])\n\t{\n\t\tif (!del[u])\n\t\t{\n\t\t\ts.erase({d... |
1326 | A | Bad Ugly Numbers | You are given a integer $n$ ($n > 0$). Find \textbf{any} integer $s$ which satisfies these conditions, or report that there are no such numbers:
In the decimal representation of $s$:
- $s > 0$,
- $s$ consists of $n$ digits,
- no digit in $s$ equals $0$,
- $s$ is not divisible by any of it's digits. | If $n = 1$, no solution exists. Otherwise, if $n \geq 2$, the number $\overline{2 3 3 \ldots 3}$ ($n$ digits) satisfies all conditions, because it is not divisible by $2$ and $3$. | [
"constructive algorithms",
"number theory"
] | 1,000 | null |
1326 | B | Maximums | Alicia has an array, $a_1, a_2, \ldots, a_n$, of non-negative integers. For each $1 \leq i \leq n$, she has found a non-negative integer $x_i = max(0, a_1, \ldots, a_{i-1})$. Note that for $i=1$, $x_i = 0$.
For example, if Alicia had the array $a = \{0, 1, 2, 0, 3\}$, then $x = \{0, 0, 1, 2, 2\}$.
Then, she calculate... | Let's restore $a_1, a_2, \ldots, a_n$ from left to right. $a_1 = b_1$. For $i>1$, $x_i = \max({a_1, \ldots, a_{i-1}})$, so we can maintain the maximum of previous elements and get the value of $x_i$. Using this value, we can restore $a_i$ as $b_i + x_i$. | [
"implementation",
"math"
] | 900 | "#include <cmath>\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <string>\n#include <set>\n#include <map>\n#include <list>\n#include <time.h>\n#include <math.h>\n#include <random>\n#include <deque>\n#include <queue>\n#include <cassert>\n#include <unordered_map>\n#include <unordered_set>\n#inclu... |
1326 | C | Permutation Partitions | You are given a permutation $p_1, p_2, \ldots, p_n$ of integers from $1$ to $n$ and an integer $k$, such that $1 \leq k \leq n$. A permutation means that every number from $1$ to $n$ is contained in $p$ exactly once.
Let's consider all partitions of this permutation into $k$ disjoint segments. Formally, a partition is... | Note that the maximum possible partition value is equal to $(n - k + 1) + \ldots + (n - 1) + n$. Let's define $a_1, a_2, \ldots, a_k$ as positions of the numbers $(n-k+1), \ldots, n$ in the increasing order ($a_1 < a_2 < \ldots < a_k$). The number of partitions with the maximum possible value is equal to $\prod\limits_... | [
"combinatorics",
"greedy",
"math"
] | 1,300 | "#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int MOD = 998244353;\n\nint n, k, a;\n\nint main()\n{\n ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n cin >> n >> k;\n int p = -1;\n int ans = 1;\n long long sum = 0;\n for (int i = 0; i < n; i++)\n {\n cin >> a;\n if (a... |
1326 | D2 | Prefix-Suffix Palindrome (Hard version) | \textbf{This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.}
You are given a string $s$, consisting of lowercase English letters. Find the longest string, $t$, which sati... | Each possible string $t$ can be modeled as $s[1..l] + s[(n-r+1)..n]$ for some numbers $l,r$ such that $0 \leq l, r$ and $l + r \leq n$. Let's find the maximum integer $0 \leq k \leq \lfloor \frac{n}{2} \rfloor$ such that $s_1 = s_n, s_2 = s_{n-1}, \ldots, s_k = s_{n-k+1}$. In some optimal solution, where $t$ is as long... | [
"binary search",
"greedy",
"hashing",
"string suffix structures",
"strings"
] | 1,800 | "#include <bits/stdc++.h>\n\nusing namespace std;\n\nconst int M = (int)(2e6 + 239);\n\nint pref[M], c;\n\nstring solve_palindrome(const string& s)\n{\n string a = s;\n reverse(a.begin(), a.end());\n a = s + \"#\" + a;\n c = 0;\n for (int i = 1; i < (int)a.size(); i++)\n {\n while (c != 0 && a[... |
1326 | E | Bombs | You are given a permutation, $p_1, p_2, \ldots, p_n$.
Imagine that some positions of the permutation contain bombs, such that there exists at least one position without a bomb.
For some fixed configuration of bombs, consider the following process. Initially, there is an empty set, $A$.
For each $i$ from $1$ to $n$:
... | Let's come up with some criteria that answer is $< x$. We claim that the answer is $< x$ if: There is at least one bomb after the rightmost value $\geq x$. There are at least two bombs after the next rightmost value $\geq x$.... ... There are at least $k$ bombs after the $k$-th rightmost value $\geq x$. Let $ans_i$ be ... | [
"data structures",
"two pointers"
] | 2,400 | null |
1326 | F2 | Wise Men (Hard Version) | \textbf{This is the hard version of the problem. The difference is constraints on the number of wise men and the time limit. You can make hacks only if all versions of this task are solved.}
$n$ wise men live in a beautiful city. Some of them know each other.
For each of the $n!$ possible permutations $p_1, p_2, \ldo... | For each binary string $s$, let's calculate $f(s)$ - the number of permutations, such that, if $s_i=1$, then $p_i$ and $p_{i+1}$ know each other, otherwise, they may know or don't know each other. To get real answers, we may use inclusion-exclusion, which may be optimized using a straightforward sum over subsets dp. To... | [
"bitmasks",
"dp",
"math"
] | 3,200 | "#include <cmath>\n#include <functional>\n#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <string>\n#include <set>\n#include <map>\n#include <list>\n#include <time.h>\n#include <math.h>\n#include <random>\n#include <deque>\n#include <queue>\n#include <cassert>\n#include <unordered_map>\n#include ... |
1326 | G | Spiderweb Trees | Let's call a graph with $n$ vertices, each of which has it's own point $A_i = (x_i, y_i)$ with integer coordinates, a planar tree if:
- All points $A_1, A_2, \ldots, A_n$ are different and no three points lie on the same line.
- The graph is a tree, i.e. there are exactly $n-1$ edges there exists a path between any pa... | Let's hang the tree on the vertex $1$. After that, we will calculate the value $dp_i$ for all vertices $i$, which is equal to the number of good partitions of the subtree of the vertex $i$ (subtree in the rooted tree). The answer to the problem in these definitions is $dp_1$. To calculate these values let's make dfs. W... | [
"dp",
"geometry",
"trees"
] | 3,500 | "#include <bits/stdc++.h>\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair<int, int> pi;\n#define prev _prev\n#define stack _stack\n\nll scal(pi a, pi b)\n{\n return (ll)a.first * (ll)a.second + (ll)b.first * (ll)b.second;\n}\n\nll mul(pi a, pi b)\n{\n return (ll)a.first * (ll)b.second - (ll)a.secon... |
1327 | A | Sum of Odd Integers | You are given two integers $n$ and $k$. Your task is to find if $n$ can be represented as a sum of $k$ \textbf{distinct positive odd} (not divisible by $2$) integers or not.
You have to answer $t$ independent test cases. | First of all, notice that the sum of the first $k$ odd integers is $k^2$. If $k^2 > n$ then the answer obviously "NO". And if $n \% 2 \ne k \% 2$ then the answer is "NO" also ($\%$ is modulo operation). Otherwise, the answer is always "YES" and it seems like this: $[1, 3, 5, \dots, 2(k-1)-1, rem]$, where $rem = n - \su... | [
"math"
] | 1,100 | for i in range(int(input())):
n, k = map(int, input().split())
print('YES' if k * k <= n and n % 2 == k % 2 else 'NO') |
1327 | B | Princesses and Princes | The King of Berland Polycarp LXXXIV has $n$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $n$ other kingdoms as well.
So Polycarp LXXXIV has enumerated his daughters from $1$ to $n$ and the kingdoms from... | Simulate the process without adding the new entry. For this you can just maintain an array $taken$, $i$-th value of which is true if the $i$-th prince is married and false otherwise. Now observe that there are two possible outcomes: Every daughter is married - the answer is optimal. There is a daughter who isn't marrie... | [
"brute force",
"graphs",
"greedy"
] | 1,200 | from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
used = [False for i in range(n)]
v = -1
for i in range(n):
l = [int(x) - 1 for x in stdin.readline().split()][1:]
for j in l:
if not used[j]:
used[j] = True
... |
1327 | C | Game with Chips | Petya has a rectangular Board of size $n \times m$. Initially, $k$ chips are placed on the board, $i$-th chip is located in the cell at the intersection of $sx_i$-th row and $sy_i$-th column.
In one action, Petya can move \textbf{all the chips} to the left, right, down or up by $1$ cell.
If the chip was in the $(x, y... | Note that $2nm$ is a fairly large number of operations. Therefore, we can first collect all the chips in one cell, and then go around the entire board. Let's calculate the required number of operations. First, let's collect all the chips in the $(1, 1)$ cell. To do this, let's do $n-1$ operations $U$ so that all the ch... | [
"constructive algorithms",
"implementation"
] | 1,600 | n, m, _ = map(int, input().split())
print(2 * (n - 1) + (n + 1) * (m - 1))
print("U" * (n - 1) + "L" * (m - 1), end="")
for i in range(n):
if i != 0:
print("D", end="")
if i % 2 == 0:
print("R" * (m - 1), end="")
else:
print("L" * (m - 1), end="") |
1327 | D | Infinite Path | You are given a colored permutation $p_1, p_2, \dots, p_n$. The $i$-th element of the permutation has color $c_i$.
Let's define an infinite path as infinite sequence $i, p[i], p[p[i]], p[p[p[i]]] \dots$ where all elements have \textbf{same color} ($c[i] = c[p[i]] = c[p[p[i]]] = \dots$).
We can also define a multiplic... | Let's look at the permutation as at a graph with $n$ vertices and edges $(i, p_i)$. It's not hard to prove that the graph consists of several cycles (self-loops are also considered as cycles). So, the sequence $i, p[i], p[p[i]], \dots$ is just a walking on the corresponding cycle. Let's consider one cycle $c_1, c_2, \d... | [
"brute force",
"dfs and similar",
"graphs",
"math",
"number theory"
] | 2,200 | #include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
#define x first
#define y second
typedef long long li;
typedef pair<int, int> pt;
const int INF = int(1e9);
const li INF64 = li(1e18);
int n;
vector<int> p, c;
inline bool read() ... |
1327 | E | Count The Blocks | You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999.
A block in an integer $x$ is a consecutive segment of equal digits that cannot be extended to the left or to the right.
For example... | Presume that we want to calculate the number of blocks of length $len$. Let's divide this blocks into two types: blocks which first element is a first element of integer, or blocks which last element is a last element of integer (for example blocks $111$ and $0$ in integer $11173220$); other blocks. At first let's calc... | [
"combinatorics",
"dp",
"math"
] | 1,800 | MOD = 998244353
p = [1] * 200005
for i in range(1, 200005):
p[i] = (p[i - 1] * 10) % MOD
n = int(input())
for i in range(1, n):
res = 2 * 10 * 9 * p[n - i - 1]
res += (n - 1 - i) * 10 * 9 * 9 * p[n - i - 2]
print(res % MOD, end = ' ')
print(10) |
1327 | F | AND Segments | You are given three integers $n$, $k$, $m$ and $m$ conditions $(l_1, r_1, x_1), (l_2, r_2, x_2), \dots, (l_m, r_m, x_m)$.
Calculate the number of distinct arrays $a$, consisting of $n$ integers such that:
- $0 \le a_i < 2^k$ for each $1 \le i \le n$;
- bitwise AND of numbers $a[l_i] \& a[l_i + 1] \& \dots \& a[r_i] =... | We will solve the problem for each bit separately, and then multiply the results. Obviously, if the position is covered by a segment with the value $1$, then we have no choice, and we must put $1$ there. For segments with the value $0$, there must be at least one position that they cover and its value is $0$. So we can... | [
"bitmasks",
"combinatorics",
"data structures",
"dp",
"two pointers"
] | 2,500 | #include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); ++i)
typedef pair<int, int> pt;
const int MOD = 998244353;
const int N = 500 * 1000 + 13;
int n, k, m;
pair<pt, int> q[N]... |
1327 | G | Letters and Question Marks | You are given a string $S$ and an array of strings $[t_1, t_2, \dots, t_k]$. Each string $t_i$ consists of lowercase Latin letters from a to n; $S$ consists of lowercase Latin letters from a to n and \textbf{no more than $14$} question marks.
Each string $t_i$ has its cost $c_i$ — an integer number. The value of some ... | Suppose we want to calculate the value of some already fixed string (we should be able to do so at least to solve the test cases without question marks). How can we do it? We can use some substring searching algorithms to calculate $F(S, t_i)$, but a better solution is to build an Aho-Corasick automaton over the array ... | [
"bitmasks",
"dp",
"string suffix structures"
] | 2,800 | #include<bits/stdc++.h>
using namespace std;
const int N = 8000043;
const int K = 15;
const int M = 1043;
int k;
char buf[N], buf2[M];
vector<string> t;
vector<int> c;
string s;
map<char, int> nxt[M];
int lnk[M];
int p[M];
char pchar[M];
map<char, int> go[M];
int term[M];
int ts = 1;
int A[M][K];
int F[M][K];
int d... |
1328 | A | Divisibility Problem | You are given two positive integers $a$ and $b$. In one move you can increase $a$ by $1$ (replace $a$ with $a+1$). Your task is to find the minimum number of moves you need to do in order to make $a$ divisible by $b$. It is possible, that you have to make $0$ moves, as $a$ is already divisible by $b$. You have to answe... | If $a \% b = 0$ ($a$ is divisible by $b$), just print $0$. Otherwise, we need exactly $b - a \% b$ moves to make zero remainder of $a$ modulo $b$. $\%$ is modulo operation. | [
"math"
] | 800 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
if (a % b == 0) cout << 0 << endl;
else cout << b - a % b << endl;
}
return 0;
} |
1328 | B | K-th Beautiful String | For the given integer $n$ ($n > 2$) let's write down all the strings of length $n$ which contain $n-2$ letters 'a' and two letters 'b' in \textbf{lexicographical} (alphabetical) order.
Recall that the string $s$ of length $n$ is lexicographically less than string $t$ of length $n$, if there exists such $i$ ($1 \le i \... | Let's try to find the position of the leftmost occurrence of 'b' (iterate over all positions from $n-2$ to $0$). If $k \le n - i - 1$ then this is the required position of the leftmost occurrence of 'b'. Then the position of rightmost occurrence is $n - k$ so we can print the answer. Otherwise, let's decrease $k$ by $n... | [
"binary search",
"brute force",
"combinatorics",
"implementation",
"math"
] | 1,300 | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
int main() {
int t;
cin >> t;
forn(tt, t) {
int n, k;
cin >> n >> k;
string s(n, 'a');
for (int i = n - 2; i >= 0; i--) {
if (k <= (n - i - 1)) {
s... |
1328 | C | Ternary XOR | A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$.
You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the other digits of $x$ can be $0$, $1$ or $2$.
Let's define the ternary XOR ... | Let's iterate from left to right over the digits of $x$. If the current digit is either $0$ or $2$ then we can set $a_i = b_i = 0$ or $a_i = b_i = 1$ correspondingly. There are no better choices. And if the current digit $x_i$ is $1$ then the optimal choise is to set $a_i = 1$ and $b_i = 0$. What happens after the firs... | [
"greedy",
"implementation"
] | 1,200 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n;
string x;
cin >> n >> x;
string a(n, '0'), b(n, '0');
for (int i = 0; i < n; ++i) {
if (x[i] == '1') {
a... |
1328 | D | Carousel | The round carousel consists of $n$ figures of animals. Figures are numbered from $1$ to $n$ in order of the carousel moving. Thus, after the $n$-th figure the figure with the number $1$ follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger and so on). The type... | The answer to this problem is at most $3$. Let's prove it by construction. Firstly, if all $t_i$ are equal then the answer is $1$. Otherwise, there are at least two different values in the array $t$ so the answer is at least $2$. If $n$ is even then the answer is always $2$ because you can color figures in the followin... | [
"constructive algorithms",
"dp",
"graphs",
"greedy",
"math"
] | 1,800 | #include <bits/stdc++.h>
using namespace std;
int solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (count(a.begin(), a.end(), a[0]) == n) {
cout << 1 << endl;
for (int i = 0; i < n; ++i) {
cout << 1 << " ";
}
cout << endl;
return 0;
}
if (n % 2 ==... |
1328 | E | Tree Queries | You are given a rooted tree consisting of $n$ vertices numbered from $1$ to $n$. The root of the tree is a vertex number $1$.
A tree is a connected undirected graph with $n-1$ edges.
You are given $m$ queries. The $i$-th query consists of the set of $k_i$ distinct vertices $v_i[1], v_i[2], \dots, v_i[k_i]$. Your task... | Firstly, let's choose some deepest (farthest from the root) vertex $fv$ in the query (among all such vertices we can choose any). It is obvious that every vertex in the query should either belong to the path from the root to $fv$ or the distance to some vertex of this path should be at most one. Now there are two ways:... | [
"dfs and similar",
"graphs",
"trees"
] | 1,900 | #include <bits/stdc++.h>
using namespace std;
int T;
vector<int> p, d;
vector<int> tin, tout;
vector<vector<int>> g;
void dfs(int v, int par = -1, int dep = 0) {
p[v] = par;
d[v] = dep;
tin[v] = T++;
for (auto to : g[v]) {
if (to == par) continue;
dfs(to, v, dep + 1);
}
tout[v] = T++;
}
bool isAnc(int v, ... |
1328 | F | Make k Equal | You are given the array $a$ consisting of $n$ elements and the integer $k \le n$.
You want to obtain \textbf{at least} $k$ equal elements in the array $a$. In one move, you can make one of the following two operations:
- Take \textbf{one} of the minimum elements of the array and increase its value by one (more formal... | This problem is just all about the implementation. Firstly, let's sort the initial values and compress them to pairs $(i, cnt[val])$, where $cnt[val]$ is the number of elements $val$. The first observation is pretty standard and easy: some equal elements will remain unchanged. So let's iterate over all elements $val$ i... | [
"greedy"
] | 2,200 | #include <bits/stdc++.h>
using namespace std;
const long long INF64 = 1e18;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &it : a) cin >> it;
sort(a.begin(), a.end());
vector<pair<int, int>> c... |
1329 | A | Dreamoon Likes Coloring | Dreamoon likes coloring cells very much.
There is a row of $n$ cells. Initially, all cells are empty (don't contain any color). Cells are numbered from $1$ to $n$.
You are given an integer $m$ and $m$ integers $l_1, l_2, \ldots, l_m$ ($1 \le l_i \le n$)
Dreamoon will perform $m$ operations.
In $i$-th operation, Dre... | After reading the statement, you may find this is a problem that will be tagged as "constructive algorithms" in Codefores. And you also can find this problem is just problem A in Div. 1. So basically we can expect there exist some simple methods to solve it. If a "constructive algorithms" problem asks you to determine ... | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | 1,800 | #include<bits/stdc++.h>
const int SIZE = 100002;
int len[SIZE];
long long suffix_sum[SIZE];
void err() {puts("-1");}
void solve() {
int N, M;
scanf("%d%d", &N, &M);
for(int i = 1; i <= M; i++) {
scanf("%d", &len[i]);
if(len[i] + i - 1 > N) {
err();
return;
}
... |
1329 | B | Dreamoon Likes Sequences | Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS:
You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints:
- The length of $a$ is $n$, $n \ge 1$
- $1 \le a_1 < a_2 < \dots < a_n \le d$
- Define an array $b$ of len... | Firstly, we define a function $h(x)$ as the position of the highest bit which is set to 1 in a positive integer $x$. For example, $h(1) = 0, h(2) = h(3) = 1$, and $h(4) = h(7) = 2$. If the constraints in this problem is satisfied, there is some observations, $h(a_i) = h(b_i)$ and $h(a_i)$ must less than $h(a_{i+1})$. A... | [
"bitmasks",
"combinatorics",
"math"
] | 1,700 | #include<bits/stdc++.h>
void solve(){
int d, m;
scanf("%d%d",&d, &m);
long long answer=1;
for(int i = 0; i < 30; i++) {
if(d < (1 << i)) break;
answer = answer * (std::min((1 << (i+1)) - 1, d) - (1 << i) + 2) % m;
}
answer--;
if(answer < 0) answer += m;
printf("%lld\n",an... |
1329 | C | Drazil Likes Heap | Drazil likes heap very much. So he created a problem with heap:
There is a max heap with a height $h$ implemented on the array. The details of this heap are the following:
This heap contains exactly $2^h - 1$ \textbf{distinct} positive non-zero integers. All integers are distinct. These numbers are stored in the arra... | The property of heap we concern in this problem mainly are: 1. The tree is a binary tree, each node has a weight value. 2. The weight of a node is always larger than the weight of its children. 3. We use $a[I]$ to record the weight of vertex $i$, and the number of its children are $2 \times i$ and vertex $2 \times i + ... | [
"constructive algorithms",
"data structures",
"greedy",
"implementation"
] | 2,400 | #include<bits/stdc++.h>
using namespace std;
const int SIZE = 1<<20;
int INF = 1000000001;
int a[SIZE], ops[SIZE];
int h, g;
int qq[24], qn;
int pull(int id) {
int tmp = a[id];
a[id] = 0;
qn = 0;
qq[qn++] = id;
while(id * 2 < (1 << h) && a[id] < max(a[id<<1], a[(id<<1)|1])) {
if(a[id<<1] > a... |
1329 | D | Dreamoon Likes Strings | Dreamoon likes strings. Today he created a game about strings:
String $s_1, s_2, \ldots, s_n$ is \textbf{beautiful} if and only if for each $1 \le i < n, s_i \ne s_{i+1}$.
Initially, Dreamoon has a string $a$. In each step Dreamoon can choose a \textbf{beautiful} substring of $a$ and remove it. Then he should concate... | Denoting a string of length two which contains two $i$-th letter as $t_i$. For example, $t_0$ is "aa", $t_1$ is "bb" . And let $c_i$ be the occurrence count of $t_i$ as a substring in $a$. For example, when $a =$ "aaabbcaa", $c_0 = 3, c_1 = 1$, and for other $i$, $c_i = 0$. In this problem, if only asking contestants o... | [
"constructive algorithms",
"data structures"
] | 3,100 | #include<bits/stdc++.h>
using namespace std;
const int SIZE = 2e5+10;
char s[SIZE];
int cnt[SIZE];
int cc[26];
int all_cnt;
int ma;
void update_ma() {
while(ma > 0 && !cnt[ma]) ma--;
}
void dec1(int id) {
cnt[cc[id]]--;
cc[id]--;
cnt[cc[id]]++;
}
pair<int, int> stk[SIZE];
int sn;
int m;
int now;
int las... |
1329 | E | Dreamoon Loves AA | There is a string of length $n+1$ of characters 'A' and 'B'. The first character and last character of the string are equal to 'A'.
You are given $m$ indices $p_1, p_2, \ldots, p_m$ ($0$-indexation) denoting the other indices of characters 'A' in the string.
Let's denote the minimum distance between two neighboring '... | The idea of this problem comes to my brain when I recall that I'm cooking and I want to cut a carrot into many pieces and make the size of each piece as evenly as possible. I think this problem is very interesting. So that's why I determine to prepare a Codeforces contest after so many years. I hope I can share this pr... | [
"binary search",
"greedy"
] | 3,300 | /*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).be... |
1330 | A | Dreamoon and Ranking Collection | Dreamoon is a big fan of the Codeforces contests.
One day, he claimed that he will collect all the places from $1$ to $54$ after two more rated contests. It's amazing!
Based on this, you come up with the following problem:
There is a person who participated in $n$ Codeforces rounds. His place in the first round is $... | The total number of rounds this person participates after $x$ more rated contests is $n+x$. So the number of places this person collects cannot exceed $n + x$. Then we can iterate $k$ from $n+x$ to $1$. In each iteration, let $r$ be the number of integers from $1$ to $k$ which doesn't appear in $a_i$. This person can c... | [
"implementation"
] | 900 | #include<cstdio>
const int MAX_V = 201;
bool achieve[MAX_V];
void solve() {
int n, x;
scanf("%d%d", &n, &x);
for(int i = 1; i <= n + x; i++) {
achieve[i] = false;
}
for(int i = 1; i <= n; i++) {
int ranking;
scanf("%d", &ranking);
achieve[ranking] = true;
}
fo... |
1330 | B | Dreamoon Likes Permutations | The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is called the length of the permutation.
Dreamoon has two permutations $p_1$ and $p_2$ of non-zero lengths $l_1$ and $l_2$.
Now Dreamoon concatenates these two permutations into another sequ... | Let $ma$ be the maximum value of all elements in $a$ . If you can recover the the array $a$ to two permutations $p1$ abd $p2$, then $ma$ must be $\max(len1, len2)$. So there are at most two case: 1. $len1 = ma, len2 = n - ma$, 2. $len1 = n - ma, len2 = ma$. We can check the two cases separately with time complexity $O(... | [
"implementation",
"math"
] | 1,400 | #include<cstdio>
const int SIZE = 200000;
int p[SIZE];
int ans[SIZE][2];
int ans_cnt;
bool judge(int a[], int n){
static int used[SIZE+1];
for(int i = 1; i <= n; i++) used[i] = 0;
for(int i = 0; i < n; i++) used[a[i]] = 1;
for(int i = 1; i <= n; i++) {
if(!used[i]) return 0;
}
return 1;
... |
1332 | A | Exercising Walk | Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!
Initially, Alice's cat is located in a cell $(x,y)$ of an infinite grid. According to Alice's theory, cat needs to move:
- exactly $a$ steps left: from $(u,v)$ to $(u-1,v)$;
- exactly $b$ steps right: from $(u,v)$ to $(u+... | The key observation is x-axis and y-axis is independent in this task as the area is a rectangle. Therefore, we should only consider 1D case (x-axis, for example). The optimal path to choose alternates between right and left moves until only one type of move is possible. And sometimes there is no place to make even one ... | [
"greedy",
"implementation",
"math"
] | 1,100 | #include<bits/stdc++.h>
using namespace std;
int a,b,c,d,x,y,x1,y1,x2,y2,xx,yy;
int main(){
int t;
cin>>t;
while (t--){
cin>>a>>b>>c>>d;
cin>>x>>y>>x1>>y1>>x2>>y2;
xx=x,yy=y;
x+=-a+b, y+=-c+d;
if (x>=x1&&x<=x2&&y>=y1&&y<=y2&&(x2>x1||a+b==0)&&(y2>y1||c+d==0)){
... |
1332 | B | Composite Coloring | A positive integer is called composite if it can be represented as a product of two positive integers, both greater than $1$. For example, the following numbers are composite: $6$, $4$, $120$, $27$. The following numbers aren't: $1$, $2$, $3$, $17$, $97$.
Alice is given a sequence of $n$ composite numbers $a_1,a_2,\ld... | The solution is obvious once one note that for any composite number $k$, there exists a prime $d$ such that $d \le \sqrt{k}$ and $k$ is divisible by $d$. Coincidentally, there are exactly $11$ primes below $\sqrt{1000}$. Thus, one can color balls according to their smallest divisor. That works because if all numbers of... | [
"brute force",
"constructive algorithms",
"greedy",
"math",
"number theory"
] | 1,400 | #include<bits/stdc++.h>
using namespace std;
int n,t;
vector<int> ans[1007];
int res[1007];
int main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
auto f=[&](int u){
for (int i=2;i<=u;++i){
if (u%i==0) return i;
}
};
cin>>t;
while (t--){
cin>>n;
... |
1332 | C | K-Complete Word | Word $s$ of length $n$ is called $k$-complete if
- $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$;
- $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \le i \le n-k$.
For example, "abaaba" is a $3$-complete word, while "abccba" is not.
Bob is given a word $s$ of length $n$ consisting of only ... | One should notice that word $s$ of length $n$ is $k$-complete if and only if there exists a palindrome $t$ of length $k$ such that $s$ can be generated by several concatenations of $t$. So in the final string all characters at positions $i$, $k - i + 1$, $k + i$, $2k - i + 1$, $2k + i$, $3k - i + 1$, $\dots$ for all $1... | [
"dfs and similar",
"dsu",
"greedy",
"implementation",
"strings"
] | 1,500 | #include<bits/stdc++.h>
using namespace std;
const int maxn=200007;
int n,k,ans=0;
int cnt[maxn][26];
string s;
int differ(int u,int v){
int ret=0,mx=0;
for (int j=0;j<26;++j){
ret+=cnt[u][j]+cnt[v][j];
mx=max(mx,cnt[u][j]+cnt[v][j]);
}
return ret-mx;
}
int main(){
int t;
cin... |
1332 | D | Walk on Matrix | Bob is playing a game named "Walk on Matrix".
In this game, player is given an $n \times m$ matrix $A=(a_{i,j})$, i.e. the element in the $i$-th row in the $j$-th column is $a_{i,j}$. Initially, player is located at position $(1,1)$ with score $a_{1,1}$.
To reach the goal, position $(n,m)$, player can move right or d... | In fact, the following matrix will work: $\left( \begin{array}{ccc} 2^{17}+k & 2^{17} & 0\\ k & 2^{17}+k & k\\ \end{array} \right)$ To find such a matrix, one should find out why the dp solution fails. One should notice that $dp_{2,2}=\max(a_{1,1}\&a_{1,2}\&a_{2,2},a_{1,1}\&a_{2,1}\&a_{2,2})$ and dp solution will choos... | [
"bitmasks",
"constructive algorithms",
"math"
] | 1,700 | k = int(input())
x = 2**17
print(2, 3)
print(x^k, x, 0)
print(k, x^k, k) |
1332 | E | Height All the Same | Alice has got addicted to a game called Sirtet recently.
In Sirtet, player is given an $n \times m$ grid. Initially $a_{i,j}$ cubes are stacked up in the cell $(i,j)$. Two cells are called adjacent if they share a side. Player can perform the following operations:
- stack up one cube in two \textbf{adjacent} cells;
-... | Observation 1. The actual values in the cells don't matter, only parity matters. Proof. Using the second operation one can make all the values of same parity equal by applying it to the lowest value until done. That observation helps us to get rid of the second operation, let us only have the first one. Observation 2. ... | [
"combinatorics",
"constructive algorithms",
"math",
"matrices"
] | 2,100 | MOD = 998244353
n, m, l, r = map(int, input().split())
if n * m % 2 == 1:
print(pow(r - l + 1, n * m, MOD))
else:
e = r // 2 - (l - 1) // 2
o = (r - l + 1) - e
print((pow(e + o, n * m, MOD) + pow(e - o, n * m, MOD)) * (MOD + 1) // 2 % MOD) |
1332 | F | Independent Set | Eric is the teacher of graph theory class. Today, Eric teaches independent set and edge-induced subgraph.
Given a graph $G=(V,E)$, an independent set is a subset of vertices $V' \subset V$ such that for every pair $u,v \in V'$, $(u,v) \not \in E$ (i.e. no edge in $E$ connects two vertices from $V'$).
An edge-induced ... | We will call one vertice is colored if and only if it is in the independent set. And a coloring is valid if and only if no two adjacent vertices are both colored. Therefore, we are asked to calculate the sum of number of valid colorings over all edge induced subgraphs. To deal with the task, one should notice that for ... | [
"dfs and similar",
"dp",
"trees"
] | 2,500 | #include<bits/stdc++.h>
#define int long long
#define ULL unsigned long long
#define F first
#define S second
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define range(a) a.begin(), a.end()
#define PI pair<int,int>
#define VI vector<int>
#define debug... |
1332 | G | No Monotone Triples | Given a sequence of integers $a$ of length $n$, a tuple $(i,j,k)$ is called monotone triples if
- $1 \le i<j<k\le n$;
- $a_i \le a_j \le a_k$ or $a_i \ge a_j \ge a_k$ is satisfied.
For example, $a=[5,3,4,5]$, then $(2,3,4)$ is monotone triples for sequence $a$ while $(1,3,4)$ is not.
Bob is given a sequence of integ... | We will solve this task with the following observations. Observation 1. If an array $x$ of length $k$ ($k \ge 3$) has no monotone triple, then one of the following is true: $x_1<x_2>x_3<x_4>x_5<\ldots$ $x_1>x_2<x_3>x_4<x_5>\ldots$ Observation 2. If an array $x$ of length $k$ ($k \ge 4$) has no monotone triple, then its... | [
"data structures"
] | 3,100 | #include<bits/stdc++.h>
using namespace std;
const int maxn=200007;
int n,q,a[maxn],b[maxn],c[maxn],t[maxn],sum[maxn];
int st1[maxn],st2[maxn],p1,p2,r1,r2,s1,s2;
int ans1[maxn][4],ans2[maxn][4];
set<int> s;
bool cmp1(int u,int v){
return a[u]<a[v];
}
bool cmp2(int u,int v){
return a[u]>a[v];
}
int main(){
... |
1333 | A | Little Artem | Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help.
Artem wants to paint an $n \times m$ board. Each cell of the board should be colored in white or black.
Lets $B$ be the number of black cells that have at least one white neigh... | In this problem it is enough to simply paint the upper left corner white and all the others black for any size of the board Like this: And there are $W=1$ (cell with coordinates $\{1, 1\}$) and $B=2$ (cells with coordinates $\{1, 2\}$ and $\{2, 1\}$). In the first version, the task restrictions were $1 \le n, m$, but w... | [
"constructive algorithms"
] | 1,000 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m; cin >> n >> m;
string black_row(m, 'B');
vector<string> result(n, black_row);
result[0][0] = 'W';
for (int i = 0; i < n; ++i) {
cout << result[i] << '\n';
}
}
int main() {
int t; cin >> t;
while(t--) solv... |
1333 | B | Kind Anton | Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:
There are two arrays of integers $a$ and $b$ of length $n$. It turned out that array $a$ contains only elements from the set $\{-1, 0, 1\}$.
Anton can perform the following sequence of operations any nu... | First of all, note that we can add an element with index $i$ to an element with index $j$ iff $i < j$. This means that the element $a_n$ cannot be added to any other element because there is no index $j > n$ in the array. This is why we can first equalize the elements $a_n$ and $b_n$. If $a_n = b_n$, they are already e... | [
"greedy",
"implementation"
] | 1,100 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n; cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
vector<int> good(2, 0);
for (int i = 0; i < n; ++i) {
if (a[i] > b[i] ... |
1333 | C | Eugene and an array | Eugene likes working with arrays. And today he needs your help in solving one challenging task.
An array $c$ is a subarray of an array $b$ if $c$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Let's call a ... | Let's solve this problem in $O(n^2 \times log (n))$for now. Note that if the subarray $[a_i,..., a_j]$ is good, then the subarray $[a_i,..., a_{j-1}]$ is also good, and if the subset $[a_i,..., a_j]$ is not good, then the subarray $[a_i,..., a_{j+1}]$ is not good either. Then for each left border $a_i$ we want to find ... | [
"binary search",
"data structures",
"implementation",
"two pointers"
] | 1,700 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<long long> prefix(n + 1, 0);
for (int i = 0; i < n; ++i) {
int x; cin >> x;
prefix[i + 1] = prefix[i] + x;
}
int begin = 0, end = 0;
long long ans = 0;
set<long long> s = {0};
while(begi... |
1333 | D | Challenges in school №41 | There are $n$ children, who study at the school №41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.
Children can do the following: in one second several pairs of neighbori... | If solution exist let's count the minimum and maximum bounds for $k$ for initial arrangement of children. A minimum $k$ achieved all possible pairs of children turn theirs heads at every step. The maximum $k$ reached if only one of possible pairs of children turn theirs heads at every step. This values is easy to count... | [
"brute force",
"constructive algorithms",
"games",
"graphs",
"greedy",
"implementation",
"sortings"
] | 2,100 | #include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> find_steps(const vector<int>& a) {
vector<int> steps;
for (int i = 0; i < n - 1; ++i) {
if (a[i] == 1 && a[i + 1] == 0) steps.push_back(i);
}
return steps;
}
int main() {
cin >> n >> k;
string s; cin >> s;
vecto... |
1333 | E | Road to 1600 | Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help!
Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess \textbf{rook} moves along straight lines up and down, left and right, as many squares as it wants. And when it... | First of all notice that there are no such boards for $N=1,2$. Then you can find an example for $N=3$ by yourself or with counting all cases with program. One of possible examples (I find it using paper, pencil and my hands): $N=3$: For large $N$ we can walk by spiral (like snake) to the case $N=3$. $N=4$: $N=5$: Rook ... | [
"brute force",
"constructive algorithms"
] | 2,400 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
if (n < 3) {
cout << -1;
return 0;
}
vector<int> solution = {
1, 3, 4, 8, 2, 7, 9, 5, 6
};
vector<vector<int>> table(n, vector<int>(n, 0));
int cur = 1;
for (int i = 0; i < n - 3; ++i) ... |
1333 | F | Kate and imperfection | Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $.
She thinks that \textbf{imperfection} of a subset $M \subseteq S$ is equal to the \textbf{maximum} of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$.
Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants... | Let $A = \{a_1, a_2, ..., a_k\}$ be one of the possible subsets with smallest imperfection. If for any number $a_i$ in $A$ not all of its divisors contained in $A$ then we can replace $a_i$ with one of it divisor. The size os the subset does not change and imperfection may only decrease. Then we can assume that for any... | [
"greedy",
"implementation",
"math",
"number theory",
"sortings",
"two pointers"
] | 2,200 | #include <bits/stdc++.h>
using namespace std;
vector<int> max_div;
void eratosthenes(int limit) {
max_div.assign(limit + 1, 0);
max_div[0] = limit + 10;
max_div[1] = 1;
for (int i = 2; i <= limit; ++i) {
if (max_div[i]) continue;
for (int j = i; j <= limit; j += i) {
if (... |
1334 | A | Level Statistics | Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases... | Let's use the fact that initially the level has $0$ plays and $0$ clears. Call the differences before the previous stats and the current ones $\Delta p$ and $\Delta c$. The stats are given in chronological order, so neither the number of plays, nor the number of clears should decrease (i.e. $\Delta p \ge 0$ and $\Delta... | [
"implementation",
"math"
] | 1,200 | #include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
int main() {
int tc;
scanf("%d", &tc);
while (tc--){
int n;
scanf("%d", &n);
int p = 0, c = 0;
bool fl = true;
forn(i, n){
int x, y;
scanf("%d%d", &x, &y);
if (x < p || y < c || y - c > x - p)
... |
1334 | B | Middle Class | Many years ago Berland was a small country where only $n$ people lived. Each person had some savings: the $i$-th one had $a_i$ burles.
The government considered a person as wealthy if he had at least $x$ burles. To increase the number of wealthy people Berland decided to carry out several reforms. Each reform looked l... | In fact, to carry out only one reform is always enough. And it's easy to prove if you make only one reform it's always optimal to take the maximum such $k$ that the average of $k$ maximums in the array $a$ is at least $x$ (i.e. sum greater or equal to $kx$). So the solution is next: sort array $a$ and find the suffix w... | [
"greedy",
"sortings"
] | 1,100 | fun main() {
val T = readLine()!!.toInt()
for (tc in 1..T) {
val (n, x) = readLine()!!.split(' ').map { it.toInt() }
val a = readLine()!!.split(' ').map { it.toInt() }.sortedDescending()
var cnt = 0
var sum = 0L
while (cnt < n && sum + a[cnt] >= (cnt + 1) * x.toLong()) {... |
1334 | C | Circle of Monsters | You are playing another computer game, and now you have to slay $n$ monsters. These monsters are standing in a circle, numbered clockwise from $1$ to $n$. Initially, the $i$-th monster has $a_i$ health.
You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targe... | We cannot utilize the explosion of the last monster we kill. So the naive approach is to iterate on the monster we kill the last, break the circle between this monster and the next one, and then shoot the first monster in the broken circle until it's dead, then the second one, and so on. Let's calculate the number of b... | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | 1,600 | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
typedef long long li;
const int N = 300 * 1000 + 13;
int n;
li a[N], b[N];
void solve() {
scanf("%d", &n);
forn(i, n) scanf("%lld%lld", &a[i], &b[i]);
li ans = 0, mn = 1e18;
forn(i, n) {
int ni = (i + 1) % n;... |
1334 | D | Minimum Euler Cycle | You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops.
You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such c... | The solution of the problem can be found clearly in constructive way. An example for $n=5$: (1 2 1 3 1 4 1 5 (2 3 2 4 2 5 (3 4 3 5 (4 5 ()))) 1) where brackets mean that we call here some recursive function $calc$. Since on each level of recursion we have only $O(n)$ elements and there $O(n)$ levels then the generation... | [
"constructive algorithms",
"graphs",
"greedy",
"implementation"
] | 1,800 | #include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
#define x first
#define y second
typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
int n;
li l, r;
inline bool read() {
if(!(cin >> n >> l >> r))
return f... |
1334 | E | Divisor Paths | You are given a positive integer $D$. Let's build the following graph from it:
- each vertex is a divisor of $D$ (not necessarily prime, $1$ and $D$ itself are also included);
- two vertices $x$ and $y$ ($x > y$) have an undirected edge between them if $x$ is divisible by $y$ and $\frac x y$ is a prime;
- the weight o... | Let's define the semantics of moving along the graph. On each step the current number is either multiplied by some prime or divided by it. I claim that the all shortest paths from $x$ to $y$ always go through $gcd(x, y)$. Moreover, the vertex numbers on the path first only decrease until $gcd(x, y)$ and only increase a... | [
"combinatorics",
"graphs",
"greedy",
"math",
"number theory"
] | 2,200 | #include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
const int MOD = 998244353;
int add(int a, int b){
a += b;
if (a >= MOD)
a -= MOD;
if (a < 0)
a += MOD;
return a;
}
int mul(int a, int b){
return a * 1ll * b % MOD;
}
int binpow(int a, int b){
int res = 1;
... |
1334 | F | Strange Function | Let's denote the following function $f$. This function takes an array $a$ of length $n$ and returns an array. Initially the result is an empty array. For each integer $i$ from $1$ to $n$ we add element $a_i$ to the end of the resulting array if it is greater than all previous elements (more formally, if $a_i > \max\lim... | The "naive" version of the solution is just dynamic programming: let $dp_{i, j}$ be the minimum cost of removed elements (or the maximum cost of remaining elements) if we considered first $i$ elements of $a$, and the resulting sequence maps to the first $j$ elements of $b$. There are two versions of this solution, both... | [
"binary search",
"data structures",
"dp",
"greedy"
] | 2,500 | #include<bits/stdc++.h>
using namespace std;
typedef long long li;
const li INF64 = li(1e18);
const int N = 500043;
li f[N];
li get(int x)
{
li ans = 0;
for (; x >= 0; x = (x & (x + 1)) - 1)
ans += f[x];
return ans;
}
void inc(int x, li d)
{
for (; x < N; x = (x | (x + 1)))
f[x]... |
1334 | G | Substring Search | You are given a permutation $p$ consisting of exactly $26$ integers from $1$ to $26$ (since it is a permutation, each integer from $1$ to $26$ occurs in $p$ exactly once) and two strings $s$ and $t$ consisting of lowercase Latin letters.
A substring $t'$ of string $t$ is an \textbf{occurence} of string $s$ if the foll... | We will run two tests for each substring of $t$ we are interested in. If at least one of them shows that the substring is not an occurence of $s$, we print 0, otherwise we print 1. The first test is fairly easy. The given permutation can be decomposed into cycles. Let's replace each character with the index of its cycl... | [
"bitmasks",
"brute force",
"fft"
] | 2,900 | #include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < n; i++)
#define sz(a) ((int)(a).size())
const int LOGN = 20;
const int N = (1 << LOGN);
typedef long double ld;
typedef long long li;
const ld PI = acos(-1.0);
struct comp
{
ld x, y;
comp(ld x = .0, ld y = .0) : x(x), y(y)... |
1335 | A | Candies and Two Sisters | There are two sisters Alice and Betty. You have $n$ candies. You want to distribute these $n$ candies between two sisters in such a way that:
- Alice will get $a$ ($a > 0$) candies;
- Betty will get $b$ ($b > 0$) candies;
- each sister will get some \textbf{integer} number of candies;
- Alice will get a greater amount... | The answer is $\lfloor\frac{n-1}{2}\rfloor$, where $\lfloor x \rfloor$ is $x$ rounded down. | [
"math"
] | 800 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << (n - 1) / 2 << endl;
}
return 0;
} |
1335 | B | Construct the String | You are given three positive integers $n$, $a$ and $b$. You have to construct a string $s$ of length $n$ consisting of lowercase Latin letters such that \textbf{each substring} of length $a$ has \textbf{exactly} $b$ distinct letters. It is guaranteed that the answer exists.
You have to answer $t$ independent test case... | If we represent letters with digits, then the answer can be represented as $1, 2, \dots, b, 1, 2, \dots, b, \dots$. There is no substring containing more than $b$ distinct characters and each substring of length $a$ contains exactly $b$ distinct characters because of the condition $b \le a$. Time complexity: $O(n)$. | [
"constructive algorithms"
] | 900 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n, a, b;
cin >> n >> a >> b;
for (int i = 0; i < n; ++i) {
cout << char('a' + i % b);
}
cout << endl;
}
ret... |
1335 | C | Two Teams Composing | You have $n$ students under your control and you have to compose \textbf{exactly two teams} consisting of some subset of your students. Each student had his own skill, the $i$-th student skill is denoted by an integer $a_i$ (different students can have the same skills).
So, about the teams. Firstly, these two teams sh... | Let the number of students with the skill $i$ is $cnt_i$ and the number of different skills is $diff$. Then the size of the first team can not exceed $diff$ and the size of the second team can not exceed $maxcnt = max(cnt_1, cnt_2, \dots, cnt_n)$. So the answer is not greater than the minimum of these two values. Moreo... | [
"binary search",
"greedy",
"implementation",
"sortings"
] | 1,100 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> cnt(n + 1);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
++cnt[x];
}
int mx ... |
1335 | D | Anti-Sudoku | You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.
The picture showing the correct sudoku solution:
Blocks are bordered with bold black color.
Your task is to change \textbf{at most} $9$ elements of this field (i.e. choose some $1 \le i, j \le 9$ ... | Well, if we replace all occurrences of the number $2$ with the number $1$, then the initial solution will be anti-sudoku. It is easy to see that this replacement will make exactly two copies of $1$ in every row, column, and block. There are also other correct approaches but I found this one the most pretty. | [
"constructive algorithms",
"implementation"
] | 1,300 | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
for (int i = 0; i < 9; ++i) {
string s;
cin >> s;
for (auto &c : s) if (c == '2') c = '1';
cout << s << endl;
}
... |
1335 | E1 | Three Blocks Palindrome (easy version) | \textbf{The only difference between easy and hard versions is constraints}.
You are given a sequence $a$ consisting of $n$ positive integers.
Let's define a \textbf{three blocks palindrome} as the sequence, consisting of at most two distinct elements (let these elements are $a$ and $b$, $a$ can be equal $b$) and is a... | Let's precalculate for each number $c$ ($0$-indexed) the array $pref_c$ of length $n+1$, where $pref_c[i]$ is the number of occurrences of the number $c$ on the prefix of length $i$. This can be done with easy dynamic programming (just compute prefix sums). Also let $sum(c, l, r)$ be $pref_c[r + 1] - pref_c[l]$ and it'... | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | 1,700 | #include <bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
... |
1335 | E2 | Three Blocks Palindrome (hard version) | \textbf{The only difference between easy and hard versions is constraints}.
You are given a sequence $a$ consisting of $n$ positive integers.
Let's define a \textbf{three blocks palindrome} as the sequence, consisting of at most two distinct elements (let these elements are $a$ and $b$, $a$ can be equal $b$) and is a... | I'll take some definitions from the solution of the easy version, so you can read it first if you don't understand something. Let $sum(c, l, r)$ be the number of occurrences of $c$ on the segment $[l; r]$. We will try to do almost the same solution as in the easy version. The only difference is how do we iterate over a... | [
"brute force",
"data structures",
"dp",
"two pointers"
] | 1,800 | #include <bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
fo... |
1335 | F | Robots on a Grid | There is a rectangular grid of size $n \times m$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $(i, j)$ is $c_{i, j}$. You are also given a map of directions: for each cell, there is a direction $s_{i, j}$ which is one of the four characters 'U', 'R', 'D' and 'L'.
- If $s_{i, j}$ ... | First of all, I want to say about $O(nm)$ solution. You can extract cycles in the graph, do some dynamic programming on trees, use some hard formulas and so on, but it is a way harder to implement than the other solution that only has an additional log, so I'll describe the one which is easier to understand and much ea... | [
"data structures",
"dfs and similar",
"dsu",
"graphs",
"greedy",
"matrices"
] | 2,200 | #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>... |
1336 | A | Linova and Kingdom | Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
There are $n$ cities and $n-1$ two-way roads connecting pairs of cities in the kingdo... | Lemma: In the optimum solution, if a node (except the root) is chosen to develop tourism, its parent must be chosen to develop tourism, too. Proof: Otherwise, if we choose its parent to develop tourism instead of itself, the sum of happiness will be greater. Then we can calculate how much happiness we will get if we ch... | [
"dfs and similar",
"dp",
"greedy",
"sortings",
"trees"
] | 1,600 | #include <bits/stdc++.h>
#define maxn 200005
std::vector<int>conj[maxn];
int n,k,u,v,depth[maxn]={0},size[maxn]={0},det[maxn];
long long ans=0;
int cmp(int a,int b){return a>b;}
int dfs(int u,int f){depth[u]=depth[f]+1;size[u]=1;
for (int i=0;i<conj[u].size();++i){
if ((v=conj[u][i])==f)continue;
size[u]+=dfs(v,u)... |
1336 | B | Xenia and Colorful Gems | Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
Recently Xenia has bought $n_r$ red gems, $n_g$ green gems and $n_b$ blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so... | First, let's assume that there exists an optimum solution in which we choose $r_x$, $g_y$ and $b_z$ satisfying $r_x \le g_y \le b_z$. Here's a lemma: When $y$ is fixed, $r_x$ is the maximum one that $r_x \le g_y$, and $b_z$ is the minimum one that $g_y \le b_z$. It's easy to prove: no matter what $z$ is, the bigger $r_... | [
"binary search",
"greedy",
"math",
"sortings",
"two pointers"
] | 1,700 | #include <bits/stdc++.h>
using namespace std;
int t, nr, ng, nb;
long long ans;
long long sq(int x) { return 1ll * x * x; }
void solve(vector<int> a, vector<int> b, vector<int> c) {
for (auto x : a) {
auto y = lower_bound(b.begin(), b.end(), x);
auto z = upper_bound(c.begin(), c.end(), x);
... |
1336 | C | Kaavi and Magic Spell | Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divination, Kaavi believes that magic spells can provide great power for her to see the future.
Kaavi has a string $T$ of length $m$ and all th... | We can use DP to solve this problem. Let $f_{i,j}$ be the answer when $S[0..i-1]$ has already been used and the current $A[0..\min(i-1,m-1-j)]$ will be in the position $[j..\min(i+j-1,m-1)]$ after all operations are finished. Specially, $f_{i,m}$ means that all characters in the current $A$ won't be in the position $[j... | [
"dp",
"strings"
] | 2,200 | #include <iostream>
#include <string>
#include <vector>
using namespace std;
const int mod = 998244353;
int main()
{
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
vector<vector<int> > f(n + 1, vector<int>(m + 1));
f[n][0] = 1;
for (int i = n - 1; i >= 1; --i)
{
for (int j = 0; j <... |
1336 | D | Yui and Mahjong Set | \textbf{This is an interactive problem.}
Yui is a girl who enjoys playing Mahjong.
She has a mysterious set which consists of tiles (this set can be empty). Each tile has an integer value between $1$ and $n$, and \textbf{at most $n$ tiles} in the set have the same value. So the set can contain at most $n^2$ tiles.
... | Suppose $c_i$ equals to the number of tiles in the current set with value $i$ (before making a query). If you insert a tile with value $x$: The delta of triplet subsets is $\dbinom{c_x}{2}$. Once you're sure that $c_x \neq 0$ holds, you can determine the exact value of $c_x$. The delta of straight subsets is $c_{x-2}c_... | [
"constructive algorithms",
"interactive"
] | 3,200 | #include <cstdio>
const int MN = 105;
int N, lstv1, lstv2, v1, v2;
int dv1[MN], dv2[MN], Tag[MN], Ans[MN];
int main() {
scanf("%d", &N);
scanf("%d%d", &lstv1, &lstv2);
for (int i = 1; i < N; ++i) {
printf("+ %d\n", i), fflush(stdout);
scanf("%d%d", &v1, &v2);
dv1[i] = v1 - lstv1, dv2[i] = v2 - lstv2;
if (... |
1336 | E2 | Chiori and Doll Picking (hard version) | This is the hard version of the problem. The only difference between easy and hard versions is the constraint of $m$. You can make hacks only if both versions are solved.
Chiori loves dolls and now she is going to decorate her bedroom!
As a doll collector, Chiori has got $n$ dolls. The $i$-th doll has a non-negative... | Build linear basis $A$ with given numbers. Suppose: $k$ is the length of $A$. $S(A)$ is the set consisted of numbers which can be produced in $A$. $p_i$ is equal to the number of $x$, where $x \in S(A)$ and $\text{popcount}(x)=i$. $ans_i$ is equal to the number of doll picking ways with value $i$. Thus, $ans_i = p_i \c... | [
"bitmasks",
"brute force",
"combinatorics",
"math"
] | 3,500 | #include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, inv2 = 499122177;
const int M = 64;
int n, m, k, p[M], c[M][M];
long long a[M], b[M], f[M];
void dfs(int i, long long x) {
if (i == k) { p[__builtin_popcountll(x)]++; return; }
dfs(i + 1, x); dfs(i + 1, x ^ a[i]);
}
int main() {
ci... |
1336 | F | Journey | In the wilds far beyond lies the Land of Sacredness, which can be viewed as a tree — connected undirected graph consisting of $n$ nodes and $n-1$ edges. The nodes are numbered from $1$ to $n$.
There are $m$ travelers attracted by its prosperity and beauty. Thereupon, they set off their journey on this land. The $i$-t... | Idea: EternalAlexander First, let's choose an arbitrary root for the tree. Then for all pairs of paths, their LCA (lowest common ancestor) can be either different or the same. Then, let's calculate the answer of pairs with different LCAs. In this case, if the intersection is not empty, it will be a vertical path as in ... | [
"data structures",
"divide and conquer",
"graphs",
"trees"
] | 3,500 | #include <bits/stdc++.h>
#define maxn 200005
int n,m,k,u[maxn],v[maxn],ch[maxn<<6][2]={0},sum[maxn<<6]={0},pt[maxn],head[maxn]={0},tail=0,cnt=0,root[maxn]={0},
anc[maxn][19]={0},son[maxn]={0},depth[maxn]={0},dfn[maxn],size[maxn],idx=0;
long long ans=0;
std::vector<int>in[maxn],vec[maxn];
struct edge {
int v,next;
}edg... |
1337 | A | Ichihime and Triangle | Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.
These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now sh... | There are many possible solutions, one of them is to always output $b$, $c$, $c$. You can easily prove that $b$, $c$, $c$ always satisfies the requirements. | [
"constructive algorithms",
"math"
] | 800 | #include <bits/stdc++.h>
using namespace std;
int t, a, b, c, d;
int main() {
for (cin >> t; t; t--) {
cin >> a >> b >> c >> d;
cout << b << " " << c << " " << c << endl;
}
return 0;
} |
1337 | B | Kana and Dragon Quest game | Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.
One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.
The dragon has a hit point of $... | First, it's better not to cast Void Absorptions after a Lightning Strike. Otherwise, there will be a Void Absorption right after a Lightning Strike. Supposing the hit point was $x$ before casting these two spells, if you cast Lightning Strike first, after these two spells the hit point will be $\left\lfloor \frac{x-10}... | [
"greedy",
"implementation",
"math"
] | 900 | #include <bits/stdc++.h>
int x,n,m,t;
void solve(){
scanf("%d%d%d",&x,&n,&m);
while (x>0&&n&&x/2+10<x){n--;x=x/2+10;}
if (x<=m*10)printf("YES\n");
else printf("NO\n");
}
int main(){
scanf("%d",&t);
while(t--)solve();
return 0;
} |
1338 | A | Powered Addition | You have an array $a$ of length $n$. For every positive integer $x$ you are going to perform the following operation during the $x$-th second:
- Select some distinct indices $i_{1}, i_{2}, \ldots, i_{k}$ which are between $1$ and $n$ inclusive, and add $2^{x-1}$ to each corresponding position of $a$. Formally, $a_{i_{... | First, let's define $b$ as ideal destination of $a$, when we used operations. Observation 1. Whatever you select any $b$, there is only one way to make it, because there is no more than single way to make specific amount of addition. That means we just have to select optimal destination of $a$. For example, if you want... | [
"greedy",
"math"
] | 1,500 | null |
1338 | B | Edge Weight Assignment | You have unweighted tree of $n$ vertices. You have to assign a \textbf{positive} weight to each edge so that the following condition would hold:
- For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$.
... | Let's make an easy and good construction which can solve actual problem. Now reroot this tree at any leaf like picture below; Our goal in this construction is, we are trying to make $xor(path(l_{1}, lca(l_{1}, l_{2}))) = xor(path(l_{2}, lca(l_{1}, l_{2}))) = xor(path(root, lca(l_{1}, l_{2})))$ for all two leaves $l_{1}... | [
"bitmasks",
"constructive algorithms",
"dfs and similar",
"greedy",
"math",
"trees"
] | 1,800 | null |
1338 | C | Perfect Triples | Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
- Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that
- $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation.
- $a$, $b$, $c$ are not in $s$.
Here triple of inte... | Let's try mathematical induction. First, suppose you have fully used numbers only between $1$ and $4^{n} - 1$ inclusive. Now we are going to use all numbers between $4^{n}$ and $4^{n+1} - 1$ inclusive by following methods. Following picture is description of $a$, $b$ and $c$ in bitwise manner; First row means we have a... | [
"bitmasks",
"brute force",
"constructive algorithms",
"divide and conquer",
"math"
] | 2,200 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.