Submission #283322

# Submission time Handle Problem Language Result Execution time Memory
283322 2020-08-25T14:25:27 Z davi_bart Toy Train (IOI17_train) C++14
15 / 100
2000 ms 1312 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
#define ll long long
//#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool pers[6000];
set<int> charge;
vector<int> p[6000];
vector<int> tempo(5010,0);
int temp=1;
int dfs(int pos,int last_charge){//return 0 if cycle without charger
  if(tempo[pos]>0){
    if(tempo[pos]>last_charge)return 0;
    return 1;
  }
  tempo[pos]=temp;
  if(charge.find(pos)!=charge.end())last_charge=temp;
  temp++;
  if(pers[pos]==0){
    int sol=1;
    for(int x:p[pos]){
      temp=tempo[pos]+1;
      sol=min(sol,dfs(x,last_charge));
      if(sol==0)break;
    }
    tempo[pos]=0;
    return sol;
  }else{
    int sol=0;
    for(int x:p[pos]){
      temp=tempo[pos]+1;
      sol=max(sol,dfs(x,last_charge));
      if(sol)break;
    }
    tempo[pos]=0;
    return sol;
  }
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	for(int i=0;i<a.size();i++)if(a[i])pers[i]=1;
	for(int i=0;i<r.size();i++)if(r[i])charge.insert(i);
	vector<int> ans(a.size(),0);
	for(int i=0;i<u.size();i++)p[u[i]].push_back(v[i]);
	for(int i=0;i<a.size();i++){
    temp=1;
    fill(tempo.begin(),tempo.end(),0);
    ans[i]=dfs(i,-2);
	}
	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:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i=0;i<a.size();i++)if(a[i])pers[i]=1;
      |              ~^~~~~~~~~
train.cpp:42:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int i=0;i<r.size();i++)if(r[i])charge.insert(i);
      |              ~^~~~~~~~~
train.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i=0;i<u.size();i++)p[u[i]].push_back(v[i]);
      |              ~^~~~~~~~~
train.cpp:45:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1024 KB Output is correct
2 Correct 20 ms 1024 KB Output is correct
3 Correct 19 ms 1016 KB Output is correct
4 Correct 19 ms 1024 KB Output is correct
5 Correct 19 ms 896 KB Output is correct
6 Correct 18 ms 1024 KB Output is correct
7 Correct 18 ms 1024 KB Output is correct
8 Correct 18 ms 1016 KB Output is correct
9 Correct 18 ms 896 KB Output is correct
10 Correct 24 ms 896 KB Output is correct
11 Correct 21 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2067 ms 1272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2086 ms 1312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 1152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1024 KB Output is correct
2 Correct 20 ms 1024 KB Output is correct
3 Correct 19 ms 1016 KB Output is correct
4 Correct 19 ms 1024 KB Output is correct
5 Correct 19 ms 896 KB Output is correct
6 Correct 18 ms 1024 KB Output is correct
7 Correct 18 ms 1024 KB Output is correct
8 Correct 18 ms 1016 KB Output is correct
9 Correct 18 ms 896 KB Output is correct
10 Correct 24 ms 896 KB Output is correct
11 Correct 21 ms 896 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 512 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Execution timed out 2067 ms 1272 KB Time limit exceeded
33 Halted 0 ms 0 KB -