Submission #113495

# Submission time Handle Problem Language Result Execution time Memory
113495 2019-05-26T00:55:02 Z E869120 Toy Train (IOI17_train) C++14
49 / 100
1480 ms 217324 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

const int INF = (1 << 30);

int N, M;
int A[20009], R[20009], U[20009], V[20009];
bool u1[20009], u2[20009];

vector<int> solve_subtask1() {
	for (int i = 0; i < M; i++) {
		if (V[i] - U[i] == 0) u1[U[i]] = true;
		if (V[i] - U[i] == 1) u2[U[i]] = true;
	}
	vector<int>ans;
	for (int i = 0; i < N; i++) {
		bool arezou = false;
		for (int j = i; j < N; j++) {
			if (u1[j] == true && A[j] == 1 && R[j] == 1) { arezou = true; break; }
			if (u1[j] == true && A[j] == 0 && R[j] == 0) { break; }
			if (u2[j] == false) {
				if (R[j] == 1) arezou = true;
				break;
			}
		}
		ans.push_back((int)arezou);
	}
	return ans;
}

int dp[11009][5009]; vector<int> X[5009];

void init() {
	for (int i = 0; i < 1000; i++) { for (int j = 0; j < 100; j++) dp[i][j] = INF; X[i].clear(); A[i] = 0; R[i] = 0; U[i] = 0; V[i] = 0; u1[i] = false; u2[i] = false; }
}

vector<int> solve_subtask2() {
	for (int i = 0; i < M; i++) X[U[i]].push_back(V[i]);
	
	int S = min(2 * N * N, 11000);
	for (int i = 0; i < N; i++) dp[S + 1][i] = 0;
	for (int i = S; i >= 0; i--) {
		for (int j = 0; j < N; j++) {
			if (R[j] == 1) {
				int cnt = 0;
				for (int k = 0; k < X[j].size(); k++) { if (dp[i + 1][X[j][k]] == INF) cnt++; }
				dp[i][j] = 0;
				if (A[j] == 1 && cnt == (int)X[j].size()) dp[i][j] = INF;
				if (A[j] == 0 && cnt >= 1) dp[i][j] = INF;
				continue;
			}
			if (A[j] == 1) {
				dp[i][j] = INF;
				for (int k = 0; k < X[j].size(); k++) {
					if (j == X[j][k]) continue;
					dp[i][j] = min(dp[i][j], dp[i + 1][X[j][k]] + 1);
				}
				if (dp[i][j] > N) dp[i][j] = INF;
			}
			else {
				dp[i][j] = 0;
				for (int k = 0; k < X[j].size(); k++) {
					dp[i][j] = max(dp[i][j], dp[i + 1][X[j][k]] + 1);
					if (j == X[j][k]) dp[i][j] = INF;
				}
				if (dp[i][j] > N) dp[i][j] = INF;
			}
		}
	}
	
	/*cout << "--- DP Table ---" << endl;
	for (int i = 0; i <= S + 1; i++) {
		printf("#% 3d: ", i);
		for (int j = 0; j < N; j++) printf("% 2d", dp[i][j]);
		printf("\n");
	}
	printf("\n");*/
	
	vector<int>ans;
	for (int i = 0; i < N; i++) {
		if (dp[0][i] == INF) ans.push_back(0);
		else ans.push_back(1);
	}
	return ans;
}

bool used[5009][5009];

void dfs(int fir, int pos) {
	for (int i = 0; i < X[pos].size(); i++) {
		if (used[fir][X[pos][i]] == true) continue;
		used[fir][X[pos][i]] = true;
		dfs(fir, X[pos][i]);
	}
}

vector<int> solve_subtask3() {
	for (int i = 0; i < M; i++) X[U[i]].push_back(V[i]);
	for (int i = 0; i < N; i++) dfs(i, i);
	
	vector<int>ans;
	for (int i = 0; i < N; i++) {
		bool ok = false;
		for (int j = 0; j < N; j++) {
			if (used[i][j] == true && used[j][j] == true && R[j] == 1) ok = true;
		}
		ans.push_back((int)ok);
	}
	return ans;
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	init();
	N = a.size(); M = u.size(); bool s1 = true; bool s3 = true;
	for (int i = 0; i < N; i++) { A[i] = a[i]; R[i] = r[i]; if (A[i] == 0) s3 = false; }
	for (int i = 0; i < M; i++) { U[i] = u[i]; V[i] = v[i]; if (V[i] - U[i] < 0 || V[i] - U[i] >= 2) s1 = false; }
	
	if (s3 == true) return solve_subtask3();
	if (s1 == true) return solve_subtask1();
	return solve_subtask2();
}

Compilation message

train.cpp: In function 'std::vector<int> solve_subtask2()':
train.cpp:47:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int k = 0; k < X[j].size(); k++) { if (dp[i + 1][X[j][k]] == INF) cnt++; }
                     ~~^~~~~~~~~~~~~
train.cpp:55:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int k = 0; k < X[j].size(); k++) {
                     ~~^~~~~~~~~~~~~
train.cpp:63:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int k = 0; k < X[j].size(); k++) {
                     ~~^~~~~~~~~~~~~
train.cpp: In function 'void dfs(int, int)':
train.cpp:91:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < X[pos].size(); i++) {
                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5248 KB Output is correct
3 Correct 8 ms 5248 KB Output is correct
4 Correct 8 ms 5248 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 8 ms 5248 KB Output is correct
8 Correct 54 ms 25472 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 5 ms 4864 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 5 ms 4864 KB Output is correct
6 Correct 5 ms 4864 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 5 ms 4864 KB Output is correct
9 Correct 5 ms 4864 KB Output is correct
10 Correct 5 ms 4864 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 5 ms 4992 KB Output is correct
14 Correct 5 ms 4864 KB Output is correct
15 Correct 5 ms 4992 KB Output is correct
16 Correct 5 ms 4992 KB Output is correct
17 Correct 5 ms 4864 KB Output is correct
18 Correct 5 ms 4864 KB Output is correct
19 Correct 5 ms 4864 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 30628 KB Output is correct
2 Correct 464 ms 30504 KB Output is correct
3 Correct 493 ms 30592 KB Output is correct
4 Correct 1441 ms 30484 KB Output is correct
5 Correct 1097 ms 30684 KB Output is correct
6 Correct 787 ms 30548 KB Output is correct
7 Correct 672 ms 30584 KB Output is correct
8 Correct 458 ms 30708 KB Output is correct
9 Correct 448 ms 30588 KB Output is correct
10 Correct 571 ms 30444 KB Output is correct
11 Correct 473 ms 30584 KB Output is correct
12 Correct 83 ms 30072 KB Output is correct
13 Correct 1475 ms 30712 KB Output is correct
14 Correct 1448 ms 30648 KB Output is correct
15 Correct 1480 ms 30712 KB Output is correct
16 Correct 1466 ms 30872 KB Output is correct
17 Correct 1470 ms 30748 KB Output is correct
18 Correct 669 ms 30260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 863 ms 216960 KB Output is correct
2 Correct 1121 ms 217080 KB Output is correct
3 Correct 1038 ms 217060 KB Output is correct
4 Correct 1167 ms 217080 KB Output is correct
5 Correct 1347 ms 217160 KB Output is correct
6 Correct 1115 ms 217080 KB Output is correct
7 Correct 1269 ms 217080 KB Output is correct
8 Correct 1010 ms 216948 KB Output is correct
9 Correct 1310 ms 216932 KB Output is correct
10 Correct 1025 ms 217080 KB Output is correct
11 Correct 969 ms 217108 KB Output is correct
12 Correct 1039 ms 217052 KB Output is correct
13 Correct 1253 ms 217080 KB Output is correct
14 Correct 1182 ms 217036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1302 ms 216952 KB Output is correct
2 Correct 1131 ms 217260 KB Output is correct
3 Correct 1315 ms 217324 KB Output is correct
4 Correct 1208 ms 217080 KB Output is correct
5 Correct 30 ms 21880 KB Output is correct
6 Correct 671 ms 216700 KB Output is correct
7 Correct 345 ms 66948 KB Output is correct
8 Correct 372 ms 67064 KB Output is correct
9 Correct 367 ms 67156 KB Output is correct
10 Correct 112 ms 48596 KB Output is correct
11 Correct 376 ms 78752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5248 KB Output is correct
3 Correct 8 ms 5248 KB Output is correct
4 Correct 8 ms 5248 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 8 ms 5248 KB Output is correct
8 Correct 54 ms 25472 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Correct 5 ms 4864 KB Output is correct
15 Correct 5 ms 4992 KB Output is correct
16 Correct 5 ms 4864 KB Output is correct
17 Correct 5 ms 4864 KB Output is correct
18 Correct 5 ms 4992 KB Output is correct
19 Correct 5 ms 4864 KB Output is correct
20 Correct 5 ms 4864 KB Output is correct
21 Correct 5 ms 4864 KB Output is correct
22 Correct 6 ms 4992 KB Output is correct
23 Correct 6 ms 4992 KB Output is correct
24 Correct 5 ms 4992 KB Output is correct
25 Correct 5 ms 4864 KB Output is correct
26 Correct 5 ms 4992 KB Output is correct
27 Correct 5 ms 4992 KB Output is correct
28 Correct 5 ms 4864 KB Output is correct
29 Correct 5 ms 4864 KB Output is correct
30 Correct 5 ms 4864 KB Output is correct
31 Correct 6 ms 4992 KB Output is correct
32 Correct 455 ms 30628 KB Output is correct
33 Correct 464 ms 30504 KB Output is correct
34 Correct 493 ms 30592 KB Output is correct
35 Correct 1441 ms 30484 KB Output is correct
36 Correct 1097 ms 30684 KB Output is correct
37 Correct 787 ms 30548 KB Output is correct
38 Correct 672 ms 30584 KB Output is correct
39 Correct 458 ms 30708 KB Output is correct
40 Correct 448 ms 30588 KB Output is correct
41 Correct 571 ms 30444 KB Output is correct
42 Correct 473 ms 30584 KB Output is correct
43 Correct 83 ms 30072 KB Output is correct
44 Correct 1475 ms 30712 KB Output is correct
45 Correct 1448 ms 30648 KB Output is correct
46 Correct 1480 ms 30712 KB Output is correct
47 Correct 1466 ms 30872 KB Output is correct
48 Correct 1470 ms 30748 KB Output is correct
49 Correct 669 ms 30260 KB Output is correct
50 Correct 863 ms 216960 KB Output is correct
51 Correct 1121 ms 217080 KB Output is correct
52 Correct 1038 ms 217060 KB Output is correct
53 Correct 1167 ms 217080 KB Output is correct
54 Correct 1347 ms 217160 KB Output is correct
55 Correct 1115 ms 217080 KB Output is correct
56 Correct 1269 ms 217080 KB Output is correct
57 Correct 1010 ms 216948 KB Output is correct
58 Correct 1310 ms 216932 KB Output is correct
59 Correct 1025 ms 217080 KB Output is correct
60 Correct 969 ms 217108 KB Output is correct
61 Correct 1039 ms 217052 KB Output is correct
62 Correct 1253 ms 217080 KB Output is correct
63 Correct 1182 ms 217036 KB Output is correct
64 Correct 1302 ms 216952 KB Output is correct
65 Correct 1131 ms 217260 KB Output is correct
66 Correct 1315 ms 217324 KB Output is correct
67 Correct 1208 ms 217080 KB Output is correct
68 Correct 30 ms 21880 KB Output is correct
69 Correct 671 ms 216700 KB Output is correct
70 Correct 345 ms 66948 KB Output is correct
71 Correct 372 ms 67064 KB Output is correct
72 Correct 367 ms 67156 KB Output is correct
73 Correct 112 ms 48596 KB Output is correct
74 Correct 376 ms 78752 KB Output is correct
75 Incorrect 568 ms 217208 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
76 Halted 0 ms 0 KB -