Submission #669789

# Submission time Handle Problem Language Result Execution time Memory
669789 2022-12-07T09:25:22 Z someone Toy Train (IOI17_train) C++14
12 / 100
8 ms 1972 KB
//#include "train.h"
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e4 + 42, INF = 1e9;

int n, m, nb[N], nbS[N];
vector<int> adj[N], ans, upd;
bool isA[N], isR[N], sent[N], mod[N];

inline void add(int i) {
    if(mod[i])
        return;
    mod[i] = true;
    upd.push_back(i);
}

void dfs(int i) {
    if(sent[i])
        return;
    sent[i] = true;
    add(i);
    for(int j : adj[i]) {
        add(j);
        nbS[j]++;
        if(isA[j] || nbS[j] == nb[j])
            dfs(j);
    }
}
 
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    n = (int)a.size();
    m = (int)u.size();
    for(int i = 0; i < n; i++)
        isA[i] = (a[i] == 1),
        isR[i] = (r[i] == 1);
    for(int i = 0; i < m; i++) {
        nb[u[i]]++;
        adj[v[i]].push_back(u[i]);
    }
    
    deque<int> id;
    for(int i = 0; i < n; i++)
        if(r[i])
            id.push_back(i);
    int sz = (int)id.size();
    while(true) {
        for(int j : id)
            dfs(j);
        for(int i = 0; i < sz; i++) {
            if((isA[id[0]] && nbS[id[0]] > 0) || (!isA[id[0]] && nbS[id[0]] == nb[id[0]]))
                id.push_back(id[0]);
            id.pop_front();
        }
        for(int j : upd) {
            nbS[j] = 0;
            sent[j] = false;
        }
        upd.clear();
        if(sz == (int)id.size())
            break;
        sz = id.size();
    }
    for(int i : id)
        dfs(i);
    for(int i = 0; i < n; i++)
        ans.push_back(((isA[i] && nbS[i] > 0) || (!isA[i] && nbS[i] == nb[i])));
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 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 Incorrect 6 ms 1972 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1364 KB Output is correct
2 Correct 6 ms 1364 KB Output is correct
3 Incorrect 7 ms 1460 KB 3rd lines differ - on the 108th token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1460 KB Output is correct
2 Correct 7 ms 1720 KB Output is correct
3 Correct 7 ms 1492 KB Output is correct
4 Correct 6 ms 1456 KB Output is correct
5 Correct 1 ms 564 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 5 ms 1080 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 4 ms 1096 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 1076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1108 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -