답안 #669596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
669596 2022-12-06T19:59:11 Z someone 장난감 기차 (IOI17_train) C++14
0 / 100
7 ms 1588 KB
//#include "train.h"
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e4 + 42, INF = 1e9;

bool isA[N], isR[N];
vector<int> adj[N], ans, upd;
int n, m, nb[N], val[N], nb0[N];

void dfs(int i) {
    if(val[i] >= 2)
        return;
    upd.push_back(i);
    if(isR[i])
        val[i]++;
    if(val[i] == 1) {
        for(int j : adj[i]) {
            nb0[j]--;
            if(nb0[j] == 0 || isA[j]) {
                val[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]]++;
        nb0[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 = id.size();
    while(true) {
        for(int j : id)
            dfs(j);
        for(int i = 0; i < sz; i++) {
            if(val[id[0]] >= 2)
                id.push_back(id[0]);
            id.pop_front();
        }
        for(int j : upd) {
            val[j] = 0;
            nb0[j] = nb[j];
        }
        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((val[i] > 0));
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 980 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1492 KB Output is correct
2 Correct 6 ms 1588 KB Output is correct
3 Correct 6 ms 1492 KB Output is correct
4 Incorrect 7 ms 1584 KB 3rd lines differ - on the 216th token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1108 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1236 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 980 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -