CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:eggag32
Submission time:2021-01-30 17:05:48 +0200
Language:C++ (C++17)
Status:READY
Result:22
Feedback
groupverdictscore
#1ACCEPTED22
#20
Test results
testverdicttimegroup
#1ACCEPTED0.14 s1, 2details
#2ACCEPTED0.11 s1, 2details
#3ACCEPTED0.13 s1, 2details
#4ACCEPTED0.14 s1, 2details
#5ACCEPTED0.11 s1, 2details
#6ACCEPTED0.13 s1, 2details
#7ACCEPTED0.14 s1, 2details
#8ACCEPTED0.11 s1, 2details
#9ACCEPTED0.16 s2details
#10--2details
#11--2details
#12ACCEPTED0.11 s2details
#13--2details
#14--2details
#15ACCEPTED0.11 s2details

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));
	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 = 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 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:

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:

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:

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:

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