CSES - Datatähti Open 2021 - Results
Submission details
Task:Split in Three
Sender:kenechi
Submission time:2021-01-31 11:57:42 +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.04 s2details
#10--2details
#11--2details
#12ACCEPTED0.01 s2details
#13--2details
#14--2details
#15ACCEPTED0.01 s2details

Compiler report

input/code.cpp: In function 'void check(std::vector<long long int>&)':
input/code.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (; id < v.size(); id++) {
            ~~~^~~~~~~~~~
input/code.cpp:28:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (; id < v.size(); id++) {
            ~~~^~~~~~~~~~
input/code.cpp:39:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (; id < v.size(); id++) {
            ~~~^~~~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;

int need;
void check(vector<int> &v) {
    int id = 0, sum = 0;
    bool fd1 = false;
    bool fd2 = false;
    bool fd3 = false;

    vector<int> now(v.size(), 1);
    for (; id < v.size(); id++) {
        sum += v[id];
        if (sum == need - 1) {
            fd1 = 1;
            break;
        }
    }
    id++;

    sum = 0;
    for (; id < v.size(); id++) {
        sum += v[id];
        now[v[id] - 1] = 2;
        if (sum == need) {
            fd2 = 1;
            break;
        }
    }
    id++;

    sum = 0;
    for (; id < v.size(); id++) {
        sum += v[id];
        now[v[id] - 1] = 3;
        if (sum == need + 1) {
            fd3 = 1;
            break;
        }
    }
    if (fd1 and fd2 and fd3) {
        for (auto x: now)cout << x << " ";
        exit(0);
    }
}

void solve() {
    int n;
    cin >> n;

    vector<int> v(n);
    iota(v.begin(), v.end(), 1ll);

//    v = {1, 3, 7, 4, 8, 2, 5, 6};
    if (n * (n + 1) % 6) {
        cout << "IMPOSSIBLE" << endl;
        return;
    }
    need = n * (n + 1) / 6;
    do {
        check(v);
    } while (next_permutation(v.begin(), v.end()));
    cout << "IMPOSSIBLE" << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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: 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