Submission #250811

# Submission time Handle Problem Language Result Execution time Memory
250811 2020-07-19T08:14:52 Z NONAME Ili (COI17_ili) C++14
49 / 100
4000 ms 889864 KB
#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;

const int N = int(2e4) + 500;

int n, m;
array <int, 2> a[N];
vector <int> g[N];
bool mk[N], m0[N], m1[N];
string s;
set <int> n1, vis[N];

void dfs(int v) {
    if (mk[v])
        return;
    mk[v] = 1;
    if (v <= n)
        return;
    dfs(a[v][0]);
    dfs(a[v][1]);
}

int input() {
    string t;
    cin >> t;
    int len = int(t.size()), res = 0;
    for (int i = 1; i < len; ++i)
        (res *= 10) += (t[i] - '0');

    if (t[0] == 'c')
        return res + n;
    return res;
}

int main() {
    fast_io;

    cin >> n >> m;
    cin >> s;
    s = "*" + s;
    for (int i = n + 1; i <= n + m; ++i) {
        a[i] = {input(), input()};

        g[a[i][0]].push_back(i);
        g[a[i][1]].push_back(i);
    }

    for (int i = n + 1; i <= n + m; ++i)
        if (s[i - n] == '0')
            dfs(i);

    for (int i = 1; i <= n; ++i)
        if (!mk[i]) n1.insert(i);

    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n + m; ++j)
            mk[j] = 0;

        dfs(i + n);
        for (int j = 1; j <= n; ++j)
            if (mk[j])
                vis[i].insert(j);
    }

    for (int i = 1; i <= m; ++i) {
        if (s[i] == '0') {
            m0[i] = 1;
            continue;
        }

        if (s[i] == '1') {
            m1[i] = 1;
            continue;
        }

        for (auto j : n1)
            if (vis[i].count(j))
                m1[i] = 1;

        if (!m1[i])
            m0[i] = 1, s[i] = '0';
    }

    for (int i = 1; i <= m; ++i) {
        if (s[i] == '?') {
            m0[i] = 1;

            for (int j = 1; j <= n + m; ++j)
                mk[j] = 0;

            queue <int> q;
            for (auto j : n1)
                if (!vis[i].count(j))
                    q.push(j);

            while (!q.empty()) {
                int v = q.front();
                q.pop();
                for (auto u : g[v])
                    if (!mk[u]) {
                        mk[u] = 1;
                        q.push(u);
                    }
            }

            for (int j = 1; j <= m; ++j)
                if (s[j] == '1' && !mk[j + n])
                    m0[i] = 0;
        }

        if (m0[i] && m1[i]) cout << "?"; else
        if (m0[i]) cout << "0";
            else cout << "1";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1792 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 1 ms 1792 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 1 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1792 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 1 ms 1792 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 1 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 5 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 3 ms 1920 KB Output is correct
13 Correct 3 ms 1920 KB Output is correct
14 Correct 6 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1792 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 1 ms 1792 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 1 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 5 ms 1920 KB Output is correct
9 Correct 4 ms 1920 KB Output is correct
10 Correct 4 ms 1920 KB Output is correct
11 Correct 5 ms 1920 KB Output is correct
12 Correct 3 ms 1920 KB Output is correct
13 Correct 3 ms 1920 KB Output is correct
14 Correct 6 ms 2048 KB Output is correct
15 Correct 509 ms 6008 KB Output is correct
16 Correct 987 ms 4448 KB Output is correct
17 Correct 745 ms 7416 KB Output is correct
18 Correct 2893 ms 6780 KB Output is correct
19 Correct 822 ms 4176 KB Output is correct
20 Correct 2505 ms 4536 KB Output is correct
21 Correct 3739 ms 4480 KB Output is correct
22 Execution timed out 4099 ms 889864 KB Time limit exceeded
23 Halted 0 ms 0 KB -