Submission #561749

# Submission time Handle Problem Language Result Execution time Memory
561749 2022-05-13T12:35:36 Z raid Toy Train (IOI17_train) C++17
28 / 100
277 ms 1724 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;
	}
  } 
  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 5 ms 1364 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 5 ms 1220 KB Output is correct
5 Correct 5 ms 1188 KB Output is correct
6 Correct 5 ms 1236 KB Output is correct
7 Correct 4 ms 1236 KB Output is correct
8 Correct 5 ms 1228 KB Output is correct
9 Correct 5 ms 1216 KB Output is correct
10 Correct 4 ms 1192 KB Output is correct
11 Correct 4 ms 1184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 540 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 536 KB Output is correct
6 Correct 1 ms 540 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Incorrect 1 ms 540 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 112 ms 1716 KB Output is correct
2 Correct 199 ms 1704 KB Output is correct
3 Correct 277 ms 1724 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Incorrect 9 ms 1620 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 1492 KB Output is correct
2 Correct 8 ms 1528 KB Output is correct
3 Correct 8 ms 1620 KB Output is correct
4 Correct 9 ms 1580 KB Output is correct
5 Correct 8 ms 1672 KB Output is correct
6 Correct 8 ms 1620 KB Output is correct
7 Correct 8 ms 1620 KB Output is correct
8 Correct 8 ms 1576 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 8 ms 1708 KB Output is correct
11 Correct 8 ms 1620 KB Output is correct
12 Correct 8 ms 1620 KB Output is correct
13 Correct 8 ms 1700 KB Output is correct
14 Correct 8 ms 1600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1676 KB Output is correct
2 Correct 9 ms 1620 KB Output is correct
3 Correct 9 ms 1700 KB Output is correct
4 Correct 8 ms 1492 KB Output is correct
5 Correct 1 ms 548 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 8 ms 1236 KB Output is correct
8 Correct 6 ms 1304 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1364 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 5 ms 1220 KB Output is correct
5 Correct 5 ms 1188 KB Output is correct
6 Correct 5 ms 1236 KB Output is correct
7 Correct 4 ms 1236 KB Output is correct
8 Correct 5 ms 1228 KB Output is correct
9 Correct 5 ms 1216 KB Output is correct
10 Correct 4 ms 1192 KB Output is correct
11 Correct 4 ms 1184 KB Output is correct
12 Correct 1 ms 540 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 536 KB Output is correct
17 Correct 1 ms 540 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Incorrect 1 ms 540 KB 3rd lines differ - on the 2nd token, expected: '0', found: '1'
20 Halted 0 ms 0 KB -