結果
問題 | No.2162 Copy and Paste 2 |
ユーザー | akakimidori |
提出日時 | 2021-12-22 12:12:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,321 ms / 7,000 ms |
コード長 | 2,130 bytes |
コンパイル時間 | 1,584 ms |
コンパイル使用メモリ | 82,272 KB |
実行使用メモリ | 104,124 KB |
最終ジャッジ日時 | 2024-11-06 21:10:52 |
合計ジャッジ時間 | 21,107 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
52,828 KB |
testcase_01 | AC | 41 ms
54,244 KB |
testcase_02 | AC | 40 ms
54,236 KB |
testcase_03 | AC | 40 ms
53,948 KB |
testcase_04 | AC | 41 ms
52,872 KB |
testcase_05 | AC | 39 ms
53,192 KB |
testcase_06 | AC | 264 ms
90,152 KB |
testcase_07 | AC | 276 ms
90,020 KB |
testcase_08 | AC | 581 ms
94,852 KB |
testcase_09 | AC | 570 ms
90,404 KB |
testcase_10 | AC | 574 ms
89,884 KB |
testcase_11 | AC | 722 ms
92,624 KB |
testcase_12 | AC | 745 ms
91,372 KB |
testcase_13 | AC | 1,010 ms
94,980 KB |
testcase_14 | AC | 617 ms
91,264 KB |
testcase_15 | AC | 644 ms
90,452 KB |
testcase_16 | AC | 662 ms
91,168 KB |
testcase_17 | AC | 1,002 ms
95,712 KB |
testcase_18 | AC | 1,207 ms
94,648 KB |
testcase_19 | AC | 1,175 ms
95,444 KB |
testcase_20 | AC | 1,126 ms
96,252 KB |
testcase_21 | AC | 673 ms
95,280 KB |
testcase_22 | AC | 695 ms
94,904 KB |
testcase_23 | AC | 165 ms
88,860 KB |
testcase_24 | AC | 1,321 ms
103,740 KB |
testcase_25 | AC | 1,310 ms
104,124 KB |
testcase_26 | AC | 1,246 ms
96,752 KB |
testcase_27 | AC | 1,317 ms
103,716 KB |
testcase_28 | AC | 1,208 ms
97,180 KB |
ソースコード
# https://yukicoder.me/submissions/692361 # これをベースに書き換え # ACL-for-python by shakayami # https://github.com/shakayami/ACL-for-python class string: def z_algorithm(s): n = len(s) if n == 0: return [] z = [0]*n i = 1 j = 0 while(i < n): z[i] = 0 if (j+z[j] <= i) else min(j+z[j]-i, z[i-j]) while((i+z[i] < n) and (s[z[i]] == s[i+z[i]])): z[i] += 1 if (j+z[j] < i+z[i]): j = i i += 1 z[0] = n return z class fenwick_tree(): n = 1 data = [0 for i in range(n)] def __init__(self, N): self.n = N self.data = [0 for i in range(N)] def add(self, p, x): assert 0 <= p < self.n, "0<=p<n,p={0},n={1}".format(p, self.n) p += 1 while(p <= self.n): self.data[p-1] += x p += p & -p def sum(self, l, r): assert (0 <= l and l <= r and r <= self.n), "0<=l<=r<=n,l={0},r={1},n={2}".format(l, r, self.n) return self.sum0(r)-self.sum0(l) def sum0(self, r): s = 0 while(r > 0): s += self.data[r-1] r -= r & -r return s def lower_bound(self, w): if w < 0: return -1 k = 1 while k < self.n: k <<= 1 x = 0 ww = w while k > 0: if x + k - 1 < self.n and self.data[x + k - 1] < ww: ww -= self.data[x + k - 1] x += k k >>= 1 return x s = input() n = len(s) z = string.z_algorithm(s) invz = [[] for i in range(n + 1)] fw = fenwick_tree(n + 1) for i in range(n): if z[i] >= 2: invz[z[i]].append(i) fw.add(i, 1) fw.add(n, 1) dp = [0 for i in range(n + 1)] for j in range(2, n): d = dp[j] dp[j + 1] = max(dp[j + 1], d) d += -1 + j - 1 pos = fw.lower_bound(fw.sum0(j) + 1) + j while pos <= n: dp[pos] = max(dp[pos], d) d += j - 1 pos = fw.lower_bound(fw.sum0(pos) + 1) + j for ii in invz[j]: fw.add(ii, -1) ans = n - dp[n] print(ans)