답안 #58626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58626 2018-07-18T13:59:24 Z patrikpavic2 Ili (COI17_ili) C++17
49 / 100
716 ms 888 KB
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 1e4 + 500;

int n, m;
int zn[N], op1[N],op2[N], skup[N], pod[N];
char c;

void dfs(int x){
    if(skup[x]) return;
    skup[x] = 1;
    if(x < n) {
        return;
    }
    dfs(op1[x]);
    dfs(op2[x]);
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 0;i<n;i++) zn[i] = 2;
    for(int i = n;i<n + m;i++){
        scanf(" %c", &c);
        if(c == '?') zn[i] = 2;
        else zn[i] = c - '0';
    }
    for(int i = n;i<n + m;i++){
        char c1, c2;
        scanf(" %c%d %c%d", &c1, &op1[i], &c2, &op2[i]);
        op1[i]--,op2[i]--;
        if(c1 == 'c') op1[i] += n;
        if(c2 == 'c') op2[i] += n;
        if(zn[i] != 0) continue;
        memset(skup, 0 ,sizeof(skup));
        dfs(i);
        for(int j = 0;j<n;j++)
            if(skup[j])
                zn[j] = 0;

    }
    for(int i = n;i<n + m;i++){
        if(zn[i] != 2) continue;
        memset(skup, 0 ,sizeof(skup));
        zn[i] = 0;
        dfs(i);
        for(int j = 0;j<n;j++){
            if(skup[j] && zn[j] != 0)
                zn[i] = 2;
        }
    }
    for(int i = n;i<n + m;i++){
        if(zn[i] != 2) continue;
        memset(skup, 0, sizeof(skup));
        memset(pod, 0, sizeof(pod));
        dfs(i);
        for(int i = 0;i<n;i++)
            if(skup[i] || !zn[i]) pod[i] = 1;
        for(int j = n;j<n + m;j++){
            if(pod[op1[j]] && pod[op2[j]])
                pod[j] = 1;
        }
        for(int j = n;j<n + m;j++){
            if(pod[j] && zn[j] == 1) zn[i] = 1;
        }
    }for(int i = n+m-1;i>=n;i--){
        if(zn[i] != 2) continue;
        memset(skup, 0, sizeof(skup));
        memset(pod, 0, sizeof(pod));
        dfs(i);
        for(int i = 0;i<n;i++)
            if(skup[i] || !zn[i]) pod[i] = 1;
        for(int j = n;j<n + m;j++){
            if(pod[op1[j]] && pod[op2[j]])
                pod[j] = 1;
        }
        for(int j = n;j<n + m;j++){
            if(pod[j] && zn[j] == 1) zn[i] = 1;
        }
    }
    for(int i = n;i<n + m;i++){
        if(zn[i] == 2)printf("?");
        else printf("%c", '0' + zn[i]);
    }
}

Compilation message

ili.cpp: In function 'int main()':
ili.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
ili.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c", &c);
         ~~~~~^~~~~~~~~~~
ili.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c%d %c%d", &c1, &op1[i], &c2, &op2[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 7 ms 532 KB Output is correct
9 Correct 7 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 7 ms 612 KB Output is correct
12 Correct 5 ms 612 KB Output is correct
13 Correct 6 ms 664 KB Output is correct
14 Correct 9 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 7 ms 532 KB Output is correct
9 Correct 7 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 7 ms 612 KB Output is correct
12 Correct 5 ms 612 KB Output is correct
13 Correct 6 ms 664 KB Output is correct
14 Correct 9 ms 664 KB Output is correct
15 Correct 296 ms 740 KB Output is correct
16 Correct 691 ms 740 KB Output is correct
17 Correct 716 ms 888 KB Output is correct
18 Incorrect 3 ms 888 KB Output isn't correct
19 Halted 0 ms 0 KB -