Task: | Split in Three |
Sender: | eggag32 |
Submission time: | 2021-01-30 17:15:37 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 22 |
#2 | ACCEPTED | 78 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.03 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 1, 2 | details |
#3 | ACCEPTED | 0.03 s | 1, 2 | details |
#4 | ACCEPTED | 0.03 s | 1, 2 | details |
#5 | ACCEPTED | 0.01 s | 1, 2 | details |
#6 | ACCEPTED | 0.03 s | 1, 2 | details |
#7 | ACCEPTED | 0.03 s | 1, 2 | details |
#8 | ACCEPTED | 0.01 s | 1, 2 | details |
#9 | ACCEPTED | 0.03 s | 2 | details |
#10 | ACCEPTED | 0.20 s | 2 | details |
#11 | ACCEPTED | 0.21 s | 2 | details |
#12 | ACCEPTED | 0.01 s | 2 | details |
#13 | ACCEPTED | 0.23 s | 2 | details |
#14 | ACCEPTED | 0.26 s | 2 | details |
#15 | ACCEPTED | 0.01 s | 2 | details |
Code
#pragma GCC optimize ("O3")#pragma GCC target ("sse4")#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef long double ld;typedef vector<int> vi;typedef pair<int, int> pi;#define debug(x) cerr << #x << ": " << x << endl#define debug2(x, y) debug(x), debug(y)#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)#define rep(i, a) for(int i = 0; i < (int)(a); i++)#define all(v) v.begin(), v.end()#define mp make_pair#define pb push_back#define lb lower_bound#define ub upper_bound#define fi first#define se second#define sq(x) ((x) * (x))const int mxN = 1675;template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }pair<int, pi> dp[mxN][mxN];int main(){ios_base::sync_with_stdio(false);cin.tie(0);//freopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);int n;cin >> n;//x - 1, x, x + 1int sum = (n * (n + 1)) / 2;if(sum % 3 != 0){cout << "IMPOSSIBLE" << '\n';return 0;}int x = sum / 3;rep(i, mxN) rep(j, mxN) dp[i][j] = mp(0, mp(-1, -1));dp[0][0] = mp(1, mp(-1, -1));for(int i = n; i >= 1; i--){if(dp[x - 1][x].fi) break;for(int j = x; j >= 0; j--){for(int k = x; k >= 0; k--) if(dp[j][k].fi){if(x - j >= i && !dp[j + i][k].fi){dp[j + i][k].fi = 1;dp[j + i][k].se = mp(j, k);}if(x - k >= i && !dp[j][k + i].fi){dp[j][k + i].fi = 1;dp[j][k + i].se = mp(j, k);}}}}if(dp[x - 1][x].fi){vi ans(n, 3);int a = x - 1, b = x;while(dp[a][b].se.fi != -1){int dif = max(a - dp[a][b].se.fi, b - dp[a][b].se.se);int f = 1;if(a == dp[a][b].se.fi) f = 0;ans[dif - 1] = (f ? 1 : 2);int a1 = dp[a][b].se.fi, b1 = dp[a][b].se.se;a = a1, b = b1;}rep(i, n) cout << ans[i] << " ";cout << '\n';}else cout << "IMPOSSIBLE" << '\n';return 0;}/*Things to look out for:- Integer overflows- Make sure that max is large enough (2e9, 4e18)- Special casesBe careful!*/
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
1 2 3 |
user output |
---|
1 2 3 |
Test 2
Group: 1, 2
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 3
Group: 1, 2
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
1 3 1 3 2 |
user output |
---|
3 3 3 1 2 |
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
1 3 2 2 1 3 |
user output |
---|
3 3 2 2 3 1 |
Test 5
Group: 1, 2
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 6
Group: 1, 2
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
2 3 1 2 3 3 2 1 |
user output |
---|
3 3 3 2 1 1 3 2 |
Test 7
Group: 1, 2
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
1 2 3 1 2 3 3 2 1 |
user output |
---|
3 3 3 3 1 3 2 2 1 |
Test 8
Group: 1, 2
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 9
Group: 2
Verdict: ACCEPTED
input |
---|
42 |
correct output |
---|
1 3 2 2 1 3 1 2 3 3 2 1 1 2 3 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... |
Test 10
Group: 2
Verdict: ACCEPTED
input |
---|
95 |
correct output |
---|
1 3 1 3 2 1 2 3 3 2 1 1 2 3 3 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... Truncated |
Test 11
Group: 2
Verdict: ACCEPTED
input |
---|
96 |
correct output |
---|
1 3 2 2 1 3 1 2 3 3 2 1 1 2 3 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... Truncated |
Test 12
Group: 2
Verdict: ACCEPTED
input |
---|
97 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
98 |
correct output |
---|
2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... Truncated |
Test 14
Group: 2
Verdict: ACCEPTED
input |
---|
99 |
correct output |
---|
1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 ... |
user output |
---|
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ... Truncated |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
100 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |