답안 #477048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477048 2021-09-30T00:42:31 Z skittles1412 장난감 기차 (IOI17_train) C++17
15 / 100
2000 ms 229640 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...) 1412
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

vector<int> who_wins(vector<int> own,
					 vector<int> charging,
					 vector<int> us,
					 vector<int> vs) {
	int n = sz(own), m = sz(us);

	vector<int> igraph[n];
	for (int i = 0; i < m; i++) {
		igraph[vs[i]].push_back(us[i]);
	}

	int pn = n;
	n = n * (n + 1);

	auto encode = [&](int u, int d) -> int { return d * pn + u; };

	int dep[n]{};
	{
		for (auto& a : us) {
			if (charging[a]) {
				dep[encode(a, 0)]++;
			} else {
				for (int i = 0; i < pn; i++) {
					dep[encode(a, i)]++;
				}
			}
		}
	}

	bool qd[n]{};
	vector<int> q;
	auto push = [&](int u, bool f = false) -> void {
		if (!qd[u] && (f || !dep[u])) {
			qd[u] = true;
			q.push_back(u);
		}
	};
	for (int i = 0; i < pn; i++) {
		if (charging[i]) {
			push(encode(i, 0));
		} else {
			for (int j = 0; j <= pn; j++) {
				push(encode(i, j));
			}
		}
	}

	vector<int> ans(n, -1);
	while (sz(q)) {
		int cur = q.back();
		q.pop_back();
		int j = cur / pn, u = cur % pn;

		if (ans[cur] == -1) {
			ans[cur] = false;
		}
		dbg(u, j, ans[cur]);

		auto process = [&](int v, int en) -> void {
			dep[en]--;
			if (!own[v]) {
				ans[en] = false;
				push(en, true);
			} else {
				push(en);
			}
		};

		if (charging[u]) {
			assert(j == 0);
			for (auto& v : igraph[u]) {
				if (charging[v]) {
					process(v, encode(v, 0));
				} else {
					for (int j = 0; j < pn; j++) {
						process(v, encode(v, j));
					}
				}
			}
		} else {
			for (auto& v : igraph[u]) {
				if (charging[v]) {
					if (j == 1) {
						process(v, encode(v, 0));
					}
				} else if (j > 0) {
					process(v, encode(v, j - 1));
				}
			}
		}
	}

	for (auto& a : ans) {
		if (a == -1) {
			a = true;
		}
	}

	vector<int> xans(pn);
	for (int i = 0; i < pn; i++) {
		xans[i] = ans[encode(i, 0)];
		
		if (xans[i] == -1) {
			xans[i] = true;
		}
	}

	return xans;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:25:18: warning: statement has no effect [-Wunused-value]
   25 | #define dbg(...) 1412
      |                  ^~~~
train.cpp:88:3: note: in expansion of macro 'dbg'
   88 |   dbg(u, j, ans[cur]);
      |   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 884 ms 221212 KB Output is correct
2 Correct 893 ms 221108 KB Output is correct
3 Correct 874 ms 221148 KB Output is correct
4 Correct 1056 ms 221124 KB Output is correct
5 Correct 888 ms 221124 KB Output is correct
6 Correct 1002 ms 221124 KB Output is correct
7 Correct 1103 ms 221384 KB Output is correct
8 Correct 585 ms 221084 KB Output is correct
9 Correct 1014 ms 221316 KB Output is correct
10 Correct 950 ms 220996 KB Output is correct
11 Correct 1034 ms 221012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2074 ms 221592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 221248 KB Output is correct
2 Execution timed out 2081 ms 229640 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2107 ms 221512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 884 ms 221212 KB Output is correct
2 Correct 893 ms 221108 KB Output is correct
3 Correct 874 ms 221148 KB Output is correct
4 Correct 1056 ms 221124 KB Output is correct
5 Correct 888 ms 221124 KB Output is correct
6 Correct 1002 ms 221124 KB Output is correct
7 Correct 1103 ms 221384 KB Output is correct
8 Correct 585 ms 221084 KB Output is correct
9 Correct 1014 ms 221316 KB Output is correct
10 Correct 950 ms 220996 KB Output is correct
11 Correct 1034 ms 221012 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 296 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Execution timed out 2074 ms 221592 KB Time limit exceeded
33 Halted 0 ms 0 KB -