답안 #370137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370137 2021-02-23T11:31:22 Z Nima_Naderi Ili (COI17_ili) C++14
100 / 100
1618 ms 2412 KB
///In the name of GOD
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 2e4 + 10;
ll n, m;
ll cnt[MXN];
char s[MXN], t[MXN];
vector<ll> adj[MXN], adt[MXN];
bool ok0[MXN], ok1[MXN];
bool check(){
    for(int i = n + m; i; i --){
        if(t[i] != '0') continue;
        for(auto j : adt[i]) t[j] = '0';
    }
    for(int i = 1; i <= n; i ++){
        if(t[i] != '0') t[i] = '1';
    }
    for(int i = n + 1; i <= n + m; i ++){
        ll exp = (t[adt[i][0]] == '1') || (t[adt[i][1]] == '1');
        if(t[i] != '?'){
            if(exp && t[i] == '0') return 0;
            if(!exp && t[i] == '1') return 0;
        }
        t[i] = (exp ? '1' : '0');
    }
    return 1;
}
int main(){
    //ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    scanf("%lld%lld", &n, &m);
    scanf("%s", s + n + 1);
    for(int i = 1; i <= n; i ++) s[i] = '?';
    for(int i = n + 1; i <= n + m; i ++){
        char ch; ll id;
        for(int j = 0; j < 2; j ++){
            scanf(" %c", &ch);
            scanf("%lld", &id);
            id += (ch == 'c' ? n : 0);
            adj[id].push_back(i), adt[i].push_back(id);
        }
    }
    /* Input is Ok!
    for(int i = 1; i <= n + m; i ++){
        cout << s[i] << " : ";
        for(auto X : adt[i]) cout << X << ' '; cout << '\n';
    }
    for(int i = 1; i <= n + m; i ++)
        cout << s[i];
    cout << '\n';
    */
    for(int i = n + m; i; i --){
        if(s[i] != '0') continue;
        for(auto j : adt[i]) s[j] = '0';
    }
    for(int i = 1; i <= n + m; i ++){
        if(s[i] != '1') continue;
        for(auto j : adj[i]) s[j] = '1';
    }

    for(int i = 1; i <= n; i ++) cnt[i] = (s[i] == '?');
    for(int i = n + 1; i <= n + m; i ++){
        ok0[i] = ok1[i] = 1;
        for(auto j : adt[i]) cnt[i] += cnt[j];
        if(s[i] == '0') assert(cnt[i] == 0);
        if(s[i] == '?'){
            if(cnt[i] == 0) ok1[i] = 0;
        }
    }
    /*
    memcpy(t, s, n + m + 1);
    for(int i = 1; i <= n + m; i ++)
        cout << t[i];
    cout << '\n';
    for(int i = 1; i <= n + m; i ++)
        cout << s[i];
    cout << '\n';
    return 0;
    */
    for(int i = 1; i <= n + m; i ++){
        if(s[i] != '?') continue;
        memcpy(t, s, n + m + 1);
        t[i] = '0';
        ok0[i] = check();
    }
    for(int i = n + 1; i <= n + m; i ++){
        if(s[i] == '?'){
            if(!ok0[i]) s[i] = '1';
            if(!ok1[i]) s[i] = '0';
        }
        printf("%c", s[i]);
    }
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N

Compilation message

ili.cpp: In function 'int main()':
ili.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |     scanf("%lld%lld", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
ili.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |     scanf("%s", s + n + 1);
      |     ~~~~~^~~~~~~~~~~~~~~~~
ili.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |             scanf(" %c", &ch);
      |             ~~~~~^~~~~~~~~~~~
ili.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |             scanf("%lld", &id);
      |             ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1260 KB Output is correct
7 Correct 1 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1260 KB Output is correct
7 Correct 1 ms 1260 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 2 ms 1260 KB Output is correct
10 Correct 3 ms 1260 KB Output is correct
11 Correct 3 ms 1260 KB Output is correct
12 Correct 3 ms 1260 KB Output is correct
13 Correct 3 ms 1260 KB Output is correct
14 Correct 2 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1260 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1280 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1260 KB Output is correct
7 Correct 1 ms 1260 KB Output is correct
8 Correct 2 ms 1260 KB Output is correct
9 Correct 2 ms 1260 KB Output is correct
10 Correct 3 ms 1260 KB Output is correct
11 Correct 3 ms 1260 KB Output is correct
12 Correct 3 ms 1260 KB Output is correct
13 Correct 3 ms 1260 KB Output is correct
14 Correct 2 ms 1260 KB Output is correct
15 Correct 50 ms 1860 KB Output is correct
16 Correct 412 ms 2028 KB Output is correct
17 Correct 393 ms 2156 KB Output is correct
18 Correct 564 ms 2284 KB Output is correct
19 Correct 458 ms 1900 KB Output is correct
20 Correct 1618 ms 2412 KB Output is correct
21 Correct 1540 ms 2412 KB Output is correct
22 Correct 287 ms 2412 KB Output is correct
23 Correct 325 ms 2412 KB Output is correct
24 Correct 281 ms 2412 KB Output is correct
25 Correct 340 ms 2156 KB Output is correct
26 Correct 360 ms 2156 KB Output is correct
27 Correct 353 ms 2156 KB Output is correct
28 Correct 322 ms 2156 KB Output is correct
29 Correct 334 ms 2156 KB Output is correct
30 Correct 339 ms 2156 KB Output is correct
31 Correct 215 ms 2156 KB Output is correct
32 Correct 306 ms 2284 KB Output is correct