CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:lookcook
Submission time:2021-01-30 16:59:00 +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
#9ACCEPTED0.30 s2details
#10--2details
#11--2details
#12--2details
#13--2details
#14--2details
#15--2details

Code

#include <bits/stdc++.h>

#define int long long

using namespace std;

map<pair<int,int>,bool> dp[5005];
map<pair<int,int>,int> to[5005];
int n;
bool rec(int a, int b, int c, int cur) {
    if (dp[a].count({b,c}) != 0) return dp[a][{b,c}];
    if (cur == n+1) {
        if (b == a+1 && b == c-1) return true;
        else return false;
    }
    bool res = false;
    if (rec(a+cur,b,c,cur+1)) {
        res = true;
        to[a][{b,c}] = 1;
    } else if (rec(a,b+cur,c,cur+1)) {
        res = true;
        to[a][{b,c}] = 2;
    } else if (rec(a,b,c+cur,cur+1)) {
        res = true;
        to[a][{b,c}] = 3;
    }
    dp[a][{b,c}] = res;
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    bool res = rec(0,0,0,1);
    if (!res) {
        cout << "IMPOSSIBLE\n";
        exit(0);
    }
    int a = 0, b = 0, c = 0;
    for (int i = 1; i <= n; i++) {
        int x = to[a][{b,c}];
        cout << x << ' ';
        if (x == 1) a += i;
        else if (x == 2) b += i;
        else c += i;
    }
    cout << '\n';
}
/*

*/

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

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

Test 7

Group: 1, 2

Verdict: ACCEPTED

input
9

correct output
1 2 3 1 2 3 3 2 1 

user output
1 1 1 2 2 2 3 1 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:

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:

input
97

correct output
IMPOSSIBLE

user output
(empty)

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:

input
100

correct output
IMPOSSIBLE

user output
(empty)