Submission #785115

# Submission time Handle Problem Language Result Execution time Memory
785115 2023-07-17T05:28:32 Z 이동현(#10024) Ili (COI17_ili) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #define int long long
using namespace std;

const int NS = 20004;
int n, m;
int way[NS][2];
int zero[NS], inone[NS], newone[NS], chk[NS];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    string s;
    cin >> s;
    for(int i = 0; i < m; ++i){
        if(s[i] == '1') inone[n + i] = 1;
        if(s[i] == '0') zero[n + i] = 1;
    }
    for(int i = n; i < n + m; ++i){
        char c;
        cin >> c;
        int x;
        cin >> x;
        --x;
        if(c == 'c') x += n;
        way[i][0] = x;

        cin >> c;
        cin >> x;
        --x;
        if(c == 'c') x += n;
        way[i][1] = x;
    }

    for(int i = n + m - 1; i >= n; --i){
        if(zero[i]){
            zero[way[i][0]] = zero[way[i][1]] = 1;
        }
    }

    for(int i = n; i < n + m; ++i){
        if(zero[i] || inone[i]){
            continue;
        }

        memset(chk, 0, sizeof(chk));
        chk[i] = 1;
        for(int j = i; j >= n; --j){
            if(chk[j]){
                if(!zero[way[j][0]]) chk[way[j][0]] = 1;
                if(!zero[way[j][1]]) chk[way[j][1]] = 1;
            }
        }
        for(int j = n; j < n + m; ++j){
            if((chk[way[j][0]] || zero[way[j][0]]) && (chk[way[j][1]] || zero[way[j][1]])){
                chk[j] = 1;
            }
            if(inone[j] && chk[j]){
                newone[i] = 1;
                break;
            }
        }
    }

    for(int i = n; i < n + m; ++i){
        if(zero[i]) cout << "0";
        else if(inone[i] || newone[i]) cout << "1";
        else cout << "?";
    }
    cout << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -