Thank you for your participation! We hope you enjoyed the problems! We would love to hear your feedback! Please share your thoughts in the comments.
Idea by MOUFLESS, prepared by MOUFLESS.
What can you say when every player has reported a win?
A report array can be genuine only if it meets both of these conditions:
- There must be at least one player who reported $$$0$$$ — there are $$$n - 1$$$ duels and $$$n$$$ players.
- There cannot be two adjacent players who both reported $$$0$$$ — one of them must have won the duel between them.
If either condition fails, the answer is YES (there is definitely a liar); otherwise, the answer is NO.
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (accumulate(a.begin(), a.end(), 0) == n) {
cout << "YES" << "\n";
return;
}
for (int i = 0; i < n - 1; i++) if (!a[i] && !a[i + 1]) {
cout << "YES" << "\n";
return;
}
cout << "NO" << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
Idea by MOUFLESS, prepared by MOUFLESS and FetFot.
What changes if the turn order is reversed — starting with Fouad's move before Mouf's cut?
Can the row and column dimensions be treated independently, or do they interact? How might that influence your approach?
We restructure the game by grouping each move (Fouad's move) with the following cut (Mouf's cut). After Mouf performs his initial cut, each combined turn consists of Fouad first moving to any remaining cell, followed by Mouf cutting the grid.
Now, let's temporarily set aside the initial cut and focus on the state of the grid just before Fouad's first move in this new structure. Suppose the remaining Grid has dimensions $$$n' \times m'$$$. Since each cut affects only one dimension, we can handle the row and column reductions independently. Thus, the number of required turns is:
where $$$f(l)$$$ denotes the number of turns required to reduce a $$$1 \times l$$$ grid to a single cell. The function $$$f(l)$$$ can be defined recursively as:
Given that $$$f$$$ is non-decreasing, the minimum between $$$f(i)$$$ and $$$f(l − i + 1)$$$ is maximized when $$$i = \left\lfloor \frac{l}{2} \right\rfloor$$$. Thus, we simplify the recurrence as:
Now returning to the initial cut, note that it is in Mouf's best interest to minimize $$$n'$$$ and $$$m'$$$ since $$$f$$$ is non-decreasing. To do so, he should ensure Fouad ends up on the boundary of the remaining grid after the first cut. This yields four possible configurations:
The total number of turns, including the initial cut, is:
The overall time complexity is: $$$O(\log(n) + \log(m))$$$.
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n, m, a, b;
cin >> n >> m >> a >> b;
vector<pair<int, int>> rec({
make_pair(a, m), make_pair(n - a + 1, m),
make_pair(n, b), make_pair(n, m - b + 1)});
int ans = n + m;
for (auto [n1, m1] : rec) {
int res = 0;
while (n1 > 1) {
++res;
n1 = (n1 + 1) / 2;
}
while (m1 > 1) {
++res;
m1 = (m1 + 1) / 2;
}
ans = min(ans, res);
}
cout << 1 + ans << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
2109C1 - Hacking Numbers (Easy Version)
Idea by MOUFLESS, prepared by MOUFLESS and FetFot.
Figure out a way to make $$$x$$$ equal $$$1$$$, then the final command will be $$$\texttt{"add n-1"}$$$.
What range of values can $$$x$$$ take after the first application of the $$$\texttt{"digit"}$$$ command?
What about the second application of the $$$\texttt{"digit"}$$$ command?
Avoid overusing the $$$\texttt{"digit"}$$$ command — after the second application, $$$x$$$ is limited to the range $$$[1, 16]$$$. Consider using the binary representation of $$$x$$$ instead.
- Apply $$$\texttt{"digit"}$$$ $$$\rightarrow$$$ $$$x \in [1, 81]$$$.
- Apply $$$\texttt{"digit"}$$$ $$$\rightarrow$$$ $$$x \in [1, 16]$$$.
- Apply $$$\texttt{"add -8"}$$$ $$$\rightarrow$$$ $$$x \in [1, 8]$$$.
- Apply $$$\texttt{"add -4"}$$$ $$$\rightarrow$$$ $$$x \in [1, 4]$$$.
- Apply $$$\texttt{"add -2"}$$$ $$$\rightarrow$$$ $$$x \in [1, 2]$$$.
- Apply $$$\texttt{"add -1"}$$$ $$$\rightarrow$$$ $$$x$$$ becomes exactly $$$1$$$.
- Finally, apply $$$\texttt{"add n-1"}$$$.
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
cout << "digit" << endl;
int x;
cin >> x;
cout << "digit" << endl;
cin >> x;
for (int i = 8; i >= 1; i /= 2) {
cout << "add " << -i << endl;
cin >> x;
}
cout << "add " << n - 1 << endl;
cin >> x;
cout << "!" << endl;
cin >> x;
assert(x == 1);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
2109C2 - Hacking Numbers (Medium Version)
Idea by MOUFLESS, prepared by MOUFLESS and FetFot.
The first command is not $$$\texttt{"digit"}$$$.
The first command is $$$\texttt{"mul"}$$$.
Combining the $$$\texttt{"mul"}$$$ and $$$\texttt{"digit"}$$$ commands is powerful! Consider a number that links these two commands.
Recall that well-known fact from high school: a number is divisible by $$$9$$$ if and only if the sum of its digits is divisible by $$$9$$$.
- Apply $$$\texttt{"mul 9"}$$$.
- Apply $$$\texttt{"digit"}$$$ $$$\rightarrow$$$ $$$x \in [9, 18, 27, 36, 45, 54, 63, 72, 81]$$$.
- Apply $$$\texttt{"digit"}$$$ $$$\rightarrow$$$ $$$x$$$ becomes exactly $$$9$$$.
- Finally, apply $$$\texttt{"add n-9"}$$$.
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
cout << "mul " << 9 << endl;
int x;
cin >> x;
cout << "digit" << endl;
cin >> x;
cout << "digit" << endl;
cin >> x;
cout << "add " << n - 9 << endl;
cin >> x;
cout << "!" << endl;
cin >> x;
assert(x == 1);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
2109C3 - Hacking Numbers (Hard Version)
Idea by MOUFLESS, prepared by MOUFLESS and FetFot.
While $$$9$$$ connects the $$$\texttt{"mul"}$$$ and $$$\texttt{"digit"}$$$ commands, there may be other numbers that do so as well.
Another valid solution for the medium version is as follows:
- $$$\texttt{"digit"}$$$.
- $$$\texttt{"mul 99"}$$$.
- $$$\texttt{"digit"}$$$.
- $$$\texttt{"add n-18"}$$$.
But what's the reasoning behind this sequence?
$$$S[(10^d - 1)x] = 9d \quad \forall x \in [1,10^d]$$$.
Let's prove that
Observe that
The first term represents $$$(x - 1)$$$ shifted $$$d$$$ places to the left (i.e. multiplies by $$$10^d$$$). The second term is the $$$d$$$-digit string of nines minus $$$(x - 1)$$$, namely
Therefore, for every $$$i$$$ ($$$1 \le i \le d$$$), the $$$i$$$-th digit of the second term and the $$$(i + d)$$$-th digit of the first term complement each other to sum to $$$9$$$.
Drumroll, please! The number we're about to use is $$$999\,999\,999$$$. With just three commands, we can turn any $$$x$$$ into $$$n$$$:
- Apply $$$\texttt{"mul } 999\,999\,999 \texttt{"}$$$.
- Apply $$$\texttt{"digit"}$$$ $$$\rightarrow$$$ $$$x$$$ becomes exactly $$$81$$$.
- Finally, apply $$$\texttt{"add n-81"}$$$.
There's one special case: if $$$n = 81$$$, you only need the first two commands — meaning $$$f(81) = 2$$$.
Now let’s see why no other $$$n$$$ can get away with just two commands. First, note that the digit‑sum function $$$S(i)$$$ always changes when you add $$$1$$$, so $$$S(i) \neq S(i + 1)$$$.
Consider your choice of first command:
- $$$\texttt{"add y"}$$$: When $$$y$$$ is positive, it shifts the entire range of possible $$$x$$$-values. Otherwise, it shrinks the range but never cuts it down below half its size. In either case, it can’t force $$$x$$$ into a single value.
- $$$\texttt{"div y"}$$$: It fails even on small $$$x$$$-values (e.g. $$$1 \le x \le 4$$$) — it doesn’t force a single outcome.
- $$$\texttt{"digit"}$$$: After the first application, it only restricts $$$x$$$ to $$$[1, 81]$$$, and a second application only narrows it to $$$[1, 16]$$$. You still don’t get a single fixed value.
That leaves only one candidate to start with, which is $$$\texttt{"mul y"}$$$. Suppose some other multiplier $$$y \neq 999\,999\,999$$$ made $$$S(x \cdot y)$$$ constant. Test it against $$$x = 1$$$ and $$$x = 999\,999\,999$$$:
They can’t both be the same, so no such $$$y \neq 999\,999\,999$$$ exists.
Similar to the above reasoning, keeping in mind that $$$S(i) \neq S(i + 1)$$$, the only possible second command is $$$\texttt{"digit"}$$$ (as this is the only way to shrink the range, since no other command can do so). Hence, only $$$n = 81$$$ can reach a fixed result in two commands; every other $$$n$$$ requires three.
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
cout << "mul 999999999" << endl;
int x;
cin >> x;
cout << "digit" << endl;
cin >> x;
if (n != 81) {
cout << "add " << n - 81 << endl;
cin >> x;
}
cout << "!" << endl;
cin >> x;
assert(x == 1);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
We hid the command limits in C3 so people wouldn’t just guess wildly. We used C1 to bridge the gap between B and C2. This problem was originally a D, but testers found what was then D1 (now C1) way easier than C (which got moved to D). The neat trick for C3 happened by chance — Kaitokid used $$$\texttt{"mul 99"}$$$ instead of the intended $$$\texttt{"mul 9"}$$$ in C2, and that's where MOUFLESS's guessing skills kicked in and saw it could be extended to $$$999\,999\,999$$$! After we worked through a formal proof, we decided it was too good not to include in the final problem set.
Idea by MOUFLESS, prepared by MOUFLESS and FetFot.
Suppose you've reached vertex $$$i$$$, what is the shortest possible sequence of moves that brings you back to $$$i$$$?
At any vertex $$$j$$$ adjacent to $$$i$$$, you may take back-and-forth move $$$[i \to j \to i].$$$
Let us temporarily set aside the multiset $$$A$$$. Starting from vertex $$$1$$$, define
Since any walk of length $$$d$$$ can be extended to $$$d + 2$$$ by inserting a back-and-forth move $$$[i \to j \to i]$$$ at any vertex $$$j$$$ adjacent to $$$i$$$, only the minimal even and odd distances matter. By performing a breadth-first search from vertex $$$1$$$, we derive $$$\mathrm{dist}$$$.
Now reintroduce the multiset $$$A$$$ with total sum $$$S = \sum A$$$. We would like to select a sub-multiset whose sum $$$S'$$$ satisfies both
- $$$S' \ge \mathrm{dist}[i][p];$$$
- $$$S' \bmod 2 = p.$$$
Taking all elements gives $$$S' = S$$$. Let $$$p = S \bmod 2$$$, then any vertex with $$$\mathrm{dist}[i][p] \le S$$$ is reachable by a walk of parity $$$p$$$. Otherwise, we must find a suitable $$$S' \bmod 2 = 1 - p$$$ satisfying $$$\mathrm{dist}[i][1 - p] \le S'$$$, and the minimal way to flip parity is to remove the smallest odd element $$$\min_{\mathrm{odd}}$$$ from the multiset $$$A$$$. Parity change is impossible if no such odd element exists, since removing any even element leaves the parity unchanged. Setting $$$S' = S - a_{\mathrm{odd}}$$$, any vertex with $$$\mathrm{dist}[i][1 - p] \le S'$$$ is reachable by a walk of parity $$$1 - p$$$.
In conclusion, vertex $$$i$$$ is attainable by a walk using the original multiset $$$A$$$ if and only if either
- $$$\mathrm{dist}[i][p] \le S \text{ when } p = S \bmod 2 \text{, or}$$$
- $$$\mathrm{dist}[i][p] \le S - \min_{\mathrm{odd}} \text{ when } p \neq S \bmod 2 \text{ and the smallest odd element } \min_{\mathrm{odd}} \in A \text{ exists.} $$$
The overall time complexity is: $$$O(n + m + \ell)$$$.
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n, m, l;
cin >> n >> m >> l;
int const inf = 2e9 + 1;
int sum = 0, min_odd = inf;
vector<int> a(l);
for (int i = 0; i < l; ++i) {
cin >> a[i];
sum += a[i];
if (a[i] % 2) {
min_odd = min(min_odd, a[i]);
}
}
vector adj(n, vector<int>());
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u;
--v;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<array<int, 2>> dist(n, {inf, inf});
queue<pair<int, int>> q;
q.push({0, 0});
dist[0][0] = 0;
while (q.size()) {
auto [u, p] = q.front();
q.pop();
for (auto v : adj[u]) {
if (dist[v][!p] > dist[u][p] + 1) {
dist[v][!p] = dist[u][p] + 1;
q.push({v, !p});
}
}
}
for (int i = 0; i < n; ++i) {
bool found = 0;
for (int p = 0; p < 2; ++p) {
int s = sum - (p == sum % 2 ? 0 : min_odd);
if (dist[i][p] <= s) {
found = 1;
}
}
cout << found;
}
cout << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
Idea by Intellegent, prepared by Intellegent.
The state of $$$s_i$$$ depend entirely on how many operations have been performed on the suffix $$$s_i, s_{i+1}, \ldots, s_n$$$.
Let $$$dp[i][j]$$$ denote the number of ways to perform exactly $$$j$$$ moves on the suffix $$$s_i, s_{i+1}, \ldots, s_n$$$.
Some useful insight is to see that if you operate on an element, then every element after it will be unaffected; similarly, the state of an element in the string depends only on the number of operations used on the suffix after it. More specifically, an element's state flips with each operation applied to a suffix that includes it, so its value depends entirely on the number of operations done to its suffix.
This inspires the following $$$dp$$$ state:
Now, regarding transitions — the number of ways to move from state $$$dp[i][j]$$$ to $$$dp[i - 1][j + k]$$$ (in other words the number of ways to add $$$k$$$ operations at the $$$(i - 1)$$$-th index) can be thought of in terms of forming strings composed of characters $$$A$$$ and $$$B$$$, where $$$A$$$ represents making a move on $$$s_{i - 1}$$$ and $$$B$$$ represents making a move on $$$s_i,...,s_n$$$. Each valid string with $$$j$$$ $$$B$$$s and $$$k$$$ $$$A$$$s represents a unique sequence of moves, so the total number of transitions corresponds to the number of such valid strings. Notice that a string will be valid if and only if every $$$A$$$ occurs when $$$s_{i - 1}$$$ is $$$0$$$, because $$$s_{i - 1}$$$ flips every operation, meaning that every $$$A$$$ should occur on either only even indices or only odd indices depending on the initial value of $$$s_{i - 1}$$$.
This means that the transition will be either $$$\displaystyle\binom{\left\lfloor \frac{j + k}{2} \right\rfloor}{k}$$$ or $$$\displaystyle\binom{\left\lceil \frac{j + k}{2} \right\rceil}{k}$$$.
Finally, the answer can be found in $$$dp[1][k]$$$.
The overall time complexity is: $$$O(n \cdot k^2)$$$.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << "\n";
#define vdebug(a) cout << #a << " = "; for(auto x: a) cout << x << " "; cout << "\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int uid(int a, int b) { return uniform_int_distribution<int>(a, b)(rng); }
ll uld(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(rng); }
const int MOD = 998244353;
template<ll mod> // template was not stolen from https://mirror.codeforces.com/profile/SharpEdged
struct modnum {
static constexpr bool is_big_mod = mod > numeric_limits<int>::max();
using S = conditional_t<is_big_mod, ll, int>;
using L = conditional_t<is_big_mod, __int128, ll>;
S x;
modnum() : x(0) {}
modnum(ll _x) {
_x %= static_cast<ll>(mod);
if (_x < 0) { _x += mod; }
x = _x;
}
modnum pow(ll n) const {
modnum res = 1;
modnum cur = *this;
while (n > 0) {
if (n & 1) res *= cur;
cur *= cur;
n /= 2;
}
return res;
}
modnum inv() const { return (*this).pow(mod-2); }
modnum& operator+=(const modnum& a){
x += a.x;
if (x >= mod) x -= mod;
return *this;
}
modnum& operator-=(const modnum& a){
if (x < a.x) x += mod;
x -= a.x;
return *this;
}
modnum& operator*=(const modnum& a){
x = static_cast<L>(x) * a.x % mod;
return *this;
}
modnum& operator/=(const modnum& a){ return *this *= a.inv(); }
friend modnum operator+(const modnum& a, const modnum& b){ return modnum(a) += b; }
friend modnum operator-(const modnum& a, const modnum& b){ return modnum(a) -= b; }
friend modnum operator*(const modnum& a, const modnum& b){ return modnum(a) *= b; }
friend modnum operator/(const modnum& a, const modnum& b){ return modnum(a) /= b; }
friend bool operator==(const modnum& a, const modnum& b){ return a.x == b.x; }
friend bool operator!=(const modnum& a, const modnum& b){ return a.x != b.x; }
friend bool operator<(const modnum& a, const modnum& b){ return a.x < b.x; }
friend ostream& operator<<(ostream& os, const modnum& a){ os << a.x; return os; }
friend istream& operator>>(istream& is, modnum& a) { ll x; is >> x; a = modnum(x); return is; }
};
using mint = modnum<MOD>;
struct Combi{
vector<mint> _fac, _ifac;
int n;
Combi() {
n = 1;
_fac.assign(n + 1, 1);
_ifac.assign(n + 1, 1);
}
void check_size(int m){
int need = n;
while (need < m) need *= 2;
m = need;
if (m <= n) return;
_fac.resize(m + 1);
_ifac.resize(m + 1);
for (int i = n + 1; i <= m; i++) _fac[i] = i * _fac[i - 1];
_ifac[m] = _fac[m].inv();
for (int i = m - 1; i > n; i--) _ifac[i] = _ifac[i + 1] * (i + 1);
n = m;
}
mint fac(int m){
check_size(m);
return _fac[m];
}
mint ifac(int m){
check_size(m);
return _ifac[m];
}
mint ncr(int n, int r){
if (n < r || r < 0) return 0;
return fac(n) * ifac(n - r) * ifac(r);
}
mint npr(int n, int r){
if (n < r || r < 0) return 0;
return fac(n) * ifac(n - r);
}
} comb;
void solve(){
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<vector<mint>> dp(n, vector<mint>(k + 1));
dp[n - 1][0] = 1;
if (s[n - 1] == '0')
dp[n - 1][1] = 1;
for (int i = n - 2; i >= 0; i--){
for (int j = 0; j <= k; j++){
for (int c = 0; j + c <= k; c++){
int spaces = (j + c + (s[i] == '0')) / 2;
dp[i][j + c] += dp[i + 1][j] * comb.ncr(spaces, c);
}
}
}
cout << dp[0][k] << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
}
Idea by MOUFLESS, prepared by MOUFLESS.
Suppose you need $$$\mathrm{dis}_F \ge x$$$. To achieve this, construct a "cage" — a contiguous path of cells all with values at least $$$x$$$ — that separates Fouad from the exit, while ensuring that $$$\mathrm{dis}_M$$$ remains unchanged.
Try to find a path for Mouf that impacts the building of the "cage" as little as possible.
First, find $$$\mathrm{dis}_M$$$ using Dijkstra's algorithm or DSU.
Define $$$can(x)$$$ to be true if you can make $$$\mathrm{dis}_F$$$ greater than or equal to $$$x$$$, and false otherwise. It's clear that if $$$can(x)$$$ is true, then $$$can(x−1)$$$ is also true, which leads us to perform a binary search on the value of $$$x$$$.
Suppose we choose a set $$$S$$$ of black cells with values strictly less than $$$x$$$ and decide to apply operations on them; the optimal strategy is to make the values of all chosen cells equal to $$$x$$$.
Now, suppose we don't care about $$$\mathrm{dis}_M$$$. How can we find the maximum possible $$$\mathrm{dis}_F$$$?
We need to create a cage that separates Fouad from the exit. The cage consists of the borders of the grid, in addition to cells with values greater than or equal to $$$x$$$ (after applying operations), forming a connected chain such that every two consecutive cells in the chain share an edge or corner.
By using multi-source Dijkstra's algorithm, start from one border and try to reach another, where the weight of each cell represents how many operations are needed to raise its value to at least $$$x$$$. If it cannot be reached (e.g., if the cell is white and its value is less than $$$x$$$), then set the weight to infinity.
We have six cases to build the cage, as described in the picture below:
Now we have two cases to consider:
- $$$x \le \mathrm{dis}_M$$$: In this scenario, $$$\mathrm{dis}_M$$$ will remain unchanged regardless of the set $$$S$$$ we choose.
- $$$x \gt \mathrm{dis}_M$$$: Here, we must ensure that at least one path for Mouf has a cost equal to $$$\mathrm{dis}_M$$$, while ensuring that no cell in this path is included in $$$S$$$.
But which path should we retain?
Suppose Mouf takes a path $$$P$$$. This action divides the grid into two parts:
Every cell reachable from $$$(n,1)$$$ without passing through any cell in $$$P$$$. This portion belongs to Fouad (if $$$(n, 1)$$$ is already in $$$P$$$, then there are no cells that belong to Fouad's part).
The remaining cells belong to Mouf.
As we observe, the more cells allocated to Fouad's part, the greater the options we have for constructing a cage. Therefore, we define a super path as a path that leaves the maximum number of cells available for Fouad's part. But how many super paths exist?
In fact, there is only one super path; the proof can be found below.
Suppose we have two super paths that intersect at certain cells (including the first and last cells). In this case, we have two scenarios to consider:
They only intersect at the first and last cells. In this situation, one of the paths cannot be a super path, leading to a contradiction.
They intersect at other cells: If this is the case, then neither of the paths can be considered a super path. We can take the optimal segments from each path to construct a superior path, which also leads to a contradiction.
For further clarification, please refer to the illustration below.
Now, how do we identify that super path?
We begin by performing a multi-source BFS, initializing the queue with the cells in the first row and the first $$$r$$$ cells of the last column (as they always belong to Mouf's part). When visiting a cell, we mark it. If its value is less than or equal to $$$\mathrm{dis}_M$$$, we pop it from the queue and continue; otherwise, we spread to the eight neighboring cells.
Through this process, we will have certainly marked the super path (and potentially some additional cells from Mouf's part). If $$$x \gt \mathrm{dis}_M$$$, it becomes impossible to utilize any marked cell to construct the cage — therefore, we set the weight for these cells to infinity. While you might consider the marked cells that are not part of the super path, this is inconsequential since any cage utilizing these cells will invariably pass through the super path.
The overall time complexity of this approach is: $$$O(n^2 \cdot \log(A_{MAX} + k) \cdot \log(n))$$$.
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int inf = 1e9;
array<int, 8> dx{0, 0, 1, -1, 1, 1, -1, -1};
array<int, 8> dy{1, -1, 0, 0, -1, 1, -1, 1};
void solve() {
int n, r, k;
cin >> n >> r >> k;
--r;
vector a(n, vector<int>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
vector b(n, vector<int>(n));
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
for (int j = 0; j < n; ++j) {
b[i][j] = s[j] - '0';
}
}
auto in = [&](int i, int j) {
return (0 <= i && i < n && 0 <= j && j < n);
};
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<>> pq;
pq.push({a[0][0], 0, 0});
vector dis(n, vector<int>(n, inf));
dis[0][0] = a[0][0];
while (pq.size()) {
auto [mx, i, j] = pq.top();
pq.pop();
if (dis[i][j] != mx) {
continue;
}
for (int dir = 0; dir < 4; ++dir) {
int ni = i + dx[dir];
int nj = j + dy[dir];
if (in(ni, nj) && dis[ni][nj] > max(mx, a[ni][nj])) {
int nmx = max(mx, a[ni][nj]);
dis[ni][nj] = nmx;
pq.push({nmx, ni, nj});
}
}
}
int mouf = dis[r][n - 1];
vector dont(n, vector<int>(n));
auto run = [&](auto &&run, int i, int j) -> void {
for (int dir = 0; dir < 8; ++dir) {
int ni = i + dx[dir];
int nj = j + dy[dir];
if (in(ni, nj) && dont[ni][nj] == 0) {
dont[ni][nj] = 1;
if (a[ni][nj] > mouf) {
run(run, ni, nj);
}
}
}
};
for (int j = 0; j < n; ++j) {
dont[0][j] = 1;
if (a[0][j] > mouf) {
run(run, 0, j);
}
}
for (int i = 0; i <= r; ++i) {
dont[i][n - 1] = 1;
if (a[i][n - 1] > mouf) {
run(run, i, n - 1);
}
}
int L = 1, R = 2e6;
while (L <= R) {
int mid = (L + R) / 2;
for (int j = 0; j < n; ++j) {
if ((mid > mouf && dont[n - 1][j]) || (mid > a[n - 1][j] && b[n - 1][j] == 0)) {
continue;
}
pq.push({max(0, mid - a[n - 1][j]), n - 1, j});
}
for (int i = r; i < n; ++i) {
if ((mid > mouf && dont[i][n - 1]) || (mid > a[i][n - 1] && b[i][n - 1] == 0)) {
continue;
}
pq.push({max(0, mid - a[i][n - 1]), i, n - 1});
}
fill(dis.begin(), dis.end(), vector<int>(n, inf));
while (pq.size()) {
auto [cost, i, j] = pq.top();
pq.pop();
dis[i][j] = min(dis[i][j], cost);
if (dis[i][j] != cost) {
continue;
}
for (int dir = 0; dir < 8; ++dir) {
int ni = i + dx[dir];
int nj = j + dy[dir];
if (in(ni, nj)) {
if ((mid > mouf && dont[ni][nj]) || (mid > a[ni][nj] && b[ni][nj] == 0)) {
continue;
}
if (dis[ni][nj] > cost + max(0, mid - a[ni][nj])) {
int ncost = cost + max(0, mid - a[ni][nj]);
dis[ni][nj] = ncost;
pq.push({ncost, ni, nj});
}
}
}
}
int minCost = inf;
if (mid <= mouf) {
for (int j = 0; j < n; ++j) {
minCost = min(minCost, dis[0][j]);
}
for (int i = 0; i <= r; ++i) {
minCost = min(minCost, dis[i][n - 1]);
}
}
for (int i = 1; i < n; ++i) {
minCost = min(minCost, dis[i][0]);
}
if (minCost <= k) {
L = mid + 1;
} else {
R = mid - 1;
}
}
cout << mouf << " " << R << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
When MOUFLESS came up with F, the intended solution was based on flows — then, thanks to the efforts of ApraCadabra, Kaitokid, and Wael_Zaiback, they helped us refine the problem until we got here.








Intuition behind C2?
The 4th hint mentions that $$$S(x)$$$ is divisible by 9 if $$$x$$$ is divisible by 9. Since $$$9x \leq 9\cdot 10^9$$$, $$$S(9x) \leq S(8999999991) = 81$$$ and $$$S(S(9x)) \leq S(81) = 9$$$ (since it must be divisble by $$$9$$$). Since $$$S(x) \gt 0$$$, this means that $$$S(S(9x))=9$$$.
Recall the divisibility trick for 9. Any number is divisible by 9 if the sum of it's digits are divisible by 9. With that in mind, we multiply x with 9. Then after performing 2 digits operation, x will be 9(why?). After that we just add n-9 or subtract 9-n from the number.
After multiplying a number with 9 the sum of its digit become 9 or multiple of 9
multiple of 9
why cant we do digit operation thrice or 4 times in C1.
After 2 digits the number is less than 16, after 3 is less than 9 and it's not dividing our range in half
i realized even LGMs took nearly 15-20 minutes on C3 showing its not a knowledge check but rather an insanely high quality problem
loved the contest
C is really amazing! Only solved c1 c2 :(
Yeah.Although I only managed to solve C1, I figured it out as soon as I saw hint 1. How amazing!
Blazingly fast editorial
F is a really good question well structured, and nicely written. My logic regarding dinic was wrong ig but the solution and hints make much more sense than whatever I was trying anyways
commenting even after cheating, damn bro.
I'm unsure why you would think I've cheated, but please do elaborate.
how can u reach master just by solving 108 problems and whos is even doing cp in go in india ?
I have practiced cses, atcoder qs before and also for the reason I use go is because I test packages for aur in Arch Linux so knowledge of go is helpful especially since hyprland uses it a lot
can u share ur atcoder problem count and cses problem count ???
Unfortunately when my main email was compromised since I had logged into it on a public space,I have lost access to my atcoder account. But u can see my go templates here which I have been using throughout. Also count of questions never relates to your skill, moreso the level of questions you solve.
i dont know why am i getting down voted as this guy is literally a cheater.
Can vouch. He doesn't cheat. He legit streamed this whole div for me.
CodeForces is not the only OJ in the world. Some people only compete in CodeForces, and it's too unethical to say that others cheat when you see that others don't do enough questions in CodeForces
cheaters defending cheaters great
Just because you couldnt achieve something doesnt make it impossible. Stop the saltiness :(
The super path in problem F seems to be the same as the left-hand rule in solving a maze, and that is how I implemented this problem.
I cannot find a proof that is intuitivem but it is probably right.
My implementation:
(c1) I was thinking about making it one. I was thinking about repetitive summation. But I couldn't put them together. And this was all in the very beginning. I probably would have easily solved C2 & C3 and then jump by like 1000 rating. (Sigh).
Loved C. I will use this as a riddle for non-cpers. Thank you for the lightning fast editorial as well
.
One of the best contests && editorials so far!
In problem C1
for the case "5 1234" By my logic, I'm getting correct answer, but getting wrong verdict could someone please help
my submission 320120751 `
when you output "!", the test case will stop immediately.
you can not continue to try other answer.
digit(1234) => 10
digit(10) => 1
add(1, -3) => 1, since 1 — 3 == -2. -2 < 1 and res should greater than 0.
add(1, -3) => 1.
add(1, n-3) => 3. since (n == 5) and (n — 3 == 2), so you get 1 + 2, which equals to 3
then you output "!" and the jury gave you a WA
got it thanks!
not being able to find my error in c1 sample test 2 here is my code 320132118
You've done -4,-2,-1 instead of -8,-4,-2,-1
thanks for finding this error. but still it should have pass the sample cases..shouldn't it? why it is saying code returned 1 instead of 5 in case 2
Because after last add, u forgot to take jury response inn.
could you help me why am I getting wrong in test case 2 ? expected 5 but got 1 ? 320172832 thankyou!
U are getting 1 instead of 5 because you forgot to take jury response inn after printing “!”. And also after 2 digit operations, the range will be 1 <= x <= 16.
thankyou so much
when u do digits the second time; 1 <= res <= 16 and not 1 <= res <= 9
Thank you for the great round and fast editorial.
can someone explain why this does not work 320080436
my code is similar with yours, the wrong answer is also same, ^-^ i want to know why it is wrong
well turns out, removing the part with the maximum area does not always give optimal results check this : here
why does this solution for C1 fail?
I also made this error at first, but it's because "!" also returns "1", so you need an additional "garbage line". Instead, your code is taking the "1" from the first "!" as the second n.
Can someone explain to me why, in problem B it is necessary to check all four possible initial cuts, instead of choosing the one that minimizes n'*m'? Thank you in advance :D
quick explanation
other guy = fouad egg = example few typos sorry
thank u so much man, i always suck when in the search of counterexamples xD
Thanks man!
To solve an 8*8 grid (area 64) you need 6 cuts.
However, to solve a 3*21 grid (area 63) you need 7 cuts.
thanks dude ;D
Hi! In fact, you don't have to check all 4 cases. You only need to check 2 cases, that is
1. eliminate max horizontaland2. eliminate max vertical. This is how I did it:deleted
C was an amazing problem and I thoroughly enjoyed D as well. Best Div-2 in a while imo.
https://mirror.codeforces.com/contest/2109/submission/320143895 https://mirror.codeforces.com/contest/2109/submission/320143592 Why using vector is giving runtime error this is the only difference between these submissions can someone explain :)
runtime error occurs in first one because l can exceed allocated size n+5, causing out-of-bounds access in arr[i]. second one avoids this by reading into a temporary variable instead of storing in the array.
size of array is l not n :)
thanks :)
To solve both C1 and C2, I focused on C2 first, knowing its logic would cover C1 as well. The key insight came from observing that the sum of digits of a number is equivalent to the number modulo 9, which led me to search for a uniform target, and 9 fit perfectly, as any multiple of 9 eventually reduces to 9 through repeated digit sums. I tested several approaches:
Case 1: Take the sum of digits first, then multiply → ❌ Fails for large numbers like
999999999(e.g., sum = 81 → 729, sum again = 18 → not reliable). Case 2: Take the sum of digits twice, then multiply → ❌ Still unreliable, doesn’t guarantee reduction to 9. Case 3: Multiply first, then take the sum of digits twice → ✅ Works for all values, including edge cases like999999999, always reduces to 9.Once we reach 9, we can add
(n-9)to get the desiredn, making all inputs consistent and efficient. I hope this provides some help on how we can approach the answer...C3 is an extremely amazing problem.
In Question D,
I found the mininum odd distance and even distance.
Then I am preprocessing array to find the maximum even distance and odd distance we can go from node 1.
then for every node i am checking if minimum odd distance or even distance is within reachable range.
But the logic is failing in 6test case, can someone please help in finding the issue in below logic
bool isPresent(int e,int o,int even, int odd){ if((e<=even && e>0)|| (o<=odd && o>0))return true; return false; }I thought question B could be simulated:the first preson choose the max area of four directions and cut, then the second person choose the mid point of the grid, but it is wrong, i want to know why, who can explain this question :D
here is my code 320140049 3q
cyclop5 linked his explanation above
exactly my problem, failing is test 2, 1516th test-case
yes, my code failed in 1516 case too
u cannot choose the max-area here is the counter-proof https://hackmd.io/@BVRtvyboStedZwQBOnYDHQ/HJLTUUI-xl
make_pair(a, m), make_pair(n — a + 1, m), make_pair(n, b), make_pair(n, m — b + 1)});
can anyone explain why need to do this for Question B
If it is just for symmetry then output should have been same for below code also ?
for the first cut this is important. Becoz monster is not always placed at median of the grid at the starting of the game.
Problem D is so similar to this problem.
What was div useful for in problem C? Is there any solution using it?
This submission fails on Test 6 can anyone help me with what is wrong? problem D
320150215
edit: i changed the max distance of a node from 1 to 1e18 from the previous 1e9 and it works
forgot to see that max(a[i])*l is atmost 2e9
can someone explain why this does not work in C1:
it should make all numbers
1 <= x <= 9to 1, right? Or am I missing something?after 9 you will have only 4 moves available (out of which 1 needs to be used to make it equal to n.
but after applying "digits" twice x can be as large as 16!!
Thanks!
1 extra operation?
I really enjoyed every problems and one of the best contest I ever participated
my thinking was correct for D but couldnt implmenet it ;/
Can anyone please explain the solution for B. i am unable to understand through editorial.
okay so after your first cut, the monster is always going to move to the middle as much as it can to slow you down. so the best thing you can do is just keep cutting things in half.
so you just try cutting up to where the monster is in all 4 directions. then for each cut, look at what you have left and figure out how many times you'll have to halve the rows and the columns (ceiling half because hes going to move to the side worst for you) until you have 1x1 and the minimum of the 4 is your answer
thank you so much!! it helps me to think about code!!
will someone please explain the jury thing to me please, I'm new. Much Appreciated :)
I'm so mad i got C1 correct from my first try but missed the last cin after the "!" aghh
hello this is my first comment and i need some help on why my approach for prob B is wrong here.
while(t-->0){ int n = xc.nextInt(); int m = xc.nextInt(); int a = xc.nextInt(); int b = xc.nextInt(); if(n-a+1 < a) a = n+1-a; if(m-b+1 < b) b = m+1-b; long ans = 0; if(n>m){ n=a; ans++; } else{ m=b; ans++; } ans += (int)Math.ceil(Math.log(n)/Math.log(2)); ans += (int)Math.ceil(Math.log(m)/Math.log(2)); xc.println(ans);```````````````````
my intuition is if the rows are larger than columns and regardless of where the monster is at first. we should always divide rows because else then in the next case we gotta divide them anyway.
my code is failing on the last case of test case 1. where it gives answer 11 instead of the given 10
i think ur supposed to see row cut % vs col cut % for the first cut
and u gotta understand rows and cols dont affect each other,regardless of what u cut first,the total no. of cuts remains the same..
hence for the first turn,in the last test case,its better to cut the col first cuz it reduces the moves required to cut col completely a lot more
your an absolute legend dude !! i finally understood it and ur thinking is right on point
thx I know
For question B, why is it wrong to delete the largest block in all four directions every time? Is there a counterexample ? my code
just check my comment above yours ull understand it .
Loved problem D.
What if we slightly change the problem statement in 2109B - Slice to Survive:
In each turn:
Mouf first cuts the grid along a row or column line into two parts, discarding the part without Fouad's monster. The grid must have at least two cells; otherwise, the game has already ended.
Then, in the same turn, Fouad moves his monster to any adjacent cell (up/down/left/right) within the remaining grid.
In C3 solution, this line
but this condition only holds for $$$y\in[1,10^9], y\neq 10^9-1$$$, right?
how about
mul yfor $$$y\in[10^9+1,10^{18}]$$$?then x * y > 10 ** 18 is possible, which is bad. (wasted commands)
In problem C1 I think that in case x=19 after 2 times use "digit" will make it equal to 0 so we need 1 "add 0" to find it so we need 8 questions or digit only return non-zero? Am I missing something ?(sorry for my bad english)
for the case x=19, digit(19) will be 1+9=10, not 0
I am sorry i mean after 2 times using digit like the solution. I also try the author MOUFLESS code it give the wrong answer in case x=19
.
in D-D-D it is written that there is no cycle in the graph but in the pretest 1 the subtest 2 there is cycle in it 5 5 1 5 1 2 2 3 3 4 4 5 3 5 in this 3 is connected with 5 and 4 and 4 and 5 are connected. please clarify if i did it incorrectly
It's a simple graph but a simple graph can infact contain a cycle
can anyone please tell me why its showing wrong output for problem B? Even though i checked multiple times ~~~~~~~~~~~~~~~~~~~~~~~~~ //this is code
include <bits/stdc++.h>
using namespace std;
void counti(int n, int m, int a, int b, int* count) { if (n == 1 && m == 1) return;
int left = (b - 1) * n; int right = (m - b) * n; int top = (a - 1) * m; int bottom = (n - a) * m; int maxi = max({left, right, top, bottom}); if (maxi == left) { m = m - (b - 1); b = 1; } else if (maxi == right) { m = b; } else if (maxi == top) { n = n - (a - 1); a = 1; } else { n = a; } a = ceil(n / 2.0); b = ceil(m / 2.0); (*count)++; counti(n, m, a, b, count);}
int main() {
int t; cin >> t; vector<int> ans; for (int i = 0; i < t; i++) { int n, m, a, b; cin >> n >> m >> a >> b; int count = 0; counti(n, m, a, b, &count); ans.push_back(count); } for (auto i : ans) { cout << i << endl; } return 0;} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can anyone please tell me why this approach 320081025 for 2109B - Slice to Survive is wrong. My idea was the person cuts such a way that the number of squares would be minimum and other one always tries to go to the center of the remaining part
If there are 2 board configurations 4*4 and 3*5. Which one is better? In the case of 4*4 (the area is 16), 4 moves are required, and in the case of 3*5 (the area is 15), 5 moves are required.
Okay. Thanks
D<<<C1 :<
I think problem D is too typical
Maybe it is because D was firstly proposed as C, and C1 was proposed as D1. That is why some people might consider D easier than C
10/10 contest
can anyone help me find whats wrong in my code for B
// this is my code ~~~~~ int main() {
ll T; cin >> T; while (T--) { ll n,m,a,b;cin>>n>>m>>a>>b; ll c=0; while(!(n==1 && m==1)){ if((min(a,n-a+1)*m)<(min(b,m-b+1)*n)) n=min(a,n-a+1); else m=min(b,m-b+1); a=(n+1)/2;b=(m+1)/2; c++; } cout<<c<<endl; } return 0;} ~~~~~
can someone point out where my submission for B is giving WA. 320076938
Can someone tell the mistake in my code? Unable to understand where I have gone wrong. 320113345
:-(
For problem B, the editorial suggests a $$$O(log(n) + log(m))$$$ solution by dividing $$$n$$$ and $$$m$$$ by 2 until they are 1. Why not just compute the $$$\log_2(n)$$$ and $$$\log_2(m)$$$ which would result in a $$$O(1)$$$ solution. See 320205143 for implementation.
Sorry, I don't get it What's wrong in what he said? I'm not high rated, I don't understand what's wrong with this approach Could someone pls check https://mirror.codeforces.com/contest/2109/submission/320361956
Can someone help me with Problem D? Why am I getting TLE in test case #7 while my solution is the same. #320193695
Can someone explain me why in B task moving monster into center is not best strategy? Or maybe say why this solution gets wa2 at test №1516 (!!!)
It is not obvious why greedily selecting the rectangle with the smallest area is the optimal strategy.
I select center because then the max chunk that first player could cut is smaller than any max chunk for any other positions of monster. And then first player chooses cut for the min possible chunk, so monster has less space to be, so first player will faster catch him to 1 cell (that are just my thoughts, i haven't proofs). If it's good solution — idk why that crashes, otherwise, if it's bad — idk why this solved 1515 tests...
The problem is not with selecting the position for the second player. Instead, consider the strategy for the first player, or search above for an explanation of why you are receiving a WA (it took me 30 seconds to find a discussion about exactly the 1516th test in the comments).
okay, thanks
/*in Q B i am doing a cut to the largest part then fit monster in the exact mid of it and keep doing untill n==m==1
can't understand why getting wrong on given test case 22 99 20 70 getting 11 should get 10, can anyone explain */ ~~~~~
// this is the code
void doit(int n, int m, int a, int b, int &x) { if (n <= 1 && m <= 1) return;
long long top = a - 1; long long bottom = n - a; long long left = b - 1; long long right = m - b; long long best = max({top, bottom, left, right}); int n1 = n, m1 = m, a1 = a, b1 = b; if (best == bottom) { n1 = top + 1; a1 = (n1 + 1) / 2; b1=(m+1)/2; } else if (best == top) { n1 = bottom + 1; a1 = (n1 + 1) / 2; b1=(m+1)/2; } else if (best == right) { m1 = left + 1; b1 = (m1 + 1) / 2; a1=(n+1)/2; } else { m1 = right + 1; b1 = (m1 + 1) / 2; a1=(n+1)/2; } x++; doit(n1, m1, a1, b1, x);}
void solve() { int n, m, a, b; cin >> n >> m >> a >> b;
} ~~~~~
Good Div2 thx for the contest
Can somebody explain why
vector<array<int, 2>> dist(n, {1e9, 1e9});does not work but2e9+1works in problem D? Submissionbecause sum a(i) = 2*10^5*10^4 = 2*10^9
man!what can i say!?I can simply and straightforwardly state that we didn't reach that conclusion about the number 9 in high school.
In task "2109A — It's Time To Duel" There must be at least one player with 0.
Can anyone tell me what am I doing wrong with problem B?
320251774
It gives WA at 1516th test case at test case 2.
can anyone tell why the largest area elimination approach does not work in problem B??
Because it assumes the monster won’t move after the cut. But in this game, Fouad can move to the worst-case position for Mouf every time. So removing the largest area doesn’t guarantee the fewest moves, as Fouad can reposition to force more turns. Instead, we must consider how many times we need to halve both row and column ranges, assuming Fouad always moves optimally to delay the game.
I have been thinking about the solution with flow for the last problem. I basically got the the point where I need to find the minumum cut between bottom left and destination while keeping the top left on the destination side. Is there some min cut algo that allows you to force a node to be on one side of the cut? If not, does anyone know the intended solution?
This is the fastest flow solution we came up with while testing; it took about $$$15$$$ seconds to pass tests. However, when the intended solution was the min-cut, the constraints differed ($$$n^2 \le 400$$$).
You can see the min-cut solution here: 320339656.
You can add edges with INF weight S -> X to force node X to be in S side, more generally, you can add that type of edge to force a set of nodes to be always in exactly one of the 2 sides. I did come up with the dijkstra solution so idk the flow implementation detalis. See this submission on other problem that uses that idea
Can anybody tell why my code is failing in Problem B in test case 2 in which 1516th numbers differ , my submission code — https://mirror.codeforces.com/contest/2109/my
My friend wrote some cheaters' name to MOUFLESS. Remove them from contest. Some copy from AI, some others use ChunkCode01 or a telegram channel called Contest Solvers. I looked all the submissions of the people who are newbie and are in the top 200. Most of the codes were identicial and most of them wrote ChunkCode01 as coment in their codes so, i researched and found that it is a Youtube channel giving the codes of the all problems' solution.
In the proof of C3 what happens if $$$(x - 1) \gt 10^d - 1$$$ (i.e. $$$(10^d - 1) - (x-1)$$$ is negative)
The proof breaks. But if $$$x - 1 \gt 10^d - 1 \dot\implies x \gt 10^d$$$, then $$$x \not\in [1, 10^d]$$$, i.e. the assumption of the proof is not satisfied and it doesn't matter (since the proof is a statement of the form $$$x \in [1, 10^d] \implies ...$$$).
Thanks, I did not see that part and assumed the proof was for all integers. Turns out the claim does not hold in the general case (for example $$$18$$$ does not divide $$$S(211 * 99) = S(20889) = 27$$$).
Yes, if the numbers are $$$ \gt 10^d$$$, then there will be an overlap after the shifting and the result might not be predictable (for all $$$x$$$)
Hi guys, i have a question to Problem a. We say that if The reported values were 101 for example, then it is valid and no one lied. But I think in this case it is possible that everyone lied since 010 is a possible outcome. And then everyone could lie to make it 101. Am I thinking right or am I missing something? Thanks in advance
Good point :) But I think what the problem is asking is "can the array be a possible outcome of the game assuming no one lied". So
101would be a possible outcome, and so is010.can anyone can explain test case 3 of B? why 4
i think it is 3. f(2,2) (n,m)=(3,3) -> the first turn: (n, m) = (3,2) f (1,1) -> second turn: (n,m) = (3,1) f(1,1) -> the third (n,m) = (1,1) f(1,1). the game end
Hi, I am having trouble understanding the E. I fail to understand the DP's transitions. and the intuition behind it. Can someone help me unlock this huge mindgap !? Thanks
Test case for 1516 for B Slice to Survive: would be something like this: 1
7 17 3 8
The answer should be 7, but the greedy algorithm if done to maximize the size of the part to be removed would give 8 as the answer for this. Essentially for the first step you should do a vertical cut instead of horizontal one. I think we can't choose a greedy option for step 1, cause if you choose the logic that do a cut that reduces the maximum side (rows or cols) first which would pass this case, but fail in :
1
22 99 20 70
So essentially we have only the choice of the first move, to decide which edge does F reaches nearer too, other than that it's gonna be half of that edge and a fixed number of moves. So for the first choice we need to check all possible ways only.
Can't we just use recursion for E (basically brute force)? let the initial state be f(s,k) First, we find all the indices i where s[i] = '0', then for each i, we find the string that comes by flipping the first i characters of the string (call this t) we then sum f(t,k-1) for all possible strings t. I calculated the time complexity to be O(n2k), which I don't think should give any problems, but I don't think the solution will be this straightforward. Can anyone tell me if I'm missing something? Edit: Ok NVM my brain wasnt working when I first wrote this
2109A — It's Time To Duel The code gives correct answers for all the sample test cases, but it is not getting accepted upon submission. Could someone please help me identify the issue? I'm new here nice to meet you all!
~~~~~~~~~~~~~~~~
This is code
t= int (input())
for _ in range(t): n = int(input()) a = list(map(int, input().split()))
if (n % 2 == 0): if (sum(a)% 2 == 0): print("yes") else: print("No") else: if (sum(a)%2 != 0): print("No") else: print("Yes")~~~~~~~~~~~~~~~~~~~~~
a
can anyone explain why this does not work https://mirror.codeforces.com/contest/2109/submission/324617912
it fails particularly for the case
538585931 350004549 292308221 202610425
can anyone tell what's wrong in this code, why is it giving runtime error for https://mirror.codeforces.com/problemset/problem/2109/C1 this problem
I am 100% sure that my approach is correct. Please look in solve() function
this is my submission https://mirror.codeforces.com/contest/2109/submission/325876581
the solution of problem b was unclear
Can anyone point out why is it giving me wrong answer for test case : 22 99 20 70
Anyone pls help? C1
Why i am getting WRONG ANS although my soln is same as editorial? 344622024
https://mirror.codeforces.com/contest/2109/submission/351443596
hi FetFot. My AC solution for D has a silly mistake because I found the overall minimum instead of the minimum odd number. However, it still gets AC. Was this accepted due to weak test cases?
Seems like the if logic at the end accidentally compensates for the bug.
in B I found the region which needs to be removed that eliminates the max rows and columns and then updated m and n accordingly and then did the same way as in editorial to find the remaining no of steps required but getting stuck on tc2. It would be great if someone could help. 353232624