Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
Forget the exact sums for a second. Only their values modulo matter.
For any cut, the three remainders satisfy
List the possible triples of residues modulo . If three residues are all equal, their sum is modulo . If they are all different, they are exactly , whose sum is also modulo .
So if the total array sum is not divisible by , there is no possible answer. No cut can magically fix that. Math is rude like that.
If the total sum is divisible by , then for any valid cut, . With three residues modulo , that automatically means they are either all equal or all different. Since , just output , .
The problem looks like it wants you to search for the right two cut points. It really does not.
Let the three part sums modulo be . Since the three parts cover the whole array exactly once,
Now look at what the condition actually says.
If are all the same, then the triple is one of:
Each has sum modulo .
If are all different, then because the only residues modulo are , the triple must be some permutation of:
That also has sum modulo .
So a valid cut can exist only if the total sum of the array is divisible by .
The sneaky part: this condition is also sufficient.
For any three residues modulo , if their sum is modulo , then they must be either:
There is no third option. If exactly two were equal, say with , then the sum would not be modulo .
So if the total sum is divisible by , literally any valid cut works. Since , the cut , always makes three non-empty parts:
Therefore:
1 2;0 0.Complexity: per test case, just to compute the sum. Memory: .
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sum = (sum + x) % 3;
}
if (sum == 0) cout << "1 2\n";
else cout << "0 0\n";
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sum = (sum + x) % 3;
}
if (sum == 0) cout << "1 2\n";
else cout << "0 0\n";
}
return 0;
}