CSES - NOI 2019 - Results
Submission details
Task:Distance Code
Sender:Knut Salomonsson
Submission time:2019-03-06 15:24:30 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.02 s1, 2, 3details
#20.02 s1, 2, 3details
#30.02 s1, 2, 3details
#40.02 s1, 2, 3details
#50.02 s1, 2, 3details
#60.01 s1, 2, 3details
#70.02 s1, 2, 3details
#80.02 s1, 2, 3details
#90.01 s1, 2, 3details
#100.02 s1, 2, 3details
#110.02 s1, 2, 3details
#120.02 s2, 3details
#130.01 s2, 3details
#140.02 s2, 3details
#150.01 s2, 3details
#160.04 s3details
#170.04 s3details
#180.04 s3details
#190.05 s3details
#200.02 s1, 2, 3details

Code

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define rep(i, a, b) for(int i = a;i<b;i++)
#define iter(it, obj) for(auto it = obj.begin();it != obj.end();it++)

vector<char> evs;
vi thieves;
int n, m, k;

vi dp(int i, vector<bool> free, vector<vi > pris, int out){
    char c = evs[i];
    int t = thieves[i];

    if(c == 'C'){
        if(!free[t])
            return {-1};
        if(i == m-1){
            return {1};
        }
        free[t] = false;
        out--;
        pris[0].push_back(t);
        vi arr1 = dp(i+1,free, pris, out);
        if(arr1[0] != -1){
            arr1.insert(arr1.begin(),1);
            return arr1;
        }
        pris[0].pop_back(); pris[1].push_back(t);
        vi arr2 = dp(i+1, free, pris, out);
        if(arr2[0] != -1){
            arr2.insert(arr2.begin(),2);
            return arr2;
        }
        return {-1};
    }

    if(c == 'O'){
        if(pris[0].size() == 0 && pris[1].size() == 0)
        return {-1};
        if(!free[t])
        return {-1};
        if(i == m-1){
            if(pris[0].size()>0)
                return {1};
            else return {2};
        }
        if(pris[0].size() > 0){
            int send = out;
            iter(it, pris[0]){
                free[*it] = true;
                send++;
            }
            vector<vi > cop = pris;
            cop[0].clear();
            vi arr1 = dp(i+1, free, cop, send);
            if(arr1[0] != -1){
                arr1.insert(arr1.begin(), 1);
                return arr1;
            }
        }
        if(pris[1].size()>0){
            int send = out;
            iter(it, pris[1]){
                free[*it] = true;
                send++;
            }
            vector<vi > cop = pris;
            cop[1].clear();
            vi arr2 = dp(i+1, free, cop, send);
            if(arr2[0] != -1){
                arr2.insert(arr2.begin(), 2);
                return arr2;
            }
        }

    }
    return {-1};
}

int main(){
    cin >> n >>k >> m;
    thieves.resize(m); evs.resize(m);

    rep(i,0, m){
        cin >> evs[i] >> thieves[i];
        thieves[i]--;
    }
    vector<bool> tmp1 = vector<bool>(n, true);
    vector<vi > tmp2 = vector<vi >(2, vi());

    vi arr = dp(0, tmp1, tmp2, n);
    if(arr[0] == -1){
        cout << "IMPOSSIBLE"<<endl;
        return 0;
    }
    iter(it, arr){
        cout << *it<<endl;
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
1
2
2 1

correct output
(empty)

user output
IMPOSSIBLE

Test 2

Group: 1, 2, 3

Verdict:

input
1
3
3 1
2 1

correct output
(empty)

user output
IMPOSSIBLE

Test 3

Group: 1, 2, 3

Verdict:

input
1
4
3 2
2 1
4 1

correct output
(empty)

user output
IMPOSSIBLE

Test 4

Group: 1, 2, 3

Verdict:

input
1
4
2 3
3 4
1 3

correct output
(empty)

user output
IMPOSSIBLE

Test 5

Group: 1, 2, 3

Verdict:

input
1
5
3 5
4 1
1 3
...

correct output
(empty)

user output
IMPOSSIBLE

Test 6

Group: 1, 2, 3

Verdict:

input
1
5
3 2
3 4
5 1
...

correct output
(empty)

user output
IMPOSSIBLE

Test 7

Group: 1, 2, 3

Verdict:

input
1
5
4 3
1 4
4 2
...

correct output
(empty)

user output
IMPOSSIBLE

Test 8

Group: 1, 2, 3

Verdict:

input
1
10
9 3
8 9
2 9
...

correct output
(empty)

user output
IMPOSSIBLE

Test 9

Group: 1, 2, 3

Verdict:

input
1
10
9 2
5 8
7 1
...

correct output
(empty)

user output
IMPOSSIBLE

Test 10

Group: 1, 2, 3

Verdict:

input
1
10
10 4
9 1
4 7
...

correct output
(empty)

user output
IMPOSSIBLE

Test 11

Group: 1, 2, 3

Verdict:

input
1
10
2 6
4 3
3 5
...

correct output
(empty)

user output
IMPOSSIBLE

Test 12

Group: 2, 3

Verdict:

input
1
500
10 6
6 255
6 428
...

correct output
(empty)

user output
IMPOSSIBLE

Test 13

Group: 2, 3

Verdict:

input
1
500
152 466
451 313
158 479
...

correct output
(empty)

user output
IMPOSSIBLE

Test 14

Group: 2, 3

Verdict:

input
1
500
109 440
330 190
443 161
...

correct output
(empty)

user output
IMPOSSIBLE

Test 15

Group: 2, 3

Verdict:

input
1
500
144 373
257 233
341 318
...

correct output
(empty)

user output
IMPOSSIBLE

Test 16

Group: 3

Verdict:

input
1
100000
54983 75172
93807 75172
44082 75172
...

correct output
(empty)

user output
IMPOSSIBLE

Test 17

Group: 3

Verdict:

input
1
100000
88863 19059
86423 76688
98536 95984
...

correct output
(empty)

user output
IMPOSSIBLE

Test 18

Group: 3

Verdict:

input
1
100000
59979 6389
19097 24999
27846 82330
...

correct output
(empty)

user output
IMPOSSIBLE

Test 19

Group: 3

Verdict:

input
1
100000
58761 66001
25102 51081
98625 67861
...

correct output
(empty)

user output
IMPOSSIBLE

Test 20

Group: 1, 2, 3

Verdict:

input
1
6
2 1
3 2
4 2
...

correct output
(empty)

user output
IMPOSSIBLE