답안 #545225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545225 2022-04-04T04:19:28 Z socpite Ili (COI17_ili) C++17
100 / 100
437 ms 25260 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

const int maxn = 1e4+5;


pair<int, int> child[maxn][2];

int n, m;

string str;
bitset<maxn> subset[maxn][2];
bitset<maxn> val[2];
bitset<maxn> orval[2];
bitset<maxn> crr;
int ans[maxn];

int main(){
    //freopen(".inp", "r", stdin);
    cin >> n >> m >> str;
    for(int i = 1; i <= m; i++){
        char c;
        cin >> c;
        if(c == 'x')child[i][0].s = 0;
        else child[i][0].s = 1;
        cin >> child[i][0].f;
        cin >> c;
        if(c == 'x')child[i][1].s = 0;
        else child[i][1].s = 1;
        cin >> child[i][1].f;
    }
    crr.set();
    for(int i = 1; i <= n; i++){
        subset[i][0].set();
        subset[i][0][i]=0;
        //for(int j = 1; j <= n; j++)cout << subset[i][0][j];
        //cout << endl;
    }
    for(int i = 1; i <= m; i++){
        subset[i][1] = subset[child[i][1].f][child[i][1].s]&subset[child[i][0].f][child[i][0].s];
        //for(int j = 1; j <= n; j++)cout << subset[i][1][j];
        //cout << endl;
        if(str[i-1] == '0')crr&=subset[i][1];
    }
    orval[0]=crr;
    //for(int i = 1; i <= n; i++)cout << crr[i];
    //cout << endl;
    for(int i = 1; i <= m; i++){
        orval[1][i] = orval[child[i][1].s][child[i][1].f]|orval[child[i][0].s][child[i][0].f];
    }
    for(int i = 1; i <= m; i++){
        if(str[i-1] =='?'){
            if(orval[1][i]){
                val[0] = crr&subset[i][1];
                bool gg = 0;
                for(int j = 1; j <= m; j++){
                    val[1][j] = val[child[j][1].s][child[j][1].f]|val[child[j][0].s][child[j][0].f];
                    if(str[j-1] != '?'){
                        //cout << val[1][j] << endl;
                        if(int(val[1][j]) != str[j-1]-'0')gg=1;
                    }
                }
                if(!gg)ans[i]=-1;
                else ans[i]=1;
            }
            else ans[i]=0;
        }
        else ans[i]=str[i-1]-'0';
        //cout << ans[i] << endl;
    }
    for(int i = 1; i <= m; i++){
        if(ans[i] == -1)cout << '?';
        else cout << ans[i];
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 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 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 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 2 ms 1492 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1364 KB Output is correct
11 Correct 3 ms 1492 KB Output is correct
12 Correct 2 ms 1364 KB Output is correct
13 Correct 2 ms 1364 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 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 2 ms 1492 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1364 KB Output is correct
11 Correct 3 ms 1492 KB Output is correct
12 Correct 2 ms 1364 KB Output is correct
13 Correct 2 ms 1364 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
15 Correct 118 ms 15208 KB Output is correct
16 Correct 192 ms 17748 KB Output is correct
17 Correct 222 ms 21204 KB Output is correct
18 Correct 431 ms 25080 KB Output is correct
19 Correct 170 ms 17880 KB Output is correct
20 Correct 402 ms 24772 KB Output is correct
21 Correct 437 ms 25060 KB Output is correct
22 Correct 205 ms 23928 KB Output is correct
23 Correct 231 ms 24908 KB Output is correct
24 Correct 218 ms 24828 KB Output is correct
25 Correct 238 ms 24884 KB Output is correct
26 Correct 214 ms 24488 KB Output is correct
27 Correct 209 ms 24576 KB Output is correct
28 Correct 250 ms 24180 KB Output is correct
29 Correct 199 ms 24228 KB Output is correct
30 Correct 202 ms 24392 KB Output is correct
31 Correct 252 ms 25260 KB Output is correct
32 Correct 250 ms 25044 KB Output is correct