Submission #20176791
Source Code Expand
import sys
def find_root(uf, x):
root = uf[0]
while root[x] != x:
root[x] = root[root[x]]
x = root[x]
return x
def merge(uf, x, y):
root, size = uf
x, y = find_root(uf, x), find_root(uf, y)
if x == y:
return False
if size[x] < size[y]:
x, y = y, x
size[x] += size[y]
root[y] = root[x]
return True
def Z_inv(Z):
N = len(Z)
EQ = []
NEQ = []
if Z[0] != N:
return False
i, j = 1, 0
while i < N:
while i + j < N:
if Z[i] != j:
EQ.append((j, i + j))
j += 1
else:
NEQ.append((j, i + j))
break
if Z[i] != j:
return False
if not j:
i += 1
continue
k = 1
while i + k < N and k + Z[k] < j:
if Z[i + k] != Z[k]:
return False
k += 1
i += k
j -= k
root = list(range(N))
size = [0]*N
uf = (root, size)
for i, j in EQ:
merge(uf, i, j)
for i, j in NEQ:
if find_root(uf, i) == find_root(uf, j):
return False
return True
print('Yes'if Z_inv(list(map(int,open(0).read().split()))[:0:-1])else'No')
Submission Info
| Submission Time | |
|---|---|
| Task | D - LCP(prefix,suffix) |
| User | maspy |
| Language | Python (3.8.2) |
| Score | 1200 |
| Code Size | 1313 Byte |
| Status | AC |
| Exec Time | 543 ms |
| Memory | 110588 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 1200 / 1200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt |
| All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_example_01.txt | AC | 22 ms | 9180 KiB |
| 00_example_02.txt | AC | 20 ms | 9192 KiB |
| 00_example_03.txt | AC | 19 ms | 9308 KiB |
| 00_example_04.txt | AC | 18 ms | 9028 KiB |
| 01.txt | AC | 27 ms | 11004 KiB |
| 02.txt | AC | 36 ms | 16916 KiB |
| 03.txt | AC | 23 ms | 12160 KiB |
| 04.txt | AC | 76 ms | 38404 KiB |
| 05.txt | AC | 59 ms | 29040 KiB |
| 06.txt | AC | 73 ms | 38280 KiB |
| 07.txt | AC | 56 ms | 25964 KiB |
| 08.txt | AC | 72 ms | 38308 KiB |
| 09.txt | AC | 109 ms | 23596 KiB |
| 10.txt | AC | 311 ms | 56780 KiB |
| 11.txt | AC | 116 ms | 25968 KiB |
| 12.txt | AC | 268 ms | 55156 KiB |
| 13.txt | AC | 146 ms | 28936 KiB |
| 14.txt | AC | 291 ms | 59224 KiB |
| 15.txt | AC | 142 ms | 31284 KiB |
| 16.txt | AC | 349 ms | 63696 KiB |
| 17.txt | AC | 397 ms | 75288 KiB |
| 18.txt | AC | 390 ms | 74240 KiB |
| 19.txt | AC | 386 ms | 71520 KiB |
| 20.txt | AC | 373 ms | 70284 KiB |
| 21.txt | AC | 399 ms | 74948 KiB |
| 22.txt | AC | 387 ms | 72256 KiB |
| 23.txt | AC | 390 ms | 71360 KiB |
| 24.txt | AC | 383 ms | 74136 KiB |
| 25.txt | AC | 172 ms | 61040 KiB |
| 26.txt | AC | 120 ms | 31100 KiB |
| 27.txt | AC | 94 ms | 23364 KiB |
| 28.txt | AC | 166 ms | 57568 KiB |
| 29.txt | AC | 69 ms | 18868 KiB |
| 30.txt | AC | 179 ms | 52180 KiB |
| 31.txt | AC | 69 ms | 17452 KiB |
| 32.txt | AC | 119 ms | 39192 KiB |
| 33.txt | AC | 61 ms | 16660 KiB |
| 34.txt | AC | 57 ms | 12632 KiB |
| 35.txt | AC | 115 ms | 25924 KiB |
| 36.txt | AC | 130 ms | 43768 KiB |
| 37.txt | AC | 37 ms | 10828 KiB |
| 38.txt | AC | 145 ms | 38548 KiB |
| 39.txt | AC | 51 ms | 14140 KiB |
| 40.txt | AC | 61 ms | 13988 KiB |
| 41.txt | AC | 507 ms | 101888 KiB |
| 42.txt | AC | 496 ms | 98540 KiB |
| 43.txt | AC | 423 ms | 70532 KiB |
| 44.txt | AC | 543 ms | 110588 KiB |
| 45.txt | AC | 503 ms | 100516 KiB |
| 46.txt | AC | 507 ms | 81960 KiB |
| 47.txt | AC | 453 ms | 75700 KiB |
| 48.txt | AC | 485 ms | 100440 KiB |
| 49.txt | AC | 190 ms | 66492 KiB |
| 50.txt | AC | 215 ms | 73952 KiB |
| 51.txt | AC | 74 ms | 28640 KiB |
| 52.txt | AC | 534 ms | 110588 KiB |
| 53.txt | AC | 195 ms | 60080 KiB |
| 54.txt | AC | 177 ms | 55808 KiB |
| 55.txt | AC | 156 ms | 51912 KiB |
| 56.txt | AC | 215 ms | 75632 KiB |
| 57.txt | AC | 357 ms | 68080 KiB |
| 58.txt | AC | 354 ms | 65688 KiB |
| 59.txt | AC | 349 ms | 65740 KiB |
| 60.txt | AC | 352 ms | 65540 KiB |
| 61.txt | AC | 24 ms | 9132 KiB |
| 62.txt | AC | 17 ms | 9252 KiB |
| 63.txt | AC | 194 ms | 59828 KiB |
| 64.txt | AC | 175 ms | 55812 KiB |
| 65.txt | AC | 155 ms | 51984 KiB |
| 66.txt | AC | 216 ms | 75548 KiB |