結果

問題 No.2162 Copy and Paste 2
ユーザー 👑 ygussanyygussany
提出日時 2022-03-06 20:44:07
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,927 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 33,152 KB
実行使用メモリ 596,864 KB
最終ジャッジ日時 2024-04-24 13:03:11
合計ジャッジ時間 13,432 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 188 ms
107,392 KB
testcase_07 AC 211 ms
123,408 KB
testcase_08 AC 1,210 ms
316,800 KB
testcase_09 AC 38 ms
34,560 KB
testcase_10 AC 53 ms
47,196 KB
testcase_11 AC 84 ms
59,192 KB
testcase_12 AC 72 ms
52,224 KB
testcase_13 WA -
testcase_14 AC 200 ms
100,864 KB
testcase_15 AC 237 ms
110,592 KB
testcase_16 AC 344 ms
140,672 KB
testcase_17 AC 291 ms
110,592 KB
testcase_18 MLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	int x, y, d;
} list;

int hash_func(int x, int y)
{
	return (((long long)x << 20) + y) % H_Mod;
}

list *hash[HASH] = {}, hd[25000000], *p;

int main()
{
	char S[200001];
	scanf("%s", S);
	
	int i, Z[200001], Z_flag[200001] = {}, flag[200001];
	Z_algorithm(S, Z);
	for (i = 0; S[i] != 0; i++);
	for (i--; i >= 0; i--) {
		Z_flag[Z[i]] |= 1;
		if (Z_flag[i] != 0) flag[i] = 1;
		else flag[i] = 0;
	}
	
	int h, head, tail, x, y, d;
	hd[0].x = 0;
	hd[0].y = 0;
	hd[0].d = 0;
	hd[0].next = hash[0];
	hash[0] = &(hd[0]);
	for (head = 0, tail = 1; head < tail; head++) {
		x = hd[head].x;
		y = hd[head].y;
		d = hd[head].d;
		if (S[x] == 0) break;
		h = hash_func(x + 1, y);
		for (p = hash[h]; p != NULL; p = p->next) if (p->x == x + 1 && p->y == y) break;
		if (p == NULL) {
			hd[tail].x = x + 1;
			hd[tail].y = y;
			hd[tail].d = d + 1;
			hd[tail].next = hash[h];
			hash[h] = &(hd[tail++]);
		}
		
		if (Z[x] >= y) {
			h = hash_func(x + y, y);
			for (p = hash[h]; p != NULL; p = p->next) if (p->x == x + y && p->y == y) break;
			if (p == NULL) {
				hd[tail].x = x + y;
				hd[tail].y = y;
				hd[tail].d = d + 1;
				hd[tail].next = hash[h];
				hash[h] = &(hd[tail++]);
			}
		}
		
		if (flag[x] != 0) {
			h = hash_func(x, x);
			for (p = hash[h]; p != NULL; p = p->next) if (p->x == x && p->y == x) break;
			if (p == NULL) {
				hd[tail].x = x;
				hd[tail].y = x;
				hd[tail].d = d + 1;
				hd[tail].next = hash[h];
				hash[h] = &(hd[tail++]);
			}
		}
	}
	printf("%d\n", d);
	fflush(stdout);
	return 0;
}
0