Submission #561775

# Submission time Handle Problem Language Result Execution time Memory
561775 2022-05-13T13:15:01 Z raid Toy Train (IOI17_train) C++17
28 / 100
290 ms 1504 KB
#include <bits/stdc++.h>
#include "train.h"

using namespace std;

const int MAXN = 5005;

vector<int> G[MAXN], Gt[MAXN], owner, fuel;
vector<int> res, viz, S;
vector<int> inset;
int N;

vector<int> who_wins( vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
  owner = a, fuel = r;
  
  for ( int i = 0; i < (int)u.size(); ++i ) {
	G[u[i]].push_back(v[i]);
	Gt[v[i]].push_back(u[i]);
  }
  N = a.size();
  res.resize(N), S.resize(N);
  queue<int> q;
  viz.assign(N, 0);
  inset.resize(N);
  for ( int i = 0; i < N; ++i ) inset[i] = 1;
  bool emp = false;
  while ( !emp ) {
    for ( int i = 0; i < N; ++i ) {
      if ( fuel[i] && inset[i] ) {
	    q.push(i);
	    S[i] = 1;
      } else {
		S[i] = 0;
	  }
    }
    while ( !q.empty() ) {
	  int u = q.front();
	  q.pop();
	  for ( auto v : Gt[u] ) {
	    ++viz[v];
	    if ( inset[v] && !S[v] && owner[v] == 1 ) {
          q.push(v);
	  	  S[v] = 1;
	    } else if ( inset[v] && !S[v] && owner[v] == 0 && viz[v] == (int)G[v].size() ) {
		  q.push(v);
		  S[v] = 1;
	    }
	  }
    }
	bool ok = true;
    for ( int i = 0; i < N; ++i ) {
	  if ( S[i] == 0 && inset[i] ) {
		ok = false;
	  }
	}
	if ( ok ) {
	  for ( int i = 0; i < N; ++i ) {
		res[i] = S[i];
	  }
      break;
	}
	for ( int i = 0; i < N; ++i ) {
	  if ( inset[i] ) {
	    S[i] = 1 - S[i];
	    if ( S[i] ) q.push(i);
	  }
      viz[i] = 0;
    } 
    while ( !q.empty() ) {
 	  int u = q.front();
	  q.pop();
	  for ( auto v : Gt[u] ) {
	    ++viz[v];
	    if ( inset[v] && !S[v] && owner[v] == 0 ) {
          q.push(v);
		  S[v] = 1;
	    } else if ( inset[v] && !S[v] && owner[v] == 1 && viz[v] == (int)G[v].size() ) {
		  q.push(v);
		  S[v] = 1;
	    }
	  }
    }
	for ( int i = 0; i < N; ++i ) {
      if ( S[i] ) inset[i] = 0;
	  viz[i] = 0;
	}
  } 
  return res;
}
/*
int main() {

	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int> a(n), r(n), u(m), v(m);

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for(int i = 0; i < m; i++)
		scanf("%d", &u[i]);
	for ( int i = 0; i < m; ++i ) {
	  scanf("%d", &v[i]);
	}

	vector<int> res = who_wins(a, r, u, v);

	for(int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1108 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1164 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 4 ms 1108 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Incorrect 1 ms 468 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 106 ms 1504 KB Output is correct
2 Correct 209 ms 1496 KB Output is correct
3 Correct 290 ms 1492 KB Output is correct
4 Correct 8 ms 1496 KB Output is correct
5 Incorrect 9 ms 1480 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 6 ms 1236 KB Output is correct
2 Correct 7 ms 1352 KB Output is correct
3 Correct 8 ms 1396 KB Output is correct
4 Correct 7 ms 1492 KB Output is correct
5 Correct 8 ms 1492 KB Output is correct
6 Correct 7 ms 1360 KB Output is correct
7 Correct 8 ms 1364 KB Output is correct
8 Correct 8 ms 1356 KB Output is correct
9 Correct 7 ms 1352 KB Output is correct
10 Correct 7 ms 1492 KB Output is correct
11 Correct 7 ms 1504 KB Output is correct
12 Correct 7 ms 1472 KB Output is correct
13 Correct 8 ms 1500 KB Output is correct
14 Correct 7 ms 1396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1492 KB Output is correct
2 Correct 7 ms 1492 KB Output is correct
3 Correct 8 ms 1492 KB Output is correct
4 Correct 7 ms 1364 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 5 ms 1108 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1108 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 5 ms 1144 KB Output is correct
5 Correct 5 ms 1164 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 4 ms 1108 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Incorrect 1 ms 468 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -