#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_ = 1005, M_ = 1005;
const int SN_ = 2002005;
const int lgSN_ = 21;
int N, K, A[M_];
int S[SN_], X[SN_], SN;
int SA[SN_], SS[SN_], Ord[lgSN_][SN_];
int L, lgL;
inline 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;
}
inline 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 start[SN_], lnk[SN_], val[SN_];
int main() {
int i, j, k;
scanf("%d%d", &N, &K);N*=10;
for(i = 1; i <= N; i+=10) {
int mi; scanf("%d", &mi);
for(j = 1; j <= mi; j++) scanf("%d", A+j);
for(k=0; k<10; k++){
for(j = 1; j <= mi; j++) ++SN, S[SN] = A[j], X[SN] = i+k; S[++SN] = 0;
for(j = mi; j >= 1; j--) ++SN, S[SN] = A[j], X[SN] = i+k; S[++SN] = 0;
}
}
for(i = 1; i <= SN; i++) SS[i] = SS[i - 1] + (S[i] == 0), SA[i] = i;
for(i = 1; i <= SN; i++) Ord[0][i] = S[i];
for(L = 1, lgL = 0; L <= SN; L <<= 1, lgL++) {
for(k = L; k >= 0; k -= L) {
for(i = 1; i <= SN; i++) {
int v = 0; if(SA[i] + k <= SN) v = Ord[lgL][SA[i] + k];
lnk[i] = start[v]; start[v] = i;
val[i] = SA[i];
}
int sn = SN;
i = SN; if(L == 1) i = 10000;
for(; i >= 0; i--) {
for(j = start[i]; j > 0; j = lnk[j]) {
SA[sn--] = val[j];
val[j] = 0;
}
start[i] = 0;
}
}
Ord[lgL + 1][SA[1]] = 1;
for(i = 2; i <= SN; i++) {
Ord[lgL + 1][SA[i]] = Ord[lgL + 1][SA[i - 1]];
if(cmpSA(SA[i - 1], SA[i])) ++Ord[lgL + 1][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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
219864 KB |
Output is correct |
2 |
Correct |
0 ms |
219864 KB |
Output is correct |
3 |
Correct |
0 ms |
219864 KB |
Output is correct |
4 |
Correct |
0 ms |
219864 KB |
Output is correct |
5 |
Correct |
0 ms |
219864 KB |
Output is correct |
6 |
Correct |
0 ms |
219864 KB |
Output is correct |
7 |
Correct |
0 ms |
219864 KB |
Output is correct |
8 |
Correct |
0 ms |
219864 KB |
Output is correct |
9 |
Correct |
1 ms |
219864 KB |
Output is correct |
10 |
Correct |
0 ms |
219864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
219864 KB |
Output is correct |
2 |
Correct |
1 ms |
219864 KB |
Output is correct |
3 |
Correct |
1 ms |
219864 KB |
Output is correct |
4 |
Correct |
0 ms |
219864 KB |
Output is correct |
5 |
Correct |
0 ms |
219864 KB |
Output is correct |
6 |
Correct |
1 ms |
219864 KB |
Output is correct |
7 |
Correct |
1 ms |
219864 KB |
Output is correct |
8 |
Correct |
1 ms |
219864 KB |
Output is correct |
9 |
Correct |
0 ms |
219864 KB |
Output is correct |
10 |
Correct |
2 ms |
219864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
219864 KB |
Output is correct |
2 |
Correct |
6 ms |
219864 KB |
Output is correct |
3 |
Correct |
6 ms |
219864 KB |
Output is correct |
4 |
Correct |
15 ms |
219864 KB |
Output is correct |
5 |
Correct |
3 ms |
219864 KB |
Output is correct |
6 |
Correct |
9 ms |
219864 KB |
Output is correct |
7 |
Correct |
9 ms |
219864 KB |
Output is correct |
8 |
Correct |
23 ms |
219864 KB |
Output is correct |
9 |
Correct |
47 ms |
219864 KB |
Output is correct |
10 |
Correct |
28 ms |
219864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
219864 KB |
Output is correct |
2 |
Correct |
39 ms |
219864 KB |
Output is correct |
3 |
Correct |
44 ms |
219864 KB |
Output is correct |
4 |
Correct |
20 ms |
219864 KB |
Output is correct |
5 |
Correct |
33 ms |
219864 KB |
Output is correct |
6 |
Correct |
57 ms |
219864 KB |
Output is correct |
7 |
Correct |
60 ms |
219864 KB |
Output is correct |
8 |
Correct |
46 ms |
219864 KB |
Output is correct |
9 |
Correct |
48 ms |
219864 KB |
Output is correct |
10 |
Correct |
49 ms |
219864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
385 ms |
219864 KB |
Output is correct |
2 |
Correct |
761 ms |
219864 KB |
Output is correct |
3 |
Execution timed out |
1000 ms |
219864 KB |
Program timed out |
4 |
Halted |
0 ms |
0 KB |
- |
5 |
Halted |
0 ms |
0 KB |
- |
6 |
Halted |
0 ms |
0 KB |
- |
7 |
Halted |
0 ms |
0 KB |
- |
8 |
Halted |
0 ms |
0 KB |
- |
9 |
Halted |
0 ms |
0 KB |
- |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
0 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |
3 |
Halted |
0 ms |
0 KB |
- |
4 |
Halted |
0 ms |
0 KB |
- |
5 |
Halted |
0 ms |
0 KB |
- |
6 |
Halted |
0 ms |
0 KB |
- |
7 |
Halted |
0 ms |
0 KB |
- |
8 |
Halted |
0 ms |
0 KB |
- |
9 |
Halted |
0 ms |
0 KB |
- |
10 |
Halted |
0 ms |
0 KB |
- |