Submission #106468

# Submission time Handle Problem Language Result Execution time Memory
106468 2019-04-18T15:14:52 Z KLPP Toy Train (IOI17_train) C++14
28 / 100
306 ms 3064 KB
#include "train.h"
#include<vector>
#include<iostream>
#include<queue>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
vector<int> nei[10000];
vector<int> inv[10000];
bool active[10000];
int owner[10000];
int charge[10000];
int n;
bool S[10000];
int count[10000];
int reference;
void extend(int node){
  if(S[node])return;
  S[node]=true;
  //cout<<node<<endl;
  rep(i,0,inv[node].size()){
    int v=inv[node][i];
    if(active[v]){
      count[v]++;
      if(!S[v]){
	if(reference==owner[v]){
	//cout<<v<<endl;
	
	  extend(v);
	}else{
	  if(count[v]==nei[v].size()){
	  
	    extend(v);
	  }
	}
      }
    }
  }
}
void solve(){
  //rep(i,0,n)cout<<active[i]<<" ";
  //cout<<endl;
  reference=1;
  rep(i,0,n)count[i]=0;
  rep(i,0,n){
    S[i]=false;
  }
  rep(i,0,n){
    if(charge[i] && active[i])extend(i);
  }
  int cont=0;
  rep(i,0,n){
    
    if(!S[i] && active[i])S[i]=true;
    else S[i]=false;
    cont+=S[i];
    //cout<<S[i]<<endl;
    //cout<<S[i]<<" ";
  }//cout<<endl;
  if(cont==0)return;
  reference=0;
  rep(i,0,n)count[i]=0;
  queue<int> q;
  rep(i,0,n){
    if(S[i] && active[i]){
      q.push(i);
      S[i]=false;
    }
  }
  while(!q.empty()){
    extend(q.front());
    q.pop();
  }
  rep(i,0,n){
    if(active[i] && S[i]){
      active[i]=false;
    }
  }
  solve();
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
  n=a.size();
  rep(i,0,n){
    owner[i]=a[i];
    charge[i]=r[i];
  }
  rep(i,0,u.size()){
    nei[u[i]].push_back(v[i]);inv[v[i]].push_back(u[i]);
  }
  rep(i,0,n)active[i]=true;
  solve();
  vector<int> answer;
  rep(i,0,n){
    answer.push_back(active[i]);
  }
  return answer;
}

Compilation message

train.cpp: In function 'void extend(int)':
train.cpp:6:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i=a;i<b;i++)
train.cpp:20:7:
   rep(i,0,inv[node].size()){
       ~~~~~~~~~~~~~~~~~~~~       
train.cpp:20:3: note: in expansion of macro 'rep'
   rep(i,0,inv[node].size()){
   ^~~
train.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(count[v]==nei[v].size()){
       ~~~~~~~~^~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:6:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,a,b) for(int i=a;i<b;i++)
train.cpp:86:7:
   rep(i,0,u.size()){
       ~~~~~~~~~~~~               
train.cpp:86:3: note: in expansion of macro 'rep'
   rep(i,0,u.size()){
   ^~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1408 KB Output is correct
2 Correct 9 ms 1536 KB Output is correct
3 Correct 9 ms 1536 KB Output is correct
4 Correct 9 ms 1536 KB Output is correct
5 Correct 8 ms 1536 KB Output is correct
6 Correct 9 ms 1536 KB Output is correct
7 Correct 7 ms 1536 KB Output is correct
8 Correct 9 ms 1536 KB Output is correct
9 Correct 12 ms 1536 KB Output is correct
10 Correct 11 ms 1408 KB Output is correct
11 Correct 8 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 896 KB Output is correct
2 Correct 3 ms 768 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Incorrect 3 ms 896 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 2248 KB Output is correct
2 Correct 223 ms 2824 KB Output is correct
3 Correct 306 ms 3064 KB Output is correct
4 Correct 14 ms 2044 KB Output is correct
5 Incorrect 17 ms 2048 KB 3rd lines differ - on the 11th token, expected: '0', found: '1'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1656 KB Output is correct
2 Correct 13 ms 1664 KB Output is correct
3 Correct 11 ms 1664 KB Output is correct
4 Correct 18 ms 1664 KB Output is correct
5 Correct 11 ms 1792 KB Output is correct
6 Correct 12 ms 1792 KB Output is correct
7 Correct 14 ms 1664 KB Output is correct
8 Correct 12 ms 1664 KB Output is correct
9 Correct 16 ms 1536 KB Output is correct
10 Correct 13 ms 1764 KB Output is correct
11 Correct 18 ms 1792 KB Output is correct
12 Correct 12 ms 1792 KB Output is correct
13 Correct 16 ms 1792 KB Output is correct
14 Correct 18 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1792 KB Output is correct
2 Correct 13 ms 1920 KB Output is correct
3 Correct 16 ms 1792 KB Output is correct
4 Correct 15 ms 1664 KB Output is correct
5 Correct 3 ms 896 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 8 ms 1408 KB Output is correct
8 Correct 9 ms 1408 KB Output is correct
9 Correct 11 ms 1576 KB Output is correct
10 Correct 5 ms 1024 KB Output is correct
11 Correct 12 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1408 KB Output is correct
2 Correct 9 ms 1536 KB Output is correct
3 Correct 9 ms 1536 KB Output is correct
4 Correct 9 ms 1536 KB Output is correct
5 Correct 8 ms 1536 KB Output is correct
6 Correct 9 ms 1536 KB Output is correct
7 Correct 7 ms 1536 KB Output is correct
8 Correct 9 ms 1536 KB Output is correct
9 Correct 12 ms 1536 KB Output is correct
10 Correct 11 ms 1408 KB Output is correct
11 Correct 8 ms 1536 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 3 ms 768 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 2 ms 768 KB Output is correct
18 Correct 3 ms 896 KB Output is correct
19 Incorrect 3 ms 896 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -