結果
問題 | No.2162 Copy and Paste 2 |
ユーザー | ygussany |
提出日時 | 2022-03-06 22:08:43 |
言語 | C (gcc 12.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,019 bytes |
コンパイル時間 | 577 ms |
コンパイル使用メモリ | 33,540 KB |
実行使用メモリ | 472,932 KB |
最終ジャッジ日時 | 2024-11-06 21:14:10 |
合計ジャッジ時間 | 14,913 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 212 ms
470,660 KB |
testcase_01 | AC | 201 ms
470,660 KB |
testcase_02 | AC | 184 ms
470,664 KB |
testcase_03 | AC | 193 ms
470,664 KB |
testcase_04 | AC | 189 ms
470,664 KB |
testcase_05 | AC | 187 ms
470,664 KB |
testcase_06 | AC | 353 ms
472,932 KB |
testcase_07 | AC | 407 ms
472,932 KB |
testcase_08 | AC | 2,078 ms
472,416 KB |
testcase_09 | AC | 1,081 ms
472,288 KB |
testcase_10 | TLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
ソースコード
#include <stdio.h> void Z_algorithm(char S[], int Z[]) { int i, j, k, l; for (l = 0; S[l] != 0; l++); Z[0] = l; for (i = 1, j = 0; i < l; i++) { for (; i + j < l && S[i+j] == S[j]; j++); Z[i] = j; if (j == 0) continue; for (k = 1; k < j && k + Z[k] < j; k++) Z[i+k] = Z[k]; i += k - 1; j -= k; } } #define HASH 5000011 const int H_Mod = HASH; typedef struct List { struct List *next, *prev; int x, y; } list; int hash_func(int x, int y) { return (((long long)x << 20) + y) % H_Mod; } #define MAX 15000000 list hash[HASH], hd[MAX + 1], *p; int main() { char S[200001]; scanf("%s", S); int i, Z[200001], Z_max[200001]; Z_algorithm(S, Z); for (i = 0; S[i] != 0; i++); Z_max[i] = 0; for (i--; i >= 0; i--) Z_max[i] = (Z_max[i+1] > Z[i])? Z_max[i+1]: Z[i]; int h, head, tail, x, y, xx, yy, d, l[200001]; for (h = 0; h < HASH; h++) hash[h].next = NULL; for (i = 0; i < MAX; i++) hd[i].prev = NULL; hd[0].x = 0; hd[0].y = 0; hd[0].next = NULL; hd[0].prev = &(hash[0]); hash[0].next = &(hd[0]); l[0] = 0; l[1] = 1; for (head = 0, tail = 1, d = 0; head != tail; head++) { x = hd[head].x; y = hd[head].y; if (head == l[d+1]) { d++; l[d+1] = tail; } if (S[x] == 0) break; xx = x + 1; yy = (Z_max[xx] >= y)? y: 0; h = hash_func(xx, yy); for (p = hash[h].next; p != NULL; p = p->next) if (p->x == xx && p->y == yy) break; if (p == NULL) { hd[tail].x = xx; hd[tail].y = yy; if (hd[tail].prev != NULL) { hd[tail].prev->next = hd[tail].next; if (hd[tail].next != NULL) hd[tail].next->prev = hd[tail].prev; } hd[tail].next = hash[h].next; hd[tail].prev = &(hash[h]); if (hash[h].next != NULL) hash[h].next->prev = &(hd[tail]); hash[h].next = &(hd[tail++]); if (tail == MAX) tail = 0; } if (Z[x] >= y) { xx = x + y; yy = (Z_max[xx] >= y)? y: 0; h = hash_func(xx, yy); for (p = hash[h].next; p != NULL; p = p->next) if (p->x == xx && p->y == yy) break; if (p == NULL) { hd[tail].x = xx; hd[tail].y = yy; if (hd[tail].prev != NULL) { hd[tail].prev->next = hd[tail].next; if (hd[tail].next != NULL) hd[tail].next->prev = hd[tail].prev; } hd[tail].next = hash[h].next; hd[tail].prev = &(hash[h]); if (hash[h].next != NULL) hash[h].next->prev = &(hd[tail]); hash[h].next = &(hd[tail++]); if (tail == MAX) tail = 0; } } if (Z_max[x] >= x) { xx = x; yy = x; h = hash_func(xx, yy); for (p = hash[h].next; p != NULL; p = p->next) if (p->x == xx && p->y == yy) break; if (p == NULL) { hd[tail].x = xx; hd[tail].y = yy; if (hd[tail].prev != NULL) { hd[tail].prev->next = hd[tail].next; if (hd[tail].next != NULL) hd[tail].next->prev = hd[tail].prev; } hd[tail].next = hash[h].next; hd[tail].prev = &(hash[h]); if (hash[h].next != NULL) hash[h].next->prev = &(hd[tail]); hash[h].next = &(hd[tail++]); if (tail == MAX) tail = 0; } } } printf("%d\n", d); fflush(stdout); return 0; }