Submission #836146

# Submission time Handle Problem Language Result Execution time Memory
836146 2023-08-24T07:58:14 Z kamelfanger83 Toy Train (IOI17_train) C++14
11 / 100
13 ms 1664 KB
#include <vector>
#include <iostream>
#include <queue>

#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);
        }
    }
    while (true){
        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);
            }
        }
        if (rWin.empty()) break;
        while (!rWin.empty()){
            int i = rWin.front();
            rWin.pop();
            if (!res[i]) continue;
            res[i] = false;
            for (int re : revedg[i]){
                outwin[re]--;
                if (a[re] && outwin[re] == 0) rWin.push(re);
                else if (!a[re] && outwin[re] == edg[re].size() - 1) rWin.push(re);
            }
        }
    }
    return res;
}
/*
int main(){
    auto ret = who_wins({0, 0, 1, 0}, {0, 1, 0, 0}, {0, 1, 1, 2, 2, 3}, {0, 0, 1, 1, 3, 3});
    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:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < u.size(); ++i) {
      |                     ~~^~~~~~~~~~
train.cpp:32: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]
   32 |             else if (!a[re] && outwin[re] == edg[re].size()) addWin.push(re);
train.cpp:40:45: 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);
train.cpp:52:47: 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]
   52 |                 else if (!a[re] && outwin[re] == edg[re].size() - 1) rWin.push(re);
# Verdict Execution time Memory Grader output
1 Incorrect 3 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 1 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 1364 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 5 ms 1236 KB Output is correct
2 Correct 6 ms 1364 KB Output is correct
3 Correct 8 ms 1492 KB Output is correct
4 Correct 6 ms 1620 KB Output is correct
5 Correct 6 ms 1588 KB Output is correct
6 Correct 7 ms 1448 KB Output is correct
7 Correct 7 ms 1492 KB Output is correct
8 Correct 13 ms 1488 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 6 ms 1620 KB Output is correct
11 Correct 6 ms 1664 KB Output is correct
12 Correct 6 ms 1620 KB Output is correct
13 Correct 8 ms 1592 KB Output is correct
14 Correct 6 ms 1492 KB Output is correct
# 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 Correct 6 ms 1364 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 980 KB Output is correct
7 Correct 4 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 3 ms 980 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -