CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:lookcook
Submission time:2021-01-30 17:24:36 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2details
#20.01 s1, 2details
#3ACCEPTED0.01 s1, 2details
#4ACCEPTED0.01 s1, 2details
#50.01 s1, 2details
#6ACCEPTED0.01 s1, 2details
#7ACCEPTED0.01 s1, 2details
#80.01 s1, 2details
#9ACCEPTED0.01 s2details
#10ACCEPTED0.01 s2details
#11ACCEPTED0.01 s2details
#120.01 s2details
#13ACCEPTED0.01 s2details
#14ACCEPTED0.01 s2details
#150.01 s2details

Compiler report

input/code.cpp: In function 'long long int rec(long long int, long long int)':
input/code.cpp:13:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (pos == v.size()) {
         ~~~~^~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:48:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (p != v.size()) {
            ~~^~~~~~~~~~~
input/code.cpp:64:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (p != v.size()) {
            ~~^~~~~~~~~~~
input/code.cpp:80:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (p != v.size()) {
            ~~^~~~~~~~~~~

Code

#include <bits/stdc++.h>

#define int long long

using namespace std;

int dp[105][5055];
int to[105][5055];
int n;
vector<int> v;
int seek;
int rec(int pos, int sum) {
    if (pos == v.size()) {
        if (sum == seek) return true;
        else return false;
    }
    if (dp[pos][sum] != -1) return dp[pos][sum];
    int res = 0;
    if (rec(pos+1,sum) == 1) {
        res = 1;
        to[pos][sum] = 0;
    } else if (rec(pos+1,sum+v[pos]) == 1) {
        res = 1;
        to[pos][sum] = 1;
    }
    dp[pos][sum] = res;
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int taken[n+1];
    for (int i = 0; i <= n; i++) taken[i] = 0;
    int sum = (n*(n+1))/2;
    //cout << "Sum = " << sum << '\n';
    int aSum = (sum+1)/3-1;
    int bSum = (sum+1)/3;
    int cSum = (sum+1)/3+1;
    //cout << "ASum = " << aSum << " BSum = " << bSum << " CSum = " << cSum << '\n';
    for (int i = 1; i <= n; i++) v.push_back(i);
    for (int i = 0; i < 105; i++) for (int j = 0; j < 5055; j++) dp[i][j] = -1;
    seek = aSum;
    rec(0,0);
    int p = 0;
    int s = 0;
    while (p != v.size()) {
        if (to[p][s] == 0) {
            p++;
        } else if (to[p][s] == 1) {
            s += v[p];
            taken[v[p]] = 1;
            p++;
        }
    }
    v = {};
    for (int i = 1; i <= n; i++) if (taken[i] == 0) v.push_back(i);
    for (int i = 0; i < 105; i++) for (int j = 0; j < 5055; j++) dp[i][j] = -1;
    seek = bSum;
    rec(0,0);
    p = 0;
    s = 0;
    while (p != v.size()) {
        if (to[p][s] == 0) {
            p++;
        } else if (to[p][s] == 1) {
            s += v[p];
            taken[v[p]] = 2;
            p++;
        }
    }
    v = {};
    for (int i = 1; i <= n; i++) if (taken[i] == 0) v.push_back(i);
    for (int i = 0; i < 105; i++) for (int j = 0; j < 5055; j++) dp[i][j] = -1;
    seek = cSum;
    rec(0,0);
    p = 0;
    s = 0;
    while (p != v.size()) {
        if (to[p][s] == 0) {
            p++;
        } else if (to[p][s] == 1) {
            s += v[p];
            taken[v[p]] = 3;
            p++;
        }
    }
    for (int i = 1; i <= n; i++) cout << taken[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:

input
4

correct output
IMPOSSIBLE

user output
0 1 2 3 

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:

input
7

correct output
IMPOSSIBLE

user output
0 2 1 3 1 3 2 

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

Test 8

Group: 1, 2

Verdict:

input
10

correct output
IMPOSSIBLE

user output
0 3 3 3 2 2 2 1 1 3 

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:

input
97

correct output
IMPOSSIBLE

user output
0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...
Truncated

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:

input
100

correct output
IMPOSSIBLE

user output
0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...
Truncated