답안 #600897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600897 2022-07-21T08:54:13 Z enerelt14 늑대인간 (IOI18_werewolf) C++14
49 / 100
1117 ms 30400 KB
#include "werewolf.h"
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
struct node{
    int mn, mx;
    node(){
        mn=mx=0;
    }
};
bool vis[3005], is[3005];
vector<int>adj[200005];
void dijkstra1(int s, int l){
    queue<int>pq;
    pq.push(s);
    while(!pq.empty()){
        int u=pq.front();
        pq.pop();
        vis[u]=1;
        for (int i=0;i<adj[u].size();i++){
            if (adj[u][i]<l || vis[adj[u][i]])continue;
            pq.push(adj[u][i]);
        }
        while(!pq.empty() && vis[pq.front()])pq.pop();
    }
}
void dijkstra2(int s, int r){
    queue<int>pq;
    pq.push(s);
    while(!pq.empty()){
        int u=pq.front();
        pq.pop();
        vis[u]=1;
        for (int i=0;i<adj[u].size();i++){
            if (adj[u][i]>r || vis[adj[u][i]])continue;
            pq.push(adj[u][i]);
        }
        while(!pq.empty() && vis[pq.front()])pq.pop();
    }
}
int x[200005], num[200005], pos[200005];
node tree[800005];
void build(int id, int l, int r){
    if (l==r){
        tree[id].mn=x[l];
        tree[id].mx=x[l];
        return;
    }
    int mid=(l+r)/2;
    build(id*2+1, l, mid);
    build(id*2+2, mid+1, r);
    tree[id].mn=min(tree[id*2+1].mn, tree[id*2+2].mn);
    tree[id].mx=max(tree[id*2+1].mx, tree[id*2+2].mx);
}
int querymn(int id, int l, int r, int L, int R){
    if (L>r || l>R)return INT_MAX;
    if (L<=l && r<=R)return tree[id].mn;
    int mid=(l+r)/2;
    return min(querymn(id*2+1, l, mid, L, R), querymn(id*2+2, mid+1, r, L, R));
}
int querymx(int id, int l, int r, int L, int R){
    if (L>r || l>R)return 0;
    if (L<=l && r<=R)return tree[id].mx;
    int mid=(l+r)/2;
    return max(querymx(id*2+1, l, mid, L, R), querymx(id*2+2, mid+1, r, L, R));
}
vector<int>check_validity(int N,vector<int>X,vector<int>Y,vector<int>S,vector<int>E,vector<int>L,vector<int>R){
    if (N<=3000 && X.size()<=6000 && S.size()<=3000){
        for (int i=0;i<X.size();i++){
            adj[X[i]].pb(Y[i]);
            adj[Y[i]].pb(X[i]);
        }
        int Q=S.size();
        vector<int>ans;
        for (int j=0;j<Q;j++){
            ans.pb(0);
            if (S[j]<L[j] || E[j]>R[j])continue;
            for (int i=L[j];i<N;i++)vis[i]=0;
            dijkstra1(S[j], L[j]);
            for (int i=L[j];i<=R[j];i++)is[i]=vis[i];
            for (int i=0;i<=R[j];i++)vis[i]=0;
            dijkstra2(E[j], R[j]);
            for (int i=L[j];i<=R[j];i++){
                if (vis[i] && is[i]){
                    ans[j]=1;
                    break;
                }
            }
        }
        return ans;
    }
    for (int i=0;i<X.size();i++){
        adj[X[i]].pb(Y[i]);
        adj[Y[i]].pb(X[i]);
    }
    x[0]=N;
    for (int i=0;i<N;i++){
        if (adj[i].size()==1){
            x[1]=i;
            break;
        }
    }
    for (int i=2;i<=N;i++){
        if (adj[x[i-1]][0]==x[i-2])x[i]=adj[x[i-1]][1];
        else x[i]=adj[x[i-1]][0];
    }
    for (int i=1;i<=N;i++)pos[x[i]]=i;
    build(0, 1, N);
    vector<int>ans;
    for (int i=0;i<S.size();i++){
        ans.pb(0);
        if (S[i]<L[i] && E[i]>R[i])continue;
        if (pos[S[i]]==pos[E[i]]){
            ans[i]=1;
            continue;
        }
        if (pos[S[i]]>pos[E[i]]){
            int l=1, r=pos[S[i]];
            while(l!=r){
                int mid=(l+r)/2;
                if (querymn(0, 1, N, mid, r)>=L[i])r=mid;
                else l=mid+1;
            }
            if (l<=pos[E[i]] || querymx(0, 1, N, pos[E[i]], l)<=R[i])ans[i]=1;
        }else{
            int l=pos[S[i]], r=N;
            while(l!=r){
                int mid=(l+r)/2;
                if (querymn(0, 1, N, l, mid+1)>=L[i])l=mid+1;
                else r=mid;
            }
            if (l>=pos[E[i]] || querymx(0, 1, N, l, pos[E[i]])<=R[i])ans[i]=1;
        }
    }
    return ans;
}

Compilation message

werewolf.cpp: In function 'void dijkstra1(int, int)':
werewolf.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for (int i=0;i<adj[u].size();i++){
      |                      ~^~~~~~~~~~~~~~
werewolf.cpp: In function 'void dijkstra2(int, int)':
werewolf.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int i=0;i<adj[u].size();i++){
      |                      ~^~~~~~~~~~~~~~
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for (int i=0;i<X.size();i++){
      |                      ~^~~~~~~~~
werewolf.cpp:92:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for (int i=0;i<X.size();i++){
      |                  ~^~~~~~~~~
werewolf.cpp:110:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for (int i=0;i<S.size();i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11220 KB Output is correct
2 Correct 5 ms 11220 KB Output is correct
3 Correct 6 ms 11220 KB Output is correct
4 Correct 6 ms 11220 KB Output is correct
5 Correct 6 ms 11232 KB Output is correct
6 Correct 7 ms 11284 KB Output is correct
7 Correct 6 ms 11264 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11220 KB Output is correct
2 Correct 5 ms 11220 KB Output is correct
3 Correct 6 ms 11220 KB Output is correct
4 Correct 6 ms 11220 KB Output is correct
5 Correct 6 ms 11232 KB Output is correct
6 Correct 7 ms 11284 KB Output is correct
7 Correct 6 ms 11264 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 239 ms 11536 KB Output is correct
11 Correct 141 ms 11512 KB Output is correct
12 Correct 18 ms 11476 KB Output is correct
13 Correct 258 ms 11632 KB Output is correct
14 Correct 169 ms 11524 KB Output is correct
15 Correct 311 ms 11600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1117 ms 29768 KB Output is correct
2 Correct 956 ms 29684 KB Output is correct
3 Correct 932 ms 29676 KB Output is correct
4 Correct 1014 ms 29640 KB Output is correct
5 Correct 1048 ms 29620 KB Output is correct
6 Correct 1038 ms 29708 KB Output is correct
7 Correct 1100 ms 29688 KB Output is correct
8 Correct 903 ms 29644 KB Output is correct
9 Correct 634 ms 29692 KB Output is correct
10 Correct 764 ms 29808 KB Output is correct
11 Correct 815 ms 29804 KB Output is correct
12 Correct 842 ms 29648 KB Output is correct
13 Correct 1068 ms 29716 KB Output is correct
14 Correct 1062 ms 30280 KB Output is correct
15 Correct 1040 ms 30400 KB Output is correct
16 Correct 1022 ms 30328 KB Output is correct
17 Correct 1082 ms 30204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11220 KB Output is correct
2 Correct 5 ms 11220 KB Output is correct
3 Correct 6 ms 11220 KB Output is correct
4 Correct 6 ms 11220 KB Output is correct
5 Correct 6 ms 11232 KB Output is correct
6 Correct 7 ms 11284 KB Output is correct
7 Correct 6 ms 11264 KB Output is correct
8 Correct 6 ms 11220 KB Output is correct
9 Correct 6 ms 11220 KB Output is correct
10 Correct 239 ms 11536 KB Output is correct
11 Correct 141 ms 11512 KB Output is correct
12 Correct 18 ms 11476 KB Output is correct
13 Correct 258 ms 11632 KB Output is correct
14 Correct 169 ms 11524 KB Output is correct
15 Correct 311 ms 11600 KB Output is correct
16 Correct 1117 ms 29768 KB Output is correct
17 Correct 956 ms 29684 KB Output is correct
18 Correct 932 ms 29676 KB Output is correct
19 Correct 1014 ms 29640 KB Output is correct
20 Correct 1048 ms 29620 KB Output is correct
21 Correct 1038 ms 29708 KB Output is correct
22 Correct 1100 ms 29688 KB Output is correct
23 Correct 903 ms 29644 KB Output is correct
24 Correct 634 ms 29692 KB Output is correct
25 Correct 764 ms 29808 KB Output is correct
26 Correct 815 ms 29804 KB Output is correct
27 Correct 842 ms 29648 KB Output is correct
28 Correct 1068 ms 29716 KB Output is correct
29 Correct 1062 ms 30280 KB Output is correct
30 Correct 1040 ms 30400 KB Output is correct
31 Correct 1022 ms 30328 KB Output is correct
32 Correct 1082 ms 30204 KB Output is correct
33 Incorrect 178 ms 29764 KB Output isn't correct
34 Halted 0 ms 0 KB -