/*
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
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
2 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
2 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
2 ms |
980 KB |
Output is correct |
15 |
Correct |
88 ms |
8604 KB |
Output is correct |
16 |
Correct |
150 ms |
10960 KB |
Output is correct |
17 |
Correct |
179 ms |
11804 KB |
Output is correct |
18 |
Correct |
219 ms |
14852 KB |
Output is correct |
19 |
Correct |
133 ms |
12224 KB |
Output is correct |
20 |
Correct |
304 ms |
18832 KB |
Output is correct |
21 |
Correct |
237 ms |
21864 KB |
Output is correct |
22 |
Correct |
131 ms |
19856 KB |
Output is correct |
23 |
Correct |
144 ms |
20376 KB |
Output is correct |
24 |
Correct |
152 ms |
20052 KB |
Output is correct |
25 |
Correct |
112 ms |
19624 KB |
Output is correct |
26 |
Correct |
99 ms |
19924 KB |
Output is correct |
27 |
Correct |
96 ms |
19796 KB |
Output is correct |
28 |
Correct |
91 ms |
18848 KB |
Output is correct |
29 |
Correct |
87 ms |
19484 KB |
Output is correct |
30 |
Correct |
95 ms |
19568 KB |
Output is correct |
31 |
Correct |
110 ms |
14184 KB |
Output is correct |
32 |
Correct |
147 ms |
15428 KB |
Output is correct |