답안 #785121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785121 2023-07-17T05:31:37 Z 이동현(#10024) Ili (COI17_ili) C++17
100 / 100
122 ms 632 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;
            }
        }
        
        zero[i] = 1;
        for(int j = 0; j < n; ++j){
            if(chk[j]){
                zero[i] = 0;
                break;
            }
        }
        if(zero[i]) continue;

        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 13 ms 540 KB Output is correct
16 Correct 62 ms 556 KB Output is correct
17 Correct 51 ms 584 KB Output is correct
18 Correct 113 ms 608 KB Output is correct
19 Correct 45 ms 556 KB Output is correct
20 Correct 122 ms 632 KB Output is correct
21 Correct 116 ms 628 KB Output is correct
22 Correct 41 ms 564 KB Output is correct
23 Correct 60 ms 600 KB Output is correct
24 Correct 56 ms 560 KB Output is correct
25 Correct 80 ms 468 KB Output is correct
26 Correct 73 ms 568 KB Output is correct
27 Correct 94 ms 568 KB Output is correct
28 Correct 64 ms 560 KB Output is correct
29 Correct 81 ms 556 KB Output is correct
30 Correct 70 ms 560 KB Output is correct
31 Correct 80 ms 568 KB Output is correct
32 Correct 82 ms 560 KB Output is correct