답안 #600678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600678 2022-07-21T06:56:08 Z Mazaalai 늑대인간 (IOI18_werewolf) C++17
0 / 100
131 ms 19608 KB
#include "werewolf.h"
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
using namespace std;
using VI = vector <int>;
const int N = 3e3+1;
int n, m, q;
vector <int> paths[N];
int ans[N];
struct Query {
    int st, ed, l, r, id;
    // l means I can use cities x in human form (l <= x <= n)
    // r means I can use cities x in wolf form (0 <= x <= r)
};
int solve(int st, int ed, int l, int r) {
    bool vis[n], vis1[n]; 
    memset(vis, 0, sizeof(vis));
    memset(vis1, 0, sizeof(vis1));
    vis[st] = 1;
    queue <int> bfs; bfs.push(st);
    while(!bfs.empty()) {
        int x = bfs.front(); bfs.pop();
        for (auto el : paths[x]) {
            if (vis[el] || el < l) continue;
            vis[el] = 1;
            bfs.push(l);
        }
    }

    vis1[ed] = 1;
    bfs.push(ed);
    while(!bfs.empty()) {
        int x = bfs.front(); bfs.pop();
        if (vis[x]) return 1;
        for (auto el : paths[x]) {
            if (vis1[el] || el > r) continue;
            vis1[el] = 1;
            bfs.push(l);
        }
    }
    return 0;
}
VI check_validity(int _N, VI X, VI Y, VI ST, VI ED, VI L, VI R) {
    n = _N;
    m = sz(X);
    q = sz(ST);
    for (int i = 0; i < m; i++) {
        paths[X[i]].pb(Y[i]);
        paths[Y[i]].pb(X[i]);
    }
    vector <Query> queries;
    for (int i = 0; i < q; i++) 
        queries.pb({ST[i], ED[i], L[i], R[i], i});
    
    // solve for decreasing l ans increasing r
    VI res(q);
    for (int i = 0; i < n; i++) {
        // res[i] = ans[i];
        res[i] = solve(queries[i].st, queries[i].ed, queries[i].l, queries[i].r);
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 131 ms 19608 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -