Submission #283100

# Submission time Handle Problem Language Result Execution time Memory
283100 2020-08-25T09:59:21 Z MKopchev Toy Train (IOI17_train) C++14
0 / 100
2000 ms 1152 KB
#include "train.h"
#include<bits/stdc++.h>
using namespace std;

const int nmax=42;

int nxt[nmax];

vector<int> adj[nmax];

int n,owner[nmax],charge[nmax];

int rec(int node)//1-> A wins, 0-> B wins
{
    if(nxt[node]!=-1)
    {
        if(charge[node])return 1;

        int other=nxt[node];

        while(other!=node)
        {
            if(charge[other])return 1;

            other=nxt[other];
        }

        return 0;
    }

    for(auto k:adj[node])
    {
        nxt[node]=k;

        int mem=rec(k);

        if(mem==owner[node])return mem;

        nxt[node]=-1;
    }

    return !owner[node];
}

std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v)
{
    memset(nxt,-1,sizeof(nxt));

    n=a.size();

    for(int i=0;i<a.size();i++)owner[i]=a[i];

    for(int i=0;i<r.size();i++)charge[i]=r[i];

    for(int i=0;i<u.size();i++)
        adj[u[i]].push_back(v[i]);

    vector<int> ret={};

    for(int i=0;i<a.size();i++)
        ret.push_back(rec(i));

    return ret;
}

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:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=0;i<a.size();i++)owner[i]=a[i];
      |                 ~^~~~~~~~~
train.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=0;i<r.size();i++)charge[i]=r[i];
      |                 ~^~~~~~~~~
train.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i=0;i<u.size();i++)
      |                 ~^~~~~~~~~
train.cpp:60:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int i=0;i<a.size();i++)
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 896 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Execution timed out 2054 ms 256 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1152 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1024 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 1152 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 896 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -