Submission #283346

# Submission time Handle Problem Language Result Execution time Memory
283346 2020-08-25T14:51:05 Z davi_bart Toy Train (IOI17_train) C++14
0 / 100
2000 ms 99704 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());
vector<int> charge,pers;
vector<int> p[6000];
vector<int> tempo(5010,0);
int memo[5020][5020];
int temp=1;
int dfs(int pos,int last_charge){//return 0 if cycle without charger
  //cout<<pos<<" "<<last_charge<<" "<<memo[pos][last_charge]<<endl;
  if(memo[pos][last_charge+3]>=0)return memo[pos][last_charge+3];
  if(tempo[pos]>0){
    if(last_charge>=0 && tempo[pos]>tempo[last_charge])return memo[pos][last_charge+3]=0;
    return memo[pos][last_charge+3]=1;
  }
  tempo[pos]=temp;
  if(charge[pos])last_charge=pos;
  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 memo[pos][last_charge+3]=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 memo[pos][last_charge+3]=sol;
  }
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v){
  pers=a;charge=r;
	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++){
    if(pers[i]){
      sort(p[i].begin(),p[i].end(),[&](int aa,int bb){
        if(charge[aa]==charge[bb])return aa<bb;
        return (bool)charge[aa];
      });
    }else{
      sort(p[i].begin(),p[i].end(),[&](int aa,int bb){
        if(charge[aa]==charge[bb])return aa<bb;
        return (bool)charge[bb];
      });
    }
	}
	for(int i=0;i<a.size();i++){
    temp=1;
    fill(tempo.begin(),tempo.end(),0);
    for(int j=0;j<=a.size();j++)fill(memo[j],memo[j]+a.size()+10,-1);
    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: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<u.size();i++)p[u[i]].push_back(v[i]);
      |              ~^~~~~~~~~
train.cpp:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
train.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
train.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int j=0;j<=a.size();j++)fill(memo[j],memo[j]+a.size()+10,-1);
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2094 ms 99064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB 3rd lines differ - on the 6th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2095 ms 99704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2093 ms 99448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2089 ms 99492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2094 ms 99064 KB Time limit exceeded
2 Halted 0 ms 0 KB -