답안 #966576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966576 2024-04-20T04:54:06 Z Cookie Ili (COI17_ili) C++14
0 / 100
2 ms 2660 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
#define ull unsigned long long
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 19972207, pr = 31;
const int mxn = 2e4 + 5, mxq = 1e5 + 5, sq = 500, mxv = 10005;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!

int n, m;
bool vis[20005];
bitset<mxv>reach[10005], one;
bool can0[mxn + 1], can1[mxn + 1];
int lson[mxn + 1], rson[mxn + 1];
vt<int>adj[mxn + 1];
int id(string s){
    if(s[0] == 'x')return(s[1] - '0');
    else return(s[1] - '0' + n);
}
void dfs(int s){
    vis[s] = 1;
    if(s > n){
        if(!vis[lson[s]])dfs(lson[s]);
        if(!vis[rson[s]])dfs(rson[s]);
    }
}
void dfsreach(int s, int root){
    if(s <= n)reach[root][s] = 1;
    else{
        dfsreach(lson[s], root);
        dfsreach(rson[s], root);
    }
}
void dfs2(int s){
    vis[s] = 1;
    for(auto i: adj[s]){
        if(!vis[i]){
            dfs2(i);
        }
    }
}
void solve(){
    cin >> n >> m;
    string s; cin >> s; s = '.' + s;
    for(int i = n + 1; i <= n + m; i++){
        string s1, s2; cin >> s1 >> s2;
        lson[i] = id(s1); rson[i] = id(s2);
        adj[lson[i]].pb(i); adj[rson[i]].pb(i);
    }
    for(int i = n + m; i >= n + 1; i--){
        if(!vis[i] && s[i - n] == '0'){
            dfs(i);
        }
        
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i])one[i] = 1;
    }
    for(int i = 1; i <= m; i++){
        dfsreach(i + n, i);
    }
    for(int i = 1; i <= m; i++){
        if((one & reach[i]).count()){
            can1[i] = 1; //can still be zero
        }
        else{
             can0[i] = 1; //certain is 0;
        }
    }
    for(int i = 1; i <= m; i++){
        if(s[i] != '?')cout << s[i];
        else if(can0[i] == 1){
            cout << 0;
        }else{
            memset(vis, 0, sizeof(vis));
            bool bad = 0;
            for(int j = 1; j <= n; j++){
                if(one[j] == 1 && !reach[i][j]){
                    dfs2(j);
                }
            }
            for(int j = 1; j <= m; j++){
                if(!vis[j + n] && s[j] == '1'){
                    bad = 1;
                    break;
                }
            }
            if(bad)cout << 1;
            else cout << '?';
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("i.inp", "r", stdin);
    //freopen("i.out", "w", stdout);
    int tt; tt = 1;
    while(tt--){
        solve();

    }
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2660 KB Output is correct
3 Incorrect 1 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2660 KB Output is correct
3 Incorrect 1 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2660 KB Output is correct
3 Incorrect 1 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -