Submission #609202

# Submission time Handle Problem Language Result Execution time Memory
609202 2022-07-27T12:48:13 Z yanndev Toy Train (IOI17_train) C++17
39 / 100
144 ms 1192 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MX = 5042;
 
int n;
int deg[MX];
int baseDeg[MX];
int nxt[2 * MX];
bool vis[MX];
bool vis2[MX];
bool isOk[MX];
bool isAlice[MX];
bool isCharge[MX];
vector<int> rgraph[MX];
vector<int> nodes {};
 
bool BFS() {
    int start = 0;
    int end = 0;
 
    for (auto& i: nodes) {
        deg[i] = baseDeg[i];
        if (isCharge[i] && isOk[i])
            nxt[end++] = i;
        vis[i] = vis2[i] = false;
    }
 
    //cout << layer << ' ' << (int)nxt.size() << '\n';
    
    while (start < end) {
        auto cur = nxt[start++];
        //cout << "cur is " << cur << '\n';
 
        if (vis[cur])
            continue;
        vis[cur] = true;
 
        for (auto& x: rgraph[cur]) {
            if (!vis2[x] && ((--deg[x] == 0) || isAlice[x])) {
                vis2[x] = true;
                nxt[end++] = x;
            }
        }
    }
 
  	vector<int> newNodes {};
  	bool ret = false;
  
    for (auto& i: nodes) {
        if (isOk[i] && !vis2[i]) {
          	//vis[i] = true;
            isOk[i] = false;
            ret = true;
        } else {
          newNodes.push_back(i);
        }
    }
 	nodes = newNodes;
    return ret;
}
 
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    n = (int)a.size();
 
    for (int i = 0; i < (int)u.size(); i++) {
        rgraph[v[i]].push_back(u[i]);
        baseDeg[u[i]]++;
    }
    
    for (int i = 0; i < n; i++) {
        isAlice[i] = a[i];
        isCharge[i] = r[i];
        isOk[i] = true;
      	nodes.push_back(i);
    }
 
    while (BFS());
 
    vector<int> ans (n);
    for (int i = 0; i < n; i++)
        ans[i] = isOk[i];
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 852 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 5 ms 852 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 5 ms 908 KB Output is correct
7 Correct 4 ms 896 KB Output is correct
8 Correct 5 ms 940 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 5 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 468 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1132 KB Output is correct
2 Correct 94 ms 1192 KB Output is correct
3 Correct 112 ms 1108 KB Output is correct
4 Correct 6 ms 1108 KB Output is correct
5 Correct 11 ms 1108 KB Output is correct
6 Correct 7 ms 1108 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 7 ms 1108 KB Output is correct
11 Correct 6 ms 1108 KB Output is correct
12 Correct 8 ms 980 KB Output is correct
13 Correct 9 ms 1128 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 7 ms 1108 KB Output is correct
16 Correct 6 ms 1180 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 144 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 980 KB Output is correct
2 Correct 5 ms 980 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 7 ms 1108 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 7 ms 1148 KB Output is correct
7 Correct 7 ms 1148 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 7 ms 1120 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 7 ms 1136 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 10 ms 1136 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1128 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 6 ms 1108 KB Output is correct
4 Correct 6 ms 1108 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 4 ms 852 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 4 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 852 KB Output is correct
2 Correct 6 ms 852 KB Output is correct
3 Correct 5 ms 852 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 5 ms 908 KB Output is correct
7 Correct 4 ms 896 KB Output is correct
8 Correct 5 ms 940 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 5 ms 936 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Incorrect 1 ms 468 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
16 Halted 0 ms 0 KB -