Submission #492597

# Submission time Handle Problem Language Result Execution time Memory
492597 2021-12-08T05:26:50 Z radal Ili (COI17_ili) C++14
100 / 100
567 ms 2252 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC target("avx2,fma")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const long long int N = 2e4+20,mod = 1e9+7,inf = 1e18,sq = 400,sig = 26;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    return a+b;
}
vector<int> in[N],out[N];
int n,m;
string s;
bool fx[N];
int ans[N];
void rlx1(int v){
    if (fx[v]) return;
    ans[v] = 1;
    fx[v] = 1;
    for (int u : out[v]) rlx1(u);
    if (v > n){
        if (ans[in[v][0]] == 0) rlx1(in[v][1]);
        if (ans[in[v][1]] == 0) rlx1(in[v][0]);
    }
}
void rlx0(int v){
    if (fx[v]) return;
    fx[v] = 1;
    ans[v] = 0;
    for (int u : in[v]) rlx0(u);
    for (int u : out[v]){
        if (fx[u])
            continue;
        if (in[u][0] == v && fx[in[u][1]]) rlx0(u);
        else if (in[u][1] == v && fx[in[u][0]]) rlx0(u);
    }
}
bool rlx2(int v){
    if (ans[v] == 0) return 0;
    if (ans[v] == 1) return 1;
    ans[v] = 0;
    for (int u : in[v]){
        if (rlx2(u))
            return 1;
    }
    for (int u : out[v]){
        if (in[u][0] == v && ans[in[u][1]] == 0){
            if (rlx2(u)){
                return 1;
            }
        }
        else if (in[u][1] == v && ans[in[u][0]] == 0){
            if (rlx2(u)){
                return 1;
            }
        }
    }
    return 0;
}
int main(){
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(ans,-1,sizeof ans);
    cin >> n >> m >> s;
    rep(i,1,m+1){
        string x,y;
        cin >> x >> y;
        int u = 0,v = 0,g = x.size();
        rep(i,1,g){
            u *= 10;
            u += (x[i]-'0');
        }
        g = y.size();
        rep(i,1,g){
            v *= 10;
            v += (y[i]-'0');
        }
        if (x[0] == 'c') u += n;
        if (y[0] == 'c') v += n;
        in[i+n].pb(u);
        in[i+n].pb(v);
        out[u].pb(i+n);
        out[v].pb(i+n);
    }
    rep(i,0,m){
       if (s[i] == '0') rlx0(i+n+1);
        if (s[i] == '1'){
            rlx1(i+n+1);
        }
    }
    rep(i,1,n+1){
        if (ans[i] != -1) continue;
        if (rlx2(i)){
            ans[i] = 1;
            fx[i] = 1;
        }
        rep(i,1,n+m+1) if (!fx[i]) ans[i] = -1;
    }
    rep(i,0,m){
        if (ans[i+n+1] == 1) cout << 1;
        else if (ans[i+n+1] == 0) cout << 0;
        else{
            if (rlx2(i+n+1)){
                cout << 1;
                ans[1+n+i] = 1;
                fx[i+n+1] = 1;
            }
            else cout << '?';
            rep(i,1,n+1+m) if (!fx[i]) ans[i] = -1;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 2 ms 1356 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 2 ms 1344 KB Output is correct
11 Correct 2 ms 1356 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1320 KB Output is correct
14 Correct 2 ms 1344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 1 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 2 ms 1356 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 2 ms 1344 KB Output is correct
11 Correct 2 ms 1356 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1320 KB Output is correct
14 Correct 2 ms 1344 KB Output is correct
15 Correct 6 ms 1760 KB Output is correct
16 Correct 107 ms 1820 KB Output is correct
17 Correct 27 ms 1900 KB Output is correct
18 Correct 212 ms 2044 KB Output is correct
19 Correct 104 ms 1844 KB Output is correct
20 Correct 385 ms 2124 KB Output is correct
21 Correct 550 ms 2252 KB Output is correct
22 Correct 97 ms 2192 KB Output is correct
23 Correct 86 ms 2196 KB Output is correct
24 Correct 88 ms 2200 KB Output is correct
25 Correct 486 ms 1908 KB Output is correct
26 Correct 544 ms 2016 KB Output is correct
27 Correct 501 ms 1900 KB Output is correct
28 Correct 478 ms 1896 KB Output is correct
29 Correct 472 ms 1900 KB Output is correct
30 Correct 466 ms 1896 KB Output is correct
31 Correct 567 ms 1944 KB Output is correct
32 Correct 546 ms 1984 KB Output is correct