답안 #307451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307451 2020-09-28T07:21:29 Z HynDuf Ili (COI17_ili) C++11
100 / 100
3119 ms 2296 KB
#include <bits/stdc++.h>

#define task "I"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e4 + 2;
int n, m, type[N << 1];
bool in[N << 1];
vi g[N], gr[N << 1];
void fill0(int u)
{
    type[u] = 0;
    if (u < m) for (int v : g[u]) fill0(v);
}
vi allx1;
void canReach1(int u)
{
    if (u >= m)
    {
        if (type[u] == 1) allx1.eb(u);
        return;
    }
    for (int v : g[u]) canReach1(v);
}
int convert(const string &s)
{
    int res = 0;
    rep(i, 1, SZ(s) - 1) res = res * 10 + (s[i] - '0');
    return res - 1;
}
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> m;
    rep(i, 0, n + m) type[i] = -1;
    string s;
    cin >> s;
    rep(i, 0, m - 1) if (s[i] != '?') type[i] = s[i] - '0';
    rep(i, 0, m - 1)
    {
        string s1, s2;
        cin >> s1 >> s2;
        int n1 = convert(s1), n2 = convert(s2);
        if (s1[0] == 'x') g[i].eb(m + n1), gr[m + n1].eb(i);
        else g[i].eb(n1), gr[n1].eb(i);
        if (s2[0] == 'x') g[i].eb(m + n2), gr[m + n2].eb(i);
        else g[i].eb(n2), gr[n2].eb(i);
    }
    rep(i, 0, m - 1) if (type[i] == 0) fill0(i);
    rep(i, m, n + m - 1) if (type[i] == -1) type[i] = 1;
    rep(i, 0, m - 1) if (type[i] == -1)
    {
        allx1.clear();
        canReach1(i);
        if (allx1.empty())
        {
            type[i] = 0;
            continue;
        }
        //PR(allx1, 0, SZ(allx1) - 1);
        fill(in, in + n + m, 0);
        for (int v : allx1) in[v] = 1;
        queue<int> q;
        rep(j, m, n + m - 1) if (!in[j] && type[j] == 1) q.push(j), in[j] = 1;
        while (!q.empty())
        {
            int u = q.front();
            q.pop();
            for (int v : gr[u]) if (!in[v]) q.push(v), in[v] = 1;
        }
        rep(j, 0, m - 1) if (type[j] == 1 && !in[j])
        {
            type[i] = 1;
            break;
        }
    }
    rep(i, 0, m - 1) if (type[i] == -1) cout << '?';
    else cout << type[i];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 4 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 4 ms 1024 KB Output is correct
12 Correct 2 ms 1024 KB Output is correct
13 Correct 2 ms 1024 KB Output is correct
14 Correct 5 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 4 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 4 ms 1024 KB Output is correct
12 Correct 2 ms 1024 KB Output is correct
13 Correct 2 ms 1024 KB Output is correct
14 Correct 5 ms 1024 KB Output is correct
15 Correct 462 ms 1480 KB Output is correct
16 Correct 965 ms 1656 KB Output is correct
17 Correct 700 ms 1656 KB Output is correct
18 Correct 2863 ms 1752 KB Output is correct
19 Correct 739 ms 1536 KB Output is correct
20 Correct 2150 ms 1820 KB Output is correct
21 Correct 3119 ms 1912 KB Output is correct
22 Correct 775 ms 2040 KB Output is correct
23 Correct 850 ms 2296 KB Output is correct
24 Correct 821 ms 2040 KB Output is correct
25 Correct 597 ms 1660 KB Output is correct
26 Correct 613 ms 1656 KB Output is correct
27 Correct 616 ms 1784 KB Output is correct
28 Correct 530 ms 1656 KB Output is correct
29 Correct 597 ms 1620 KB Output is correct
30 Correct 577 ms 1656 KB Output is correct
31 Correct 471 ms 1784 KB Output is correct
32 Correct 644 ms 1784 KB Output is correct