Submission #836161

# Submission time Handle Problem Language Result Execution time Memory
836161 2023-08-24T08:09:05 Z kamelfanger83 Toy Train (IOI17_train) C++14
11 / 100
9 ms 1436 KB
#include <vector>
#include <iostream>
#include <queue>
#include <cassert>

#include "train.h"

using namespace std;

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v){
    int n = a.size();
    vector<vector<int>> edg (n), revedg (n);
    vector<int> recharg;
    for (int i = 0; i < n; ++i) {
        if (r[i]) recharg.push_back(i);
    }
    for (int i = 0; i < u.size(); ++i) {
        edg[u[i]].push_back(v[i]);
        revedg[v[i]].push_back(u[i]);
    }
    queue<int> addWin;
    for (int i : recharg) addWin.push(i);
    vector<int> res (n);
    vector<int> outwin (n);
    while(!addWin.empty()){
        int i = addWin.front();
        addWin.pop();
        if (res[i]) continue;
        res[i] = true;
        for (int re : revedg[i]){
            outwin[re]++;
            if (a[re] && outwin[re] == 1) addWin.push(re);
            else if (!a[re] && outwin[re] == edg[re].size()) addWin.push(re);
        }
    }
    queue<int> rWin;
    for (int i : recharg){
        if (res[i]){
            if (a[i] && !outwin[i]) rWin.push(i);
            else if (!a[i] && outwin[i] < edg[i].size()) rWin.push(i);
        }
    }
    while (!rWin.empty()){
        int i = rWin.front();
        rWin.pop();
        if (!res[i]) continue;
        res[i] = false;
        for (int re : revedg[i]){
            outwin[re]--;
            assert(outwin[re] >= 0);
            if (!a[re]) rWin.push(re);
            else if (outwin[re] == 0) rWin.push(re);
        }
    }
    return res;
}
/*
int main(){
    auto ret = who_wins({1, 1}, {0, 1}, {1, 0}, {0, 0});
    for (int i : ret) cout << i << " ";
    return 0;
}*/

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:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < u.size(); ++i) {
      |                     ~~^~~~~~~~~~
train.cpp:33:43: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             else if (!a[re] && outwin[re] == edg[re].size()) addWin.push(re);
train.cpp:40:41: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             else if (!a[i] && outwin[i] < edg[i].size()) rWin.push(i);
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 980 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 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 5 ms 1392 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 7 ms 1236 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 6 ms 1364 KB Output is correct
4 Correct 9 ms 1392 KB Output is correct
5 Correct 6 ms 1364 KB Output is correct
6 Correct 6 ms 1364 KB Output is correct
7 Correct 6 ms 1364 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 6 ms 1364 KB Output is correct
11 Correct 7 ms 1436 KB Output is correct
12 Correct 6 ms 1364 KB Output is correct
13 Correct 6 ms 1364 KB Output is correct
14 Correct 5 ms 1204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1364 KB Output is correct
2 Correct 6 ms 1364 KB Output is correct
3 Correct 7 ms 1304 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 1032 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Incorrect 4 ms 852 KB 3rd lines differ - on the 5th token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 980 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -