Submission #282331

# Submission time Handle Problem Language Result Execution time Memory
282331 2020-08-24T10:11:42 Z Noam13 Toy Train (IOI17_train) C++14
28 / 100
283 ms 1276 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define ii pair<int, int>
#define x first
#define y second
#define vii vector<ii>
#define pb push_back
#define all(x) x.begin(), x.end()
#define loop(i,s,e) for(int i=s;i<e;++i)
#define loopr(i,s,e) for(int i=e-1;i>=s;--i)
#define chkmin(a,b) a = min(a,b)
#define chkmax(a,b) a = max(a,b)
using namespace std;
const int INF = 1e9;


int n;

vvi ag;
vi basedeg;
vi a,r;
vi res;
vb f(vb& s, int who){ // a = 1, b = 0
    vb check(n,0);
    vi deg(n);
    loop(i,0,n) deg[i] = basedeg[i];
    queue<int> q;
    loop(i,0,n) if(s[i]) q.push(i), check[i]=1, deg[i]=0;
    while(q.size()){
        int cur = q.front(); q.pop();
        for(auto nei:ag[cur]){
            if (res[nei]!=-1) continue;
            if (a[nei]==who){
                if (!check[nei]){
                    check[nei] = 1;
                    q.push(nei);
                }
            }
            else{
                if (--deg[nei]==0){
                    check[nei] = 1;
                    q.push(nei);
                }
            }
        }
    }
    return check;
}

vi who_wins(vi aa, vi rr, vi u, vi v) {
    a = aa, r = rr;
    n = a.size();
    basedeg.resize(n); ag.resize(n); 
    loop(i,0,u.size()){
        int a = u[i], b = v[i];
        basedeg[a]++;
        ag[b].pb(a);
    }
    res.resize(n,-1);
    while(1){
        vb b(n); 
        loop(i,0,n) if(r[i] && res[i]==-1){
            b[i] = 1;
        }
        b = f(b, 1);
        int cnt = 0, sz=0, cnt2=0;
        loop(i,0,n) if(res[i]==-1) cnt2+=b[i], b[i]=!b[i], sz++;
        if (cnt2==sz || sz==0){
            loop(i,0,n) if(res[i]==-1) res[i]=1;
            break;
        }
        b = f(b,0);
        loop(i,0,n) if(b[i]) cnt++;
        if (cnt==0){
            loop(i,0,n) if(res[i]==-1) res[i]=1;
            break;
        }
        loop(i,0,n) if(b[i]) {
            for(auto nei:ag[i]) basedeg[i]--;
            res[i]=0;
        }
    }   
	return res;
}

/*
clear
g++ c.cpp grader.cpp -o c ; ./c
6 7
0 1 0 0 1 0
1 0 0 0 0 1
0 1
1 2
2 3
3 1
4 5
5 5
4 1
*/

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:12:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define loop(i,s,e) for(int i=s;i<e;++i)
......
   57 |     loop(i,0,u.size()){
      |          ~~~~~~~~~~~~             
train.cpp:57:5: note: in expansion of macro 'loop'
   57 |     loop(i,0,u.size()){
      |     ^~~~
train.cpp:82:22: warning: unused variable 'nei' [-Wunused-variable]
   82 |             for(auto nei:ag[i]) basedeg[i]--;
      |                      ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 6 ms 896 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 5 ms 896 KB Output is correct
11 Correct 4 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Incorrect 1 ms 256 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 106 ms 1276 KB Output is correct
2 Correct 198 ms 1276 KB Output is correct
3 Correct 283 ms 1272 KB Output is correct
4 Correct 8 ms 1152 KB Output is correct
5 Incorrect 9 ms 1152 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1024 KB Output is correct
2 Correct 8 ms 1024 KB Output is correct
3 Correct 8 ms 1152 KB Output is correct
4 Correct 8 ms 1152 KB Output is correct
5 Correct 10 ms 1152 KB Output is correct
6 Correct 8 ms 1152 KB Output is correct
7 Correct 8 ms 1152 KB Output is correct
8 Correct 9 ms 1152 KB Output is correct
9 Correct 8 ms 1152 KB Output is correct
10 Correct 8 ms 1152 KB Output is correct
11 Correct 8 ms 1152 KB Output is correct
12 Correct 8 ms 1152 KB Output is correct
13 Correct 9 ms 1152 KB Output is correct
14 Correct 8 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1152 KB Output is correct
2 Correct 8 ms 1152 KB Output is correct
3 Correct 9 ms 1152 KB Output is correct
4 Correct 7 ms 1024 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 5 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 896 KB Output is correct
2 Correct 6 ms 896 KB Output is correct
3 Correct 6 ms 896 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 5 ms 896 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 5 ms 896 KB Output is correct
10 Correct 5 ms 896 KB Output is correct
11 Correct 4 ms 896 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Incorrect 1 ms 256 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -