Submission #466116

# Submission time Handle Problem Language Result Execution time Memory
466116 2021-08-18T01:58:04 Z SirCovidThe19th Ili (COI17_ili) C++17
0 / 100
1 ms 716 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);
}

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[in[i][0]] == '0' and A[in[i][0]] == '1') A[i] = '0';
    
    for (int i = n; i < n + m; i++){
        if (A[i] == '?'){
            bool ok0 = 1; vector<char> tmp = A; set0(tmp, i);
            for (int j = n; j < n + m and ok0; j++){
                char &in1 = tmp[in[j][0]], &in2 = tmp[in[j][1]], &cur = tmp[j];
                if (in1 == '0' and in2 == '0') cur = '0';
                else if (in1 == '1' or in2 == '1') cur = '1';
                if (j == i and cur == '1') ok0 = 0;
                if (A[j] != '?' and cur != A[j]) ok0 = 0;
            }
            cout<<(ok0 ? "?" : "1");
        }
        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 Incorrect 1 ms 716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 716 KB Output isn't correct
4 Halted 0 ms 0 KB -