Submission #232347

#TimeUsernameProblemLanguageResultExecution timeMemory
232347amoo_safarIli (COI17_ili)C++14
100 / 100
439 ms1780 KiB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e4 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

int n, m, mk[N];
vector<int> G[N];

void DFS(int u){
	mk[u] = 1;
	for(auto adj : G[u]) if(!mk[adj]) DFS(adj);
}
vector<ll> V;
void DFS2(int u){
	mk[u] = 1;
	V.pb(u);
	for(auto adj : G[u]) if(!mk[adj]) DFS2(adj);	
}

int val[N];
void Calc(){
	for(int i = n + 1; i <= n + m; i++){
		val[i] = 0;
		for(auto adj : G[i]) val[i] |= val[adj];
	}
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	str s;
	cin >> s;
	
	char c;
	int id;
	for(int i = n + 1; i <= n + m; i ++){
		cin >> c >> id;
		G[i].pb((c == 'x' ? 0 : n) + id);
		cin >> c >> id;
		G[i].pb((c == 'x' ? 0 : n) + id);	
	}

	for(int i = 1; i <= m; i++){
		if(s[i - 1] == '0' && !mk[n + i]) DFS(n + i);
	}
	for(int i = 1; i <= n; i++) val[i] = 1 - mk[i];
	Calc();
	for(int i = 1; i <= m; i++){
		if(val[n + i] == 0) s[i - 1] = '0';
	}
	for(int j = 1; j <= m; j++){
		if(s[j - 1] != '?') continue;
		V.clear();
		DFS2(n + j);
		for(int i = 1; i <= n; i++) val[i] = 1 - mk[i];
		Calc();
		for(int i = 1; i <= m; i++){
			if(s[i - 1] == '1' && val[n + i] == 0) s[j - 1] = '1';
		}
		for(auto &x : V) mk[x] = 0;
	}
	cout << s << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...