This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
_ _ _______ _ _
| | / / | _____| | | / /
| | / / | | | | / /
| |/ / | |_____ | |/ /
| |\ \ | _____| | |\ \
| | \ \ | | | | \ \
| | \ \ | |_____ | | \ \
|_| \_\ |_______| |_| \_\
*/
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair < ll, int > PLI;
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek
#define fname ""
const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 10000;
int n, m, a[N], b[N];
bitset < N > bit[N];
int main() {
//ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef krauch
freopen("input.txt", "r", stdin);
#else
//freopen(fname".in", "r", stdin);
//freopen(fname".out", "w", stdout);
#endif
scanf("%d %d\n", &n, &m);
forn(i, 1, n) b[i] = -1;
forn(i, 1, m) {
char c;
scanf("%c", &c);
if (c == '?') a[i] = -1;
else a[i] = c - '0';
}
scanf("\n");
forn(i, 1, m) {
char c;
int x1 = -1, x2 = -1, x;
scanf("%c%d ", &c, &x);
if (c == 'x') {
bit[i][x] = 1;
}
else {
bit[i] |= bit[x];
x1 = a[x];
}
scanf("%c%d\n", &c, &x);
if (c == 'x') {
bit[i][x] = 1;
}
else {
bit[i] |= bit[x];
x2 = a[x];
}
if (x1 != -1 && x2 != -1) a[i] = (x1 | x2);
if (a[i] == 0) {
forn(j, 1, n) if (bit[i][j] == 1) b[j] = 0;
}
}
forn(i, 1, m) {
int cnt = 0;
forn(j, 1, n) if (bit[i][j] == 1) cnt += (b[j] == 0);
if (cnt == bit[i].count()) a[i] = 0;
}
forn(i, 1, m) {
int cnt = 0;
forn(j, 1, n) if (bit[i][j] == 1) cnt += (b[j] == 0);
if (cnt == bit[i].count() - 1 && a[i] == 1) forn(j, 1, n) if (bit[i][j] == 1 && b[j] != 0) b[j] = 1;
}
forn(i, 1, m) {
forn(j, 1, n) {
if (bit[i][j] == 1 && b[j] == 1) a[i] = 1;
}
}
forn(l, 1, max(n, m) + 1) {
forn(i, 1, m) {
if (a[i] != -1) continue;
forn(j, 1, m) {
if (a[j] != 1) continue;
if (bit[i].count() == (bit[i] | bit[j]).count()) {
a[i] = 1;
break;
}
}
}
forn(i, 1, m) {
forn(j, 1, n) {
if (bit[i][j] == 1 && b[j] == 0) bit[i][j] = 0;
}
}
}
forn(i, 1, m) {
if (a[i] == -1) cout << "?";
else cout << a[i];
}
cout << "\n";
return 0;
}
Compilation message (stderr)
ili.cpp: In function 'int main()':
ili.cpp:94:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (cnt == bit[i].count()) a[i] = 0;
^
ili.cpp:100:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (cnt == bit[i].count() - 1 && a[i] == 1) forn(j, 1, n) if (bit[i][j] == 1 && b[j] != 0) b[j] = 1;
^
ili.cpp:57:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d\n", &n, &m);
^
ili.cpp:61:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c", &c);
^
ili.cpp:65:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("\n");
^
ili.cpp:69:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c%d ", &c, &x);
^
ili.cpp:77:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c%d\n", &c, &x);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |