Submission #785166

# Submission time Handle Problem Language Result Execution time Memory
785166 2023-07-17T06:37:23 Z 박영우(#10025) Ili (COI17_ili) C++17
100 / 100
631 ms 86064 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 10101
#define MAXS 22
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int adj[2][MAX];
int A[MAX];
int arr[MAX];
int cpy[MAX];
int res[MAX];
bool dp[MAX][MAX];
int N, M;
void f() {
	int i, j;
	for (i = 1; i <= M; i++) {
		res[i] = 0;
		for (j = 0; j < 2; j++) {
			if (adj[j][i] < 0) res[i] |= arr[-adj[j][i]];
			else res[i] |= res[adj[j][i]];
		}
	}
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> M;
	string s;
	cin >> s;
	int i, j;
	for (i = 1; i <= M; i++) {
		if (s[i - 1] == '?') A[i] = -1;
		else A[i] = s[i - 1] == '1';
	}
	char c;
	int a;
	for (i = 1; i <= M; i++) {
		for (j = 0; j < 2; j++) {
			cin >> c >> a;
			if (c == 'x') a *= -1;
			adj[j][i] = a;
		}
	}
	for (i = 1; i <= M; i++) {
		for (j = 0; j < 2; j++) {
			if (adj[j][i] < 0) dp[i][-adj[j][i]] = 1;
			else { for (int k = 1; k <= N; k++) dp[i][k] |= dp[adj[j][i]][k]; }
		}
	}
	for (i = 1; i <= N; i++) arr[i] = cpy[i] = 1;
	for (i = 1; i <= M; i++) if (!A[i]) {
		for (j = 1; j <= N; j++) if (dp[i][j]) arr[j] = cpy[j] = 0;
	}
	f();
	for (i = 1; i <= M; i++) if (!res[i]) A[i] = 0;
	for (i = 1; i <= M; i++) if (!~A[i]) {
		for (j = 1; j <= N; j++) arr[j] = cpy[j];
		for (j = 1; j <= N; j++) if (dp[i][j]) arr[j] = 0;
		f();
		for (j = 1; j <= M; j++) if (A[j] == 1 && !res[j]) A[i] = 1;
	}
	for (i = 1; i <= M; i++) {
		if (!~A[i]) cout << '?';
		else cout << A[i];
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 372 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 372 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 1864 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 3 ms 2132 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 2 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 372 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 2260 KB Output is correct
9 Correct 2 ms 1864 KB Output is correct
10 Correct 2 ms 2260 KB Output is correct
11 Correct 2 ms 2260 KB Output is correct
12 Correct 3 ms 2132 KB Output is correct
13 Correct 2 ms 2260 KB Output is correct
14 Correct 2 ms 2380 KB Output is correct
15 Correct 83 ms 27784 KB Output is correct
16 Correct 200 ms 37516 KB Output is correct
17 Correct 135 ms 39800 KB Output is correct
18 Correct 505 ms 54844 KB Output is correct
19 Correct 205 ms 42856 KB Output is correct
20 Correct 516 ms 76940 KB Output is correct
21 Correct 631 ms 86064 KB Output is correct
22 Correct 172 ms 76960 KB Output is correct
23 Correct 198 ms 80884 KB Output is correct
24 Correct 198 ms 79992 KB Output is correct
25 Correct 173 ms 41940 KB Output is correct
26 Correct 162 ms 42060 KB Output is correct
27 Correct 196 ms 42060 KB Output is correct
28 Correct 233 ms 40984 KB Output is correct
29 Correct 210 ms 41796 KB Output is correct
30 Correct 179 ms 41604 KB Output is correct
31 Correct 144 ms 50028 KB Output is correct
32 Correct 166 ms 58392 KB Output is correct