Submission #545284

#TimeUsernameProblemLanguageResultExecution timeMemory
545284TranGiaHuy1508Ili (COI17_ili)C++17
100 / 100
304 ms21864 KiB
/*
	Unknown's C++ Template (v3)
*/


// Pragmas

// #pragma GCC optimize("Ofast", "unroll-loops")
// #pragma GCC target("avx,avx2,fma,abm,bmi,bmi2,sse4.2,popcnt")


#include "bits/stdc++.h"
using namespace std;

#define int long long

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
template <class T> using maxpq = priority_queue<T>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mid ((l+r)/2)
#define fi first
#define se second

#ifdef LOCAL
	#define debug(x) cout << #x << " = " << x << "\n";
#else
	#define debug(x) ;
#endif

template <class A, class B>
ostream& operator << (ostream& out, pair<A, B> x)
{ out << "(" << x.first << ", " << x.second << ")"; return out; }

template <class T>
ostream& operator << (ostream& out, vector<T> x){
	out << "[";
	for (int i=0; i<sz(x); i++) { out << (i ? ", " : "") << x[i]; }
	out << "]"; return out;
}

const ld PI = acos(-1.0);
const int allmod[3] = {(int)1e9+7, 998244353, (int)1e9+9};
const int mod = allmod[0];
const int maxn = 1e4 + 10;
// const int maxn = 10;
const ll inf = 1e18;
const ld eps = 1e-6;
const int multitest = 0;

vi x;
vii v;
// {0, 1, 2} -> {False, True, undefined}

using Bitset = bitset<maxn>;

int n, m;

int convert(char c, int k){
	if (c == 'x') return k-1;
	else return k-1 + n;
}

#define allbit(_, x) for (int _ = (x)._Find_first(); _ < sz((x)); _ = (x)._Find_next(_))

void main_program(){
	cin >> n >> m;

	x.assign(n+m, 1);
	v.assign(m, ii());

	string s; cin >> s;

	char char1, char2;
	int k1, k2;

	for (int i = 0; i < m; i++){
		cin >> char1 >> k1 >> char2 >> k2;
		v[i] = {convert(char1, k1), convert(char2, k2)};
	}

	debug(v);

	vector<Bitset> c(n+m);

	for (int i = 0; i < n; i++){
		c[i] = Bitset();
		c[i][i] = 1;
	}

	for (int i = 0; i < m; i++){
		c[i + n] = c[v[i].fi] | c[v[i].se];
	}

	for (int i = 0; i < m; i++){
		if (s[i] == '0'){
			allbit(j, c[i + n]){
				x[j] = 0;
			}
		}
	}
	debug(x);

	for (int i = 0; i < m; i++){
		x[i + n] = x[v[i].fi] | x[v[i].se];
		if (x[i + n] == 0) s[i] = '0';
	}

	for (int i = 0; i < m; i++){
		if (s[i] != '?') continue;

		vi tmp = x;
		allbit(j, c[i + n]){
			tmp[j] = 0;
		}

		bool valid = true;
		for (int j = 0; j < m; j++){
			tmp[j + n] = tmp[v[j].fi] | tmp[v[j].se];
			if (tmp[j + n] == 0 && s[j] == '1') valid = false;
		}

		if (!valid) s[i] = '1';
	}

	cout << s;
}

void pre_main(){

}

signed main(){
	#ifdef LOCAL
		auto stime = chrono::high_resolution_clock::now();
	#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
		if (fopen("tst04042022_ailai.inp", "r")){
			freopen("tst04042022_ailai.inp", "r", stdin);
			freopen("tst04042022_ailai.out", "w", stdout);
		}
	#endif
	int t = 1; if (multitest) cin >> t;
	pre_main();
	while (t--) main_program();
	#ifdef LOCAL
		auto etime = chrono::high_resolution_clock::now();
		auto duration = chrono::duration_cast<chrono::milliseconds>(etime-stime).count();
		cout << "\n[" << duration << "ms]\n";
	#endif
}

Compilation message (stderr)

ili.cpp: In function 'int main()':
ili.cpp:149:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |    freopen("tst04042022_ailai.inp", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ili.cpp:150:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  150 |    freopen("tst04042022_ailai.out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...