Submission #545628

# Submission time Handle Problem Language Result Execution time Memory
545628 2022-04-05T02:14:43 Z Monarchuwu Ili (COI17_ili) C++17
100 / 100
736 ms 1936 KB
/**
 *  Problem:    COI17_ili (Croatian Olympiad in Informatics 2017)
 *  Link:       https://oj.uz/problem/view/COI17_ili
**/
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
#define ff first
#define ss second

const int N = 1e4 + 7;
int n, m;
char c[N];
map<string, int> mp;
int g[N << 1][2];

int dp[N << 1];
void gogo(bool f = false) {
    fill(dp + 1, dp + n + 1, f ? 1 : -1);
    for (int i = 1; i <= m; ++i)
        dp[n + i] = c[i] == '?' ? -1 : c[i] - '0';

    for (int i = m + n; i > n; --i)
        if (!dp[i]) dp[g[i][0]] = dp[g[i][1]] = 0;
    for (int i = n + 1; i <= m + n; ++i) if (f || !~dp[i]) {
        if (dp[g[i][0]] == 1 || dp[g[i][1]] == 1) dp[i] = 1;
        else if (!dp[g[i][0]] && !dp[g[i][1]]) dp[i] = 0;
    }
}
void prep() {
    gogo();
    for (int i = 1; i <= m; ++i)
        c[i] = "?01"[dp[i + n] + 1];
}
void solve() {
    for (int i = 1; i <= m; ++i) if (c[i] == '?') {
        c[i] = '0'; // if c[i] == '0'
        gogo(true);

        bool f(true);
        for (int j = 1; j <= m; ++j)
            if (c[j] != '?' && dp[j + n] != c[j] - '0') {
                f = false;
                break;
            }
        c[i] = "1?"[f];
    }
    cout << (c + 1) << '\n';
}

int main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n >> m >> (c + 1);
    for (int i = 1; i <= n; ++i) mp["x" + to_string(i)] = mp.size() + 1;
    for (int i = 1; i <= m; ++i) mp["c" + to_string(i)] = mp.size() + 1;
    for (int i = 1; i <= m; ++i) {
        string s1, s2; cin >> s1 >> s2;
        g[i + n][0] = mp[s1], g[i + n][1] = mp[s2];
    }
    prep();
    solve();
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 27 ms 920 KB Output is correct
16 Correct 328 ms 1068 KB Output is correct
17 Correct 280 ms 1132 KB Output is correct
18 Correct 441 ms 1336 KB Output is correct
19 Correct 215 ms 1236 KB Output is correct
20 Correct 736 ms 1748 KB Output is correct
21 Correct 578 ms 1936 KB Output is correct
22 Correct 69 ms 1788 KB Output is correct
23 Correct 75 ms 1828 KB Output is correct
24 Correct 73 ms 1812 KB Output is correct
25 Correct 195 ms 1784 KB Output is correct
26 Correct 193 ms 1800 KB Output is correct
27 Correct 205 ms 1796 KB Output is correct
28 Correct 176 ms 1620 KB Output is correct
29 Correct 185 ms 1876 KB Output is correct
30 Correct 196 ms 1784 KB Output is correct
31 Correct 223 ms 1420 KB Output is correct
32 Correct 278 ms 1508 KB Output is correct