답안 #970359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970359 2024-04-26T12:12:33 Z Itamar 장난감 기차 (IOI17_train) C++14
100 / 100
1809 ms 2000 KB
#include "train.h"
#include <vector>
using namespace std;
#define ll long long
#include <vector>
#define vi vector<int>
#define pi pair<int,int>
#include <algorithm>
#define x first
#define y second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vb vector<bool>
int n, m;
const int siz = 5e3 + 1;
vi fr[siz];
vi invf[siz];
#include <queue>
void func(vi& bad, vi& A) {
	vector<bool> vis(n);
	queue<int> q;
	for (int i = 0; i < n; i++)if (bad[i])q.push(i);
	vi deg(n); for (int i = 0; i < n; i++)deg[i] = fr[i].size();
	while (!q.empty()) {
		int i = q.front();
		q.pop();
		if (vis[i])continue;
		vis[i] = 1;
		bad[i] = 1;
		for (int f : invf[i]) {
			deg[f]--;
			if (A[f] == 1) {
				if (deg[f] == fr[f].size() - 1)q.push(f);
			}
			else {
				if (deg[f] == 0)q.push(f);
			}
		}
	}
}
 
vi who_wins(vi A, vi R, vi U, vi V) {
	n = R.size(), m = U.size();
	for (int i = 0; i < m; i++) {
		fr[U[i]].push_back(V[i]);
		invf[V[i]].push_back(U[i]);
	}
	vi bad = R;
	for (int it = 0; it <= n; it++) {
		for (int i = 0; i < n; i++) {
			if (!bad[i]) {
				if (A[i]) {
					for (int j : fr[i])if (bad[j])bad[i] = 1;
				}
				else {
					bool g = 0;
					for (int j : fr[i])if (!bad[j])g = 1;
					if (g == 0)bad[i] = 1;
				}
			}
		}
	}
	for (int it = 0; it <= n; it++) {
		vi badt(n);
		for (int i = 0; i < n; i++) {
			//if (bad[i]) {
			if (A[i]) {
				bool g = 0;
				for (int j : fr[i])if (bad[j])g = 1;
				if (g == 0)badt[i] = 0;
				else badt[i] = 1;
			}
			else {
				for (int j : fr[i]) {
					if (bad[j] == 0) {
						badt[i] = 0;
						break;
					}
					if (j == fr[i].back())badt[i] = 1;
				}
			}
			//}
		}
		bad = badt;
 
		vi badtt = R; for (int i = 0; i < n; i++)if (bad[i] == 0)badtt[i] = 0;
		/*for (int it = 0; it <= n; it++) {
			for (int i = 0; i < n; i++) {
				if (!badtt[i]) {
					if (A[i]) {
						for (int j : fr[i])if (badtt[j])badtt[i] = 1;
					}
					else {
						bool g = 0;
						for (int j : fr[i])if (!badtt[j])g = 1;
						if (g == 0)badtt[i] = 1;
					}
				}
			}
		}*/
		func(badtt, A);
		for (int i = 0; i < n; i++)if (badtt[i] == 0)bad[i] = 0;
	}
	return bad;
}

Compilation message

train.cpp: In function 'void func(std::vector<int>&, std::vector<int>&)':
train.cpp:33:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if (deg[f] == fr[f].size() - 1)q.push(f);
# 결과 실행 시간 메모리 Grader output
1 Correct 761 ms 1300 KB Output is correct
2 Correct 731 ms 1304 KB Output is correct
3 Correct 751 ms 1304 KB Output is correct
4 Correct 737 ms 1300 KB Output is correct
5 Correct 710 ms 1296 KB Output is correct
6 Correct 765 ms 1368 KB Output is correct
7 Correct 293 ms 1292 KB Output is correct
8 Correct 795 ms 1296 KB Output is correct
9 Correct 808 ms 1288 KB Output is correct
10 Correct 883 ms 1364 KB Output is correct
11 Correct 913 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 660 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 856 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 329 ms 1936 KB Output is correct
2 Correct 383 ms 1780 KB Output is correct
3 Correct 426 ms 1780 KB Output is correct
4 Correct 1311 ms 1880 KB Output is correct
5 Correct 1253 ms 1872 KB Output is correct
6 Correct 393 ms 1736 KB Output is correct
7 Correct 1566 ms 1872 KB Output is correct
8 Correct 1169 ms 1876 KB Output is correct
9 Correct 489 ms 1680 KB Output is correct
10 Correct 1257 ms 1680 KB Output is correct
11 Correct 1271 ms 1660 KB Output is correct
12 Correct 559 ms 1816 KB Output is correct
13 Correct 1327 ms 1740 KB Output is correct
14 Correct 1344 ms 1740 KB Output is correct
15 Correct 1412 ms 1744 KB Output is correct
16 Correct 1389 ms 1744 KB Output is correct
17 Correct 1392 ms 1740 KB Output is correct
18 Correct 404 ms 1392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1255 ms 1536 KB Output is correct
2 Correct 1305 ms 1604 KB Output is correct
3 Correct 426 ms 1624 KB Output is correct
4 Correct 296 ms 1656 KB Output is correct
5 Correct 1345 ms 1728 KB Output is correct
6 Correct 1412 ms 1704 KB Output is correct
7 Correct 1445 ms 1692 KB Output is correct
8 Correct 392 ms 1628 KB Output is correct
9 Correct 1342 ms 1640 KB Output is correct
10 Correct 1403 ms 1748 KB Output is correct
11 Correct 1359 ms 1876 KB Output is correct
12 Correct 1500 ms 1876 KB Output is correct
13 Correct 1349 ms 1740 KB Output is correct
14 Correct 1348 ms 1640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1485 ms 1744 KB Output is correct
2 Correct 1531 ms 1876 KB Output is correct
3 Correct 1780 ms 1736 KB Output is correct
4 Correct 1734 ms 1648 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 280 ms 1248 KB Output is correct
7 Correct 56 ms 1112 KB Output is correct
8 Correct 13 ms 1368 KB Output is correct
9 Correct 49 ms 1392 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 84 ms 1188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 761 ms 1300 KB Output is correct
2 Correct 731 ms 1304 KB Output is correct
3 Correct 751 ms 1304 KB Output is correct
4 Correct 737 ms 1300 KB Output is correct
5 Correct 710 ms 1296 KB Output is correct
6 Correct 765 ms 1368 KB Output is correct
7 Correct 293 ms 1292 KB Output is correct
8 Correct 795 ms 1296 KB Output is correct
9 Correct 808 ms 1288 KB Output is correct
10 Correct 883 ms 1364 KB Output is correct
11 Correct 913 ms 1372 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 660 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 329 ms 1936 KB Output is correct
33 Correct 383 ms 1780 KB Output is correct
34 Correct 426 ms 1780 KB Output is correct
35 Correct 1311 ms 1880 KB Output is correct
36 Correct 1253 ms 1872 KB Output is correct
37 Correct 393 ms 1736 KB Output is correct
38 Correct 1566 ms 1872 KB Output is correct
39 Correct 1169 ms 1876 KB Output is correct
40 Correct 489 ms 1680 KB Output is correct
41 Correct 1257 ms 1680 KB Output is correct
42 Correct 1271 ms 1660 KB Output is correct
43 Correct 559 ms 1816 KB Output is correct
44 Correct 1327 ms 1740 KB Output is correct
45 Correct 1344 ms 1740 KB Output is correct
46 Correct 1412 ms 1744 KB Output is correct
47 Correct 1389 ms 1744 KB Output is correct
48 Correct 1392 ms 1740 KB Output is correct
49 Correct 404 ms 1392 KB Output is correct
50 Correct 1255 ms 1536 KB Output is correct
51 Correct 1305 ms 1604 KB Output is correct
52 Correct 426 ms 1624 KB Output is correct
53 Correct 296 ms 1656 KB Output is correct
54 Correct 1345 ms 1728 KB Output is correct
55 Correct 1412 ms 1704 KB Output is correct
56 Correct 1445 ms 1692 KB Output is correct
57 Correct 392 ms 1628 KB Output is correct
58 Correct 1342 ms 1640 KB Output is correct
59 Correct 1403 ms 1748 KB Output is correct
60 Correct 1359 ms 1876 KB Output is correct
61 Correct 1500 ms 1876 KB Output is correct
62 Correct 1349 ms 1740 KB Output is correct
63 Correct 1348 ms 1640 KB Output is correct
64 Correct 1485 ms 1744 KB Output is correct
65 Correct 1531 ms 1876 KB Output is correct
66 Correct 1780 ms 1736 KB Output is correct
67 Correct 1734 ms 1648 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 280 ms 1248 KB Output is correct
70 Correct 56 ms 1112 KB Output is correct
71 Correct 13 ms 1368 KB Output is correct
72 Correct 49 ms 1392 KB Output is correct
73 Correct 2 ms 860 KB Output is correct
74 Correct 84 ms 1188 KB Output is correct
75 Correct 246 ms 1744 KB Output is correct
76 Correct 341 ms 1628 KB Output is correct
77 Correct 389 ms 1772 KB Output is correct
78 Correct 381 ms 1776 KB Output is correct
79 Correct 378 ms 1772 KB Output is correct
80 Correct 1809 ms 1736 KB Output is correct
81 Correct 1193 ms 2000 KB Output is correct
82 Correct 1414 ms 1748 KB Output is correct
83 Correct 1256 ms 1944 KB Output is correct
84 Correct 1125 ms 1732 KB Output is correct
85 Correct 224 ms 1876 KB Output is correct
86 Correct 1031 ms 1876 KB Output is correct
87 Correct 341 ms 1624 KB Output is correct
88 Correct 705 ms 1732 KB Output is correct
89 Correct 1217 ms 1940 KB Output is correct
90 Correct 297 ms 1752 KB Output is correct
91 Correct 499 ms 1936 KB Output is correct
92 Correct 1089 ms 1740 KB Output is correct
93 Correct 792 ms 1744 KB Output is correct
94 Correct 665 ms 1880 KB Output is correct
95 Correct 1069 ms 1748 KB Output is correct
96 Correct 1342 ms 1904 KB Output is correct
97 Correct 679 ms 1744 KB Output is correct
98 Correct 898 ms 1624 KB Output is correct
99 Correct 731 ms 1716 KB Output is correct
100 Correct 397 ms 1392 KB Output is correct