답안 #67762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67762 2018-08-15T09:39:16 Z aquablitz11 장난감 기차 (IOI17_train) C++14
23 / 100
721 ms 1812 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;

const int N = 5e3+10;
vector<int> G[N], R[N];

vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V)
{
    // input
    int n = A.size();
    int m = U.size();
    for (int i = 0; i < m; ++i) {
        G[U[i]].push_back(V[i]);
        R[V[i]].push_back(U[i]);
    }

    vector<int> ans(n, 0);
    for (int i = 0; i < n; ++i) if (C[i]) { // i = main recharger we need for cycle
        // first step: find all nodes that can be forced to reach i
        vector<bool> reach(n, false);
        vector<int> cnt(n, 0);
        queue<int> Q;
        Q.push(i);
        reach[i] = true;
        while (!Q.empty()) {
            int u = Q.front(); Q.pop();
            for (auto p : R[u]) if (!reach[p]) {
                ++cnt[p];
                if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) {
                    reach[p] = true;
                    Q.push(p);
                }
            }
        }
        // second step: find if i could be in cycle or not
        vector<bool> cycle(n, false);
        int cntr = 0;
        for (auto v : G[i]) if (reach[v]) ++cntr;
        if ((A[i] && cntr > 0) || (!A[i] && cntr == G[i].size()))
            cycle[i] = true;
        // third step: find all nodes that could reach the cycle
        fill(cnt.begin(), cnt.end(), 0);
        if (cycle[i]) Q.push(i);
        while (!Q.empty()) {
            int u = Q.front(); Q.pop();
            ans[u] = 1;
            for (auto p : R[u]) if (!cycle[p]) {
                ++cnt[p];
                if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) {
                    cycle[p] = true;
                    Q.push(p);
                }
            }
        }
    }

    return ans;
}

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:30:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) {
train.cpp:40:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if ((A[i] && cntr > 0) || (!A[i] && cntr == G[i].size()))
                                             ~~~~~^~~~~~~~~~~~~~
train.cpp:50:63: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if ((A[p] && cnt[p] == 1) || (!A[p] && cnt[p] == G[p].size())) {
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 1016 KB 3rd lines differ - on the 26th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1016 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 1588 KB Output is correct
2 Correct 118 ms 1652 KB Output is correct
3 Correct 137 ms 1688 KB Output is correct
4 Correct 721 ms 1688 KB Output is correct
5 Correct 110 ms 1688 KB Output is correct
6 Correct 25 ms 1700 KB Output is correct
7 Correct 678 ms 1780 KB Output is correct
8 Correct 12 ms 1780 KB Output is correct
9 Correct 10 ms 1812 KB Output is correct
10 Correct 13 ms 1812 KB Output is correct
11 Correct 12 ms 1812 KB Output is correct
12 Correct 12 ms 1812 KB Output is correct
13 Correct 13 ms 1812 KB Output is correct
14 Correct 13 ms 1812 KB Output is correct
15 Correct 12 ms 1812 KB Output is correct
16 Correct 12 ms 1812 KB Output is correct
17 Correct 13 ms 1812 KB Output is correct
18 Correct 199 ms 1812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 1812 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1812 KB Output is correct
2 Correct 12 ms 1812 KB Output is correct
3 Correct 12 ms 1812 KB Output is correct
4 Correct 11 ms 1812 KB Output is correct
5 Correct 3 ms 1812 KB Output is correct
6 Correct 6 ms 1812 KB Output is correct
7 Correct 8 ms 1812 KB Output is correct
8 Correct 8 ms 1812 KB Output is correct
9 Correct 9 ms 1812 KB Output is correct
10 Correct 4 ms 1812 KB Output is correct
11 Correct 9 ms 1812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 1016 KB 3rd lines differ - on the 26th token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -