# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66559 | ekrem | Ili (COI17_ili) | C++98 | 7 ms | 4364 KiB |
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>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;
typedef pair < int , int > ii;
int n, m, c, b, a[N], aa[N];
char x, y;
ii g[N];
char s[N];
void hazirla(){
for(int i = n + m; i > n; i--){
if(a[i] == 0 and a[g[i].st] <= 0 and a[g[i].nd] <= 0){
a[g[i].st] = 0;
a[g[i].nd] = 0;
}
if((a[g[i].st] == 1 or a[g[i].nd] == 1) and abs(a[i]) > 0)
a[i] = 1;
if(a[g[i].st] == 0 and a[g[i].nd] == 0 and a[i] <= 0)
a[i] = 0;
}
}
bool bak(){
for(int i = n + 1; i <= n + m; i++){
if(a[i] == 0 and (a[g[i].st] == 1 or a[g[i].nd] == 1) )
return 0;
if(a[i] == 1 and (a[g[i].st] == 0 and a[g[i].nd] == 0) )
return 0;
}
return 1;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d %s",&n ,&m, s + 1);
memset(a, -1, sizeof a);
for(int i = n + 1; i <= n + m; i++){
if(s[i - n] == '1')
a[i] = 1;
if(s[i - n] == '0')
a[i] = 0;
}
for(int i = 1; i <= m; i++){
scanf(" %c%d %c %d",&x, &c, &y ,&b);
if(x == 'c')
c += n;
if(y == 'c')
b += n;
g[i + n].st = c;
g[i + n].nd = b;
// cout << i + n << " -> " << c << " , " << b << endl;
}
hazirla();
for(int i = 1; i <= n + m; i++){
// cout << a[i] << " ";
aa[i] = a[i];
}
// puts("");
for(int i = n + 1; i <= n + m; i++)
if(a[i] == -1){
a[i] = 0;
hazirla();
bool f = bak();
// cout << i << " = " << f << " ye bakiliyo\n";
for(int i = 1; i <= n + m; i++)a[i] = aa[i];
if(f == 1)
a[i] = -1;
else{
a[i] = 1;
hazirla();
for(int i = 1; i <= n + m; i++)aa[i] = a[i];
}
}
for(int i = n + 1; i <= n + m; i++)
if(a[i] >= 0)
printf("%d",a[i]);
else
printf("?");
// cout << a[i] << " ";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |