Submission #1087

# Submission time Handle Problem Language Result Execution time Memory
1087 2013-06-24T19:27:27 Z tncks0121 백신 (KOI13_vaccine) C++
24 / 24
532 ms 24332 KB
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <memory.h> 
#include <math.h> 
#include <assert.h> 
#include <stack> 
#include <queue> 
#include <map> 
#include <set> 
#include <algorithm> 
#include <string> 
#include <functional> 
#include <vector> 
#include <deque> 
#include <utility> 
#include <bitset> 
#include <limits.h>  

using namespace std; 
typedef long long ll; 
typedef unsigned long long llu; 
const int INF = 987654321; 
const ll LINF = 1e15;  

const int N_ = 105, M_ = 1005;
const int SN_ = 250005;
const int lgSN_ = 20;

int N, K, A[M_];
int S[SN_], X[SN_], SN;

int SA[SN_], SS[SN_], Ord[lgSN_][SN_];
int L, lgL;

bool cmpS (const int &a, const int &b) {
    return S[a] < S[b];
}

bool cmpSA (const int &a, const int &b) {
    if(Ord[lgL][a] != Ord[lgL][b]) return Ord[lgL][a] < Ord[lgL][b];
    int ta = 0, tb = 0;
    if(a + L <= SN) ta = Ord[lgL][a + L];
    if(b + L <= SN) tb = Ord[lgL][b + L];
    return ta < tb;
}

int LCP (int x, int y) {
    int r = 0;
    for(int i = lgL; --i; ) {
        if(Ord[i][x+r] == Ord[i][y+r]) r |= 1<<i;
    }
    return r;
}

int chk[N_];

int main() {
    int i, j, k;
    
    scanf("%d%d", &N, &K);
    for(i = 1; i <= N; i++) {
        int mi; scanf("%d", &mi);
        for(j = 1; j <= mi; j++) scanf("%d", A+j);
        for(j = 1; j <= mi; j++) ++SN, S[SN] = A[j], X[SN] = i; S[++SN] = 0;
        for(j = mi; j >= 1; j--) ++SN, S[SN] = A[j], X[SN] = i; S[++SN] = 0;
    }
    
    for(i = 1; i <= SN; i++) SS[i] = SS[i - 1] + (S[i] == 0) ;
    for(i = 1; i <= SN; i++) Ord[0][i] = S[i], SA[i] = i;
    
    for(L = 1, lgL = 0; L <= SN * 2; L <<= 1, lgL++) {
        sort(SA + 1, SA + SN + 1, cmpSA);
        int *O = Ord[lgL + 1]; O[SA[1]] = 1;
        for(i = 2; i <= SN; i++) {
            O[SA[i]] = O[SA[i - 1]];
            if(cmpSA(SA[i - 1], SA[i])) ++O[SA[i]];
        }
    }
    
    for(i = 1; i <= SN; i = j) {
        int count = 1; if(X[SA[i]] == 0) count = 0;
        chk[X[SA[i]]] = i;
        for(j = i + 1; j <= SN; j++) {
            if(LCP(SA[j - 1], SA[j]) < K) break;
            if(chk[X[SA[j]]] != i && X[SA[j]] > 0) ++count;
            chk[X[SA[j]]] = i;
        }
        if(count == N) {
            if(SS[SA[i] + K - 1] - SS[SA[i] - 1] > 0) continue;
            puts("YES");
            return 0;
        }
    }
    
    puts("NO");
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 24332 KB Output is correct
2 Correct 0 ms 24332 KB Output is correct
3 Correct 0 ms 24332 KB Output is correct
4 Correct 0 ms 24332 KB Output is correct
5 Correct 0 ms 24332 KB Output is correct
6 Correct 0 ms 24332 KB Output is correct
7 Correct 0 ms 24332 KB Output is correct
8 Correct 0 ms 24332 KB Output is correct
9 Correct 0 ms 24332 KB Output is correct
10 Correct 0 ms 24332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 24332 KB Output is correct
2 Correct 0 ms 24332 KB Output is correct
3 Correct 0 ms 24332 KB Output is correct
4 Correct 0 ms 24332 KB Output is correct
5 Correct 0 ms 24332 KB Output is correct
6 Correct 0 ms 24332 KB Output is correct
7 Correct 0 ms 24332 KB Output is correct
8 Correct 0 ms 24332 KB Output is correct
9 Correct 0 ms 24332 KB Output is correct
10 Correct 0 ms 24332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 24332 KB Output is correct
2 Correct 1 ms 24332 KB Output is correct
3 Correct 1 ms 24332 KB Output is correct
4 Correct 3 ms 24332 KB Output is correct
5 Correct 0 ms 24332 KB Output is correct
6 Correct 1 ms 24332 KB Output is correct
7 Correct 0 ms 24332 KB Output is correct
8 Correct 6 ms 24332 KB Output is correct
9 Correct 9 ms 24332 KB Output is correct
10 Correct 5 ms 24332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 24332 KB Output is correct
2 Correct 7 ms 24332 KB Output is correct
3 Correct 7 ms 24332 KB Output is correct
4 Correct 3 ms 24332 KB Output is correct
5 Correct 4 ms 24332 KB Output is correct
6 Correct 7 ms 24332 KB Output is correct
7 Correct 8 ms 24332 KB Output is correct
8 Correct 9 ms 24332 KB Output is correct
9 Correct 7 ms 24332 KB Output is correct
10 Correct 9 ms 24332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 24332 KB Output is correct
2 Correct 71 ms 24332 KB Output is correct
3 Correct 94 ms 24332 KB Output is correct
4 Correct 502 ms 24332 KB Output is correct
5 Correct 55 ms 24332 KB Output is correct
6 Correct 78 ms 24332 KB Output is correct
7 Correct 112 ms 24332 KB Output is correct
8 Correct 298 ms 24332 KB Output is correct
9 Correct 532 ms 24332 KB Output is correct
10 Correct 277 ms 24332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 24332 KB Output is correct
2 Correct 304 ms 24332 KB Output is correct
3 Correct 399 ms 24332 KB Output is correct
4 Correct 201 ms 24332 KB Output is correct
5 Correct 383 ms 24332 KB Output is correct
6 Correct 500 ms 24332 KB Output is correct
7 Correct 499 ms 24332 KB Output is correct
8 Correct 525 ms 24332 KB Output is correct
9 Correct 476 ms 24332 KB Output is correct
10 Correct 495 ms 24332 KB Output is correct