답안 #785213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785213 2023-07-17T07:15:34 Z 이성호(#10023) Ili (COI17_ili) C++17
100 / 100
714 ms 99140 KB
#include <iostream>
#include <vector>
using namespace std;
int N, M, state[10005];
vector<int> input[10005];
int wire[10005];
bool visited[10005];
bool zero[10005], one[10005];
pair<int, int> ch[10005][2];
bool tmp[10005];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    fill(state, state + 10005, -1);
    cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        char c; cin >> c;
        if ('0' <= c && c <= '1') state[i] = c - '0';
    }
    for (int i = 1; i <= M; i++) {
        fill(visited, visited + 10005, false);
        for (int k = 0; k < 2; k++) {
            char c; int d; cin >> c >> d;
            if (c == 'x') {
                ch[i][k] = make_pair(0, d);
                if (!visited[d]) {
                    visited[d] = true;
                    input[i].push_back(d);
                }
            }
            else {
                ch[i][k] = make_pair(1, d);
                for (int j:input[d]) {
                    if (!visited[j]) {
                        visited[j] = true;
                        input[i].push_back(j);
                    }
                }
            }
        }
    }
    fill(wire, wire + 10005, -1);
    for (int i = 1; i <= M; i++) {
        if (state[i] == 0) {
            for (int j:input[i]) {
                wire[j] = 0;
            }
        }
    }
    for (int i = 1; i <= M; i++) {
        bool flag = false;
        for (int j:input[i]) {
            if (wire[j]) {
                flag = true;
                break;
            }
        }
        one[i] = flag;
    }
    for (int i = 1; i <= M; i++) {
        for (int j:input[i]) {
            if (wire[j] == -1) wire[j] = 1;
        }
        bool ok = true;
        for (int j = 1; j <= M; j++) {
            tmp[j] = false;
            for (int k = 0; k < 2; k++) {
                if (!ch[j][k].first) tmp[j] |= (wire[ch[j][k].second] == -1);
                else tmp[j] |= tmp[ch[j][k].second];
            }
            if (state[j] != -1) ok &= state[j] == (int)tmp[j];
        }
        zero[i] = ok;
        for (int j:input[i]) {
            if (wire[j] == 1) wire[j] = -1;
        }
    }
    for (int i = 1; i <= M; i++) {
        if (zero[i]) {
            if (one[i]) cout << "?";
            else cout << 0;
        }
        else cout << 1;
    }
    cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 616 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 616 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 128 ms 1296 KB Output is correct
16 Correct 233 ms 1128 KB Output is correct
17 Correct 367 ms 1500 KB Output is correct
18 Correct 504 ms 1456 KB Output is correct
19 Correct 157 ms 1088 KB Output is correct
20 Correct 714 ms 1196 KB Output is correct
21 Correct 677 ms 1172 KB Output is correct
22 Correct 271 ms 87576 KB Output is correct
23 Correct 310 ms 97800 KB Output is correct
24 Correct 318 ms 99140 KB Output is correct
25 Correct 202 ms 1140 KB Output is correct
26 Correct 209 ms 1128 KB Output is correct
27 Correct 199 ms 1128 KB Output is correct
28 Correct 183 ms 1120 KB Output is correct
29 Correct 187 ms 1128 KB Output is correct
30 Correct 186 ms 1132 KB Output is correct
31 Correct 249 ms 37092 KB Output is correct
32 Correct 319 ms 65212 KB Output is correct