CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:aryan12
Submission time:2021-01-30 21:54:45 +0200
Language:C++ (C++17)
Status:READY
Result:22
Feedback
groupverdictscore
#1ACCEPTED22
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#2ACCEPTED0.01 s1, 2details
#3ACCEPTED0.01 s1, 2details
#4ACCEPTED0.01 s1, 2details
#5ACCEPTED0.01 s1, 2details
#6ACCEPTED0.01 s1, 2details
#7ACCEPTED0.01 s1, 2details
#8ACCEPTED0.01 s1, 2details
#9--2details
#100.01 s2details
#110.01 s2details
#12ACCEPTED0.01 s2details
#130.01 s2details
#140.01 s2details
#15ACCEPTED0.01 s2details

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

void Solve() {
	int n;
	cin >> n;
	int total = n * (n + 1) / 2;
	if(total % 3 != 0) {
		cout << "IMPOSSIBLE\n";
		return;
	}
	int maxNeed = total / 3;
	bool dp[maxNeed][maxNeed + 1][maxNeed + 2];
	for(int i = 0; i < maxNeed; i++) {
		for(int j = 0; j <= maxNeed; j++) {
			for(int k = 0; k <= maxNeed + 1; k++) {
				dp[i][j][k] = false;
			}
		}
	}
	dp[0][0][0] = true;
	for(int cur = 1; cur <= n; cur++) {
		for(int i = 0; i < maxNeed; i++) {
			for(int j = 0; j <= maxNeed; j++) {
				for(int k = 0; k <= maxNeed + 1; k++) {
					if(i >= cur && dp[i - cur][j][k]) {
						dp[i][j][k] = true;
						continue;
					}
					if(j >= cur && dp[i][j - cur][k]) {
						dp[i][j][k] = true;
						continue;
					}
					if(k >= cur && dp[i][j][k - cur]) {
						dp[i][j][k] = true;
					}
				}
			}
		}
	}
	if(!dp[maxNeed - 1][maxNeed][maxNeed + 1]) {
		cout << "IMPOSSIBLE\n";
		return;
	}
	int curI = maxNeed - 1, curJ = maxNeed, curK = maxNeed + 1;
	vector<int> ans(n + 1);
	for(int cur = n; cur > 0; cur--) {
		if(curI >= cur && dp[curI - cur][curJ][curK]) {
			ans[cur] = 1;
			curI -= cur;
			continue;
		}
		if(curJ >= cur && dp[curI][curJ - cur][curK]) {
			ans[cur] = 2;
			curJ -= cur;
			continue;
		}
		ans[cur] = 3;
		curK -= cur;
	}
	for(int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	cout << "\n";
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
}

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 2 3 3 2 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 1 3 2 3 2 1 

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:

input
42

correct output
1 3 2 2 1 3 1 2 3 3 2 1 1 2 3 ...

user output
(empty)

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