Submission #34932

# Submission time Handle Problem Language Result Execution time Memory
34932 2017-11-17T08:16:21 Z wan2000 스파이 (JOI13_spy) C++14
0 / 100
2000 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

template<typename T> inline void read(T &x){
    x = 0; char ch;
    while(!isdigit(ch=getchar()));
    do{x=10*x+ch-'0';}while(isdigit(ch=getchar()));
}

typedef unsigned long long ll;

const int N = 2001;
const int M = 8000;

int n, m, mx;
map<int,ll> D[2][N], F[N];
vector<int> Adj[2][N];

void onBit(ll &x, int p){
    x |= (1<<p);
}

void Insert(int tp, int u, int x){
    int idx = x/64;
    int i = x%64;
    onBit(D[tp][u][idx],i);
}

void DFS(int u, int tp){
    for(int i = 0; i <= mx; i++){
        F[u][i] &= D[tp][u][i];
    }
    for(int i = 0; i < (int)Adj[tp][u].size(); i++){
        int v = Adj[tp][u][i];
        for(int j = 0; j <= mx; j++){
            D[tp][v][j] |= D[tp][u][j];
        }
        DFS(v,tp);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    read(n); read(m);
    for(int i = 1; i <= n; i++){
        int x, y;
        read(x); read(y);
        Adj[0][x].push_back(i);
        Adj[1][y].push_back(i);
    }
    for(int i = 1; i <= m; i++){
        int x, y;
        read(x); read(y);
        Insert(0,x,i);
        Insert(1,y,i);
    }
    mx = m/64+1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= mx; j++) F[i][j] = -1;
    }
    DFS(0,0);
    DFS(0,1);
    for(int i = 1; i <= n; i++){
        int res = 0;
        for(int j = 0; j <= mx; j++){
            res += __builtin_popcountll(F[i][j]);
        }
        cout<<res<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 15280 KB Execution killed because of forbidden syscall writev (20)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2000 ms 262144 KB Execution timed out
2 Halted 0 ms 0 KB -