Submission #561788

# Submission time Handle Problem Language Result Execution time Memory
561788 2022-05-13T14:06:00 Z raid Toy Train (IOI17_train) C++17
100 / 100
383 ms 1728 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;
  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] ) {
	    if ( inset[v] && !S[v] && owner[v] == 1 ) {
          q.push(v);
	  	  S[v] = 1;
	    } else if ( inset[v] && !S[v] && owner[v] == 0 ) {
	      bool ok = true;
		  for ( auto vv : G[v] ) {
			if ( inset[vv] && S[vv] == 0 ) {
              ok = false;
			  break;
			}
		  }
		  if ( ok ) {
		    q.push(v);
		    S[v] = 1;
		  }
	    }
	  }
    }
	bool ok = true;
    for ( int i = 0; i < N; ++i ) {
	  if ( S[i] == 0 && inset[i] ) {
		ok = false;
		break;
	  }
	}
	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);
	  }
    } 
    while ( !q.empty() ) {
 	  int u = q.front();
	  q.pop();
	  for ( auto v : Gt[u] ) {
	    if ( inset[v] && !S[v] && owner[v] == 0 ) {
          q.push(v);
		  S[v] = 1;
	    } else if ( inset[v] && !S[v] && owner[v] == 1 ) {
		  bool ok = true;
		  for ( auto vv : G[v] ) {
			if ( inset[vv] && S[vv] == 0 ) {
              ok = false;
			  break;
			}
		  }
		  if ( ok ) {
		    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 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 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 4 ms 1036 KB Output is correct
8 Correct 4 ms 1140 KB Output is correct
9 Correct 4 ms 1056 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 5 ms 1128 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 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 540 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 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 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 536 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 1500 KB Output is correct
2 Correct 130 ms 1476 KB Output is correct
3 Correct 181 ms 1480 KB Output is correct
4 Correct 7 ms 1376 KB Output is correct
5 Correct 8 ms 1380 KB Output is correct
6 Correct 8 ms 1664 KB Output is correct
7 Correct 7 ms 1572 KB Output is correct
8 Correct 10 ms 1580 KB Output is correct
9 Correct 8 ms 1620 KB Output is correct
10 Correct 11 ms 1620 KB Output is correct
11 Correct 7 ms 1620 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 8 ms 1584 KB Output is correct
14 Correct 7 ms 1576 KB Output is correct
15 Correct 10 ms 1708 KB Output is correct
16 Correct 8 ms 1620 KB Output is correct
17 Correct 8 ms 1620 KB Output is correct
18 Correct 280 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1332 KB Output is correct
2 Correct 8 ms 1364 KB Output is correct
3 Correct 7 ms 1372 KB Output is correct
4 Correct 9 ms 1364 KB Output is correct
5 Correct 8 ms 1364 KB Output is correct
6 Correct 8 ms 1360 KB Output is correct
7 Correct 8 ms 1364 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 8 ms 1492 KB Output is correct
11 Correct 8 ms 1368 KB Output is correct
12 Correct 7 ms 1476 KB Output is correct
13 Correct 8 ms 1364 KB Output is correct
14 Correct 7 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1368 KB Output is correct
2 Correct 8 ms 1364 KB Output is correct
3 Correct 9 ms 1372 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 1136 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 7 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 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 4 ms 1036 KB Output is correct
8 Correct 4 ms 1140 KB Output is correct
9 Correct 4 ms 1056 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 5 ms 1128 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 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 540 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 540 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 536 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 78 ms 1500 KB Output is correct
33 Correct 130 ms 1476 KB Output is correct
34 Correct 181 ms 1480 KB Output is correct
35 Correct 7 ms 1376 KB Output is correct
36 Correct 8 ms 1380 KB Output is correct
37 Correct 8 ms 1664 KB Output is correct
38 Correct 7 ms 1572 KB Output is correct
39 Correct 10 ms 1580 KB Output is correct
40 Correct 8 ms 1620 KB Output is correct
41 Correct 11 ms 1620 KB Output is correct
42 Correct 7 ms 1620 KB Output is correct
43 Correct 7 ms 1492 KB Output is correct
44 Correct 8 ms 1584 KB Output is correct
45 Correct 7 ms 1576 KB Output is correct
46 Correct 10 ms 1708 KB Output is correct
47 Correct 8 ms 1620 KB Output is correct
48 Correct 8 ms 1620 KB Output is correct
49 Correct 280 ms 1308 KB Output is correct
50 Correct 6 ms 1332 KB Output is correct
51 Correct 8 ms 1364 KB Output is correct
52 Correct 7 ms 1372 KB Output is correct
53 Correct 9 ms 1364 KB Output is correct
54 Correct 8 ms 1364 KB Output is correct
55 Correct 8 ms 1360 KB Output is correct
56 Correct 8 ms 1364 KB Output is correct
57 Correct 7 ms 1364 KB Output is correct
58 Correct 7 ms 1364 KB Output is correct
59 Correct 8 ms 1492 KB Output is correct
60 Correct 8 ms 1368 KB Output is correct
61 Correct 7 ms 1476 KB Output is correct
62 Correct 8 ms 1364 KB Output is correct
63 Correct 7 ms 1364 KB Output is correct
64 Correct 9 ms 1368 KB Output is correct
65 Correct 8 ms 1364 KB Output is correct
66 Correct 9 ms 1372 KB Output is correct
67 Correct 7 ms 1364 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 4 ms 1136 KB Output is correct
70 Correct 7 ms 1108 KB Output is correct
71 Correct 7 ms 1108 KB Output is correct
72 Correct 5 ms 1108 KB Output is correct
73 Correct 2 ms 724 KB Output is correct
74 Correct 5 ms 980 KB Output is correct
75 Correct 143 ms 1648 KB Output is correct
76 Correct 214 ms 1700 KB Output is correct
77 Correct 277 ms 1684 KB Output is correct
78 Correct 263 ms 1728 KB Output is correct
79 Correct 247 ms 1680 KB Output is correct
80 Correct 8 ms 1576 KB Output is correct
81 Correct 8 ms 1644 KB Output is correct
82 Correct 9 ms 1620 KB Output is correct
83 Correct 12 ms 1620 KB Output is correct
84 Correct 11 ms 1572 KB Output is correct
85 Correct 9 ms 1620 KB Output is correct
86 Correct 9 ms 1580 KB Output is correct
87 Correct 9 ms 1640 KB Output is correct
88 Correct 14 ms 1576 KB Output is correct
89 Correct 9 ms 1620 KB Output is correct
90 Correct 14 ms 1576 KB Output is correct
91 Correct 12 ms 1580 KB Output is correct
92 Correct 19 ms 1620 KB Output is correct
93 Correct 30 ms 1632 KB Output is correct
94 Correct 22 ms 1664 KB Output is correct
95 Correct 23 ms 1656 KB Output is correct
96 Correct 114 ms 1552 KB Output is correct
97 Correct 230 ms 1648 KB Output is correct
98 Correct 383 ms 1620 KB Output is correct
99 Correct 369 ms 1600 KB Output is correct
100 Correct 275 ms 1292 KB Output is correct