Task: | Split in Three |
Sender: | eggag32 |
Submission time: | 2021-01-30 17:03:29 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 22 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 22 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.13 s | 1, 2 | details |
#2 | ACCEPTED | 0.11 s | 1, 2 | details |
#3 | ACCEPTED | 0.13 s | 1, 2 | details |
#4 | ACCEPTED | 0.13 s | 1, 2 | details |
#5 | ACCEPTED | 0.11 s | 1, 2 | details |
#6 | ACCEPTED | 0.14 s | 1, 2 | details |
#7 | ACCEPTED | 0.13 s | 1, 2 | details |
#8 | ACCEPTED | 0.11 s | 1, 2 | details |
#9 | ACCEPTED | 0.17 s | 2 | details |
#10 | TIME LIMIT EXCEEDED | -- | 2 | details |
#11 | TIME LIMIT EXCEEDED | -- | 2 | details |
#12 | ACCEPTED | 0.11 s | 2 | details |
#13 | TIME LIMIT EXCEEDED | -- | 2 | details |
#14 | TIME LIMIT EXCEEDED | -- | 2 | details |
#15 | ACCEPTED | 0.11 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 = 1705; template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); } pair<int, pair<vi, vi>> 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 + 1 int sum = (n * (n + 1)) / 2; if(sum % 3 != 0){ cout << "IMPOSSIBLE" << '\n'; return 0; } int x = sum / 3; vi emp; rep(i, mxN) rep(j, mxN) dp[i][j] = mp(0, mp(emp, emp)); dp[0][0] = mp(1, mp(emp, emp)); repn(i, 1, n + 1){ 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 = dp[j][k].se; dp[j + i][k].se.fi.pb(i); } if(x - k >= i && !dp[j][k + i].fi){ dp[j][k + i].fi = 1; dp[j][k + i].se = dp[j][k].se; dp[j][k + i].se.se.pb(i); } } } } if(dp[x - 1][x].fi){ vi ans(n, 3); rep(i, dp[x - 1][x].se.fi.size()) ans[dp[x - 1][x].se.fi[i] - 1] = 1; rep(i, dp[x - 1][x].se.se.size()) ans[dp[x - 1][x].se.se[i] - 1] = 2; 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 cases Be 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 2 2 1 3 |
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
1 3 2 2 1 3 |
user output |
---|
1 3 2 2 1 3 |
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 |
---|
2 1 1 2 3 1 2 3 |
Test 7
Group: 1, 2
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
1 2 3 1 2 3 3 2 1 |
user output |
---|
2 1 1 1 1 2 3 2 3 |
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 |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 10
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
95 |
correct output |
---|
1 3 1 3 2 1 2 3 3 2 1 1 2 3 3 ... |
user output |
---|
(empty) |
Test 11
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
96 |
correct output |
---|
1 3 2 2 1 3 1 2 3 3 2 1 1 2 3 ... |
user output |
---|
(empty) |
Test 12
Group: 2
Verdict: ACCEPTED
input |
---|
97 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 13
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
98 |
correct output |
---|
2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 ... |
user output |
---|
(empty) |
Test 14
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
99 |
correct output |
---|
1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 ... |
user output |
---|
(empty) |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
100 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |