Submission #466109

# Submission time Handle Problem Language Result Execution time Memory
466109 2021-08-18T00:42:53 Z SirCovidThe19th Ili (COI17_ili) C++17
100 / 100
1167 ms 1476 KB
#include <bits/stdc++.h>
using namespace std; 

int n, m; vector<char> A; vector<int> in[20005];

void set0(vector<char> &X, int i){
    X[i] = '0'; 
    for (auto nxt : in[i]) if (X[nxt] != '0') set0(X, nxt);
}
bool can(vector<char> &X){
    for (int i = n; i < n + m; i++){
        char &in1 = X[in[i][0]], &in2 = X[in[i][1]], &cur = X[i];
        if (in1 == '0' and in2 == '0') cur = '0';
        else if (in1 == '1' or in2 == '1') cur = '1';
        if (A[i] != '?' and cur != A[i]) return 0;
    }
    return 1;
}

int main(){
    cin >> n >> m; A.resize(n + m);

    for (int i = 0; i < n + m; i++){
        if (i < n) A[i] = '?';
        else cin >> A[i];
    }
    for (int i = n, u, v; i < n + m; i++){
        string a, b; cin >> a >> b;
        u = stoi(a.substr(1)) + (a[0] == 'c' ? n : 0);
        v = stoi(b.substr(1)) + (b[0] == 'c' ? n : 0);
        in[i].push_back(u - 1); in[i].push_back(v - 1);
    }
    for (int i = n; i < n + m; i++) if (A[i] == '0') set0(A, i);
    
    for (int i = n; i < n + m; i++){
        if (A[i] == '?'){
            vector<char> tmp0 = A, tmp1 = A; bool ok0, ok1;
            set0(tmp0, i); tmp1[i] = '1';
            A[i] = '0'; ok0 = can(tmp0);
            A[i] = '1'; ok1 = can(tmp1);
            A[i] = '?'; 
            cout<<((ok0 and ok1) ? "?" : to_string(ok1));
        }
        else cout<<A[i];
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 2 ms 792 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 772 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 2 ms 792 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 2 ms 772 KB Output is correct
14 Correct 2 ms 716 KB Output is correct
15 Correct 234 ms 1160 KB Output is correct
16 Correct 527 ms 972 KB Output is correct
17 Correct 555 ms 1476 KB Output is correct
18 Correct 1119 ms 1220 KB Output is correct
19 Correct 495 ms 1092 KB Output is correct
20 Correct 1069 ms 1228 KB Output is correct
21 Correct 1167 ms 1232 KB Output is correct
22 Correct 385 ms 1216 KB Output is correct
23 Correct 421 ms 1240 KB Output is correct
24 Correct 405 ms 1228 KB Output is correct
25 Correct 265 ms 1228 KB Output is correct
26 Correct 258 ms 1228 KB Output is correct
27 Correct 267 ms 1360 KB Output is correct
28 Correct 257 ms 1228 KB Output is correct
29 Correct 257 ms 1228 KB Output is correct
30 Correct 250 ms 1228 KB Output is correct
31 Correct 366 ms 1100 KB Output is correct
32 Correct 466 ms 1364 KB Output is correct