답안 #307458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307458 2020-09-28T07:43:06 Z HynDuf Ili (COI17_ili) C++11
100 / 100
414 ms 1272 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];
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);
        else g[i].eb(n1);
        if (s2[0] == 'x') g[i].eb(m + n2);
        else g[i].eb(n2);
    }
    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, 1);
        for (int v : allx1) in[v] = 0;
        rep(j, m, n + m - 1) if (type[j] == 0) in[j] = 0;
        rep(j, 0, m - 1)
        {
            if (in[g[j][0]] || in[g[j][1]]) in[j] = 1;
            else
            {
                if (type[j] == 1)
                {
                    type[i] = 1;
                    break;
                }
                in[j] = 0;
            }
        }
    }
    rep(i, 0, m - 1) if (type[i] == -1) cout << '?';
    else cout << type[i];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 640 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 640 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 22 ms 768 KB Output is correct
16 Correct 157 ms 896 KB Output is correct
17 Correct 89 ms 896 KB Output is correct
18 Correct 233 ms 1016 KB Output is correct
19 Correct 122 ms 896 KB Output is correct
20 Correct 414 ms 1024 KB Output is correct
21 Correct 410 ms 1036 KB Output is correct
22 Correct 227 ms 1016 KB Output is correct
23 Correct 251 ms 1272 KB Output is correct
24 Correct 243 ms 1088 KB Output is correct
25 Correct 144 ms 1024 KB Output is correct
26 Correct 155 ms 1024 KB Output is correct
27 Correct 148 ms 1144 KB Output is correct
28 Correct 131 ms 1016 KB Output is correct
29 Correct 138 ms 1144 KB Output is correct
30 Correct 144 ms 1020 KB Output is correct
31 Correct 200 ms 1024 KB Output is correct
32 Correct 263 ms 1144 KB Output is correct