Submission #970582

# Submission time Handle Problem Language Result Execution time Memory
970582 2024-04-26T17:58:13 Z jcelin Ili (COI17_ili) C++14
100 / 100
476 ms 1464 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;

#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 2e4 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

int ans[MAXN], n, m;
vi g[MAXN];
bool bio[MAXN], in[MAXN];

void dfs(int u){
	if(bio[u]) return;
	bio[u] = 1;
	if(u < n) return;
	for(auto &x : g[u]) dfs(x);
}

void solve(){
	cin >> n >> m;
	for(int i=0; i<n+m; i++) ans[i] = 2;
	for(int i=n; i<n+m; i++){
		char x;
		cin >> x;
		if(x == '1') ans[i] = 1;
		if(x == '0') ans[i] = 0;
	}
	
	for(int i=n; i<n+m; i++){
		for(int j=0; j<2; j++){
			char x;
			cin >> x;
			int vl;
			cin >> vl;
			vl--;
			if(x == 'c') vl += n;
			g[i].PB(vl);
		}
	}
	
	for(int i=n; i<n+m; i++) if(ans[i] == 0){
		fill(bio, bio + n + m, 0);
		dfs(i);
		for(int j=0; j<n+m; j++) if(bio[j]) ans[j] = 0;
	}
	
	for(int i=n; i<n+m; i++){
		int su = 0;
		for(auto &x : g[i]) su += ans[x];
		if(su == 0) ans[i] = 0;
	}
	
	for(int i=n; i<n+m; i++){
		if(ans[i] != 2) continue;
		fill(bio, bio + n + m, 0);
		fill(in, in + n + m, 0);
		dfs(i);
		for(int j=0; j<n; j++) if(ans[j] == 0 or bio[j]) in[j] = 1;
		for(int j=n; j<n+m; j++){
			in[j] = 1;
			for(auto &x : g[j]) in[j] &= in[x];
		}
		
		for(int j=0; j<n+m; j++) if(in[j] and ans[j] == 1) ans[i] = 1;
	}
	
	for(int i=n; i<n+m; i++){
		if(ans[i] == 2) cout << "?";
		else cout << ans[i];
	}
	cout << "\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while(tt--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 856 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 91 ms 1368 KB Output is correct
16 Correct 181 ms 1272 KB Output is correct
17 Correct 253 ms 1340 KB Output is correct
18 Correct 279 ms 1420 KB Output is correct
19 Correct 227 ms 1280 KB Output is correct
20 Correct 459 ms 1432 KB Output is correct
21 Correct 476 ms 1464 KB Output is correct
22 Correct 229 ms 1372 KB Output is correct
23 Correct 243 ms 1448 KB Output is correct
24 Correct 241 ms 1448 KB Output is correct
25 Correct 197 ms 1444 KB Output is correct
26 Correct 193 ms 1372 KB Output is correct
27 Correct 183 ms 1444 KB Output is correct
28 Correct 171 ms 1428 KB Output is correct
29 Correct 199 ms 1428 KB Output is correct
30 Correct 216 ms 1440 KB Output is correct
31 Correct 211 ms 1220 KB Output is correct
32 Correct 218 ms 1372 KB Output is correct