結果
問題 | No.2606 Mirror Relay |
ユーザー | 👑 seekworser |
提出日時 | 2024-09-09 02:32:18 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 316 ms / 2,000 ms |
コード長 | 4,061 bytes |
コンパイル時間 | 3,744 ms |
コンパイル使用メモリ | 66,460 KB |
実行使用メモリ | 83,932 KB |
最終ジャッジ日時 | 2024-09-09 02:32:26 |
合計ジャッジ時間 | 8,036 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 3 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 3 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 4 ms
6,944 KB |
testcase_20 | AC | 4 ms
6,944 KB |
testcase_21 | AC | 3 ms
6,944 KB |
testcase_22 | AC | 3 ms
6,944 KB |
testcase_23 | AC | 3 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 3 ms
6,944 KB |
testcase_26 | AC | 3 ms
6,940 KB |
testcase_27 | AC | 4 ms
6,944 KB |
testcase_28 | AC | 3 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 25 ms
7,296 KB |
testcase_40 | AC | 24 ms
7,168 KB |
testcase_41 | AC | 24 ms
7,296 KB |
testcase_42 | AC | 24 ms
7,296 KB |
testcase_43 | AC | 24 ms
7,296 KB |
testcase_44 | AC | 24 ms
7,296 KB |
testcase_45 | AC | 25 ms
7,296 KB |
testcase_46 | AC | 25 ms
7,296 KB |
testcase_47 | AC | 25 ms
7,296 KB |
testcase_48 | AC | 24 ms
7,296 KB |
testcase_49 | AC | 76 ms
25,408 KB |
testcase_50 | AC | 90 ms
25,928 KB |
testcase_51 | AC | 93 ms
28,188 KB |
testcase_52 | AC | 70 ms
21,172 KB |
testcase_53 | AC | 97 ms
27,608 KB |
testcase_54 | AC | 82 ms
25,156 KB |
testcase_55 | AC | 143 ms
43,732 KB |
testcase_56 | AC | 78 ms
25,200 KB |
testcase_57 | AC | 74 ms
23,868 KB |
testcase_58 | AC | 103 ms
30,532 KB |
testcase_59 | AC | 26 ms
7,424 KB |
testcase_60 | AC | 25 ms
7,424 KB |
testcase_61 | AC | 25 ms
7,296 KB |
testcase_62 | AC | 25 ms
7,296 KB |
testcase_63 | AC | 26 ms
7,680 KB |
testcase_64 | AC | 25 ms
7,296 KB |
testcase_65 | AC | 26 ms
7,424 KB |
testcase_66 | AC | 25 ms
7,296 KB |
testcase_67 | AC | 25 ms
7,296 KB |
testcase_68 | AC | 25 ms
7,168 KB |
testcase_69 | AC | 316 ms
83,932 KB |
testcase_70 | AC | 2 ms
6,940 KB |
testcase_71 | AC | 1 ms
6,944 KB |
testcase_72 | AC | 1 ms
6,940 KB |
ソースコード
import macros;macro ImportExpand(s:untyped):untyped = parseStmt($s[2]) # verification-helper: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/NTL_1_E import strutils import sequtils import algorithm ImportExpand "cplib/collections/palindromic_tree.nim" <=== "when not declared CPLIB_COLLECTIONS_PALINDROMIC_TREE:\n const CPLIB_COLLECTIONS_PALINDROMIC_TREE* = 1\n import sequtils\n import algorithm\n type PalindromicTreeNode* = object\n link: seq[ref PalindromicTreeNode]\n suffix_link: ref PalindromicTreeNode\n len, count, id: int\n\n type PalindromicTree* = object\n amax: int\n nodes: seq[ref PalindromicTreeNode]\n\n proc len*(node: PalindromicTreeNode): int = node.len\n proc count*(node: PalindromicTreeNode): int = node.count\n proc id*(node: PalindromicTreeNode): int = node.id\n proc suffix_link*(node: PalindromicTreeNode): ref PalindromicTreeNode = node.suffix_link\n proc link*(node: PalindromicTreeNode): seq[ref PalindromicTreeNode] = node.link\n proc nodes*(pt: PalindromicTree): seq[ref PalindromicTreeNode] = pt.nodes\n\n proc newPalindromicTreeNode(pt: var PalindromicTree, amax, len: int): ref PalindromicTreeNode =\n result = new PalindromicTreeNode\n result[].link = newSeq[ref PalindromicTreeNode](amax)\n result[].suffix_link = nil\n result[].len = len\n result[].count = 0\n result[].id = pt.nodes.len\n pt.nodes.add(result)\n\n proc init(amax: int): PalindromicTree =\n discard result.newPalindromicTreeNode(amax, -1)\n discard result.newPalindromicTreeNode(amax, 0)\n result.amax = amax\n result.nodes[1][].suffix_link = result.nodes[0]\n\n\n proc initPalindromicTree*(a: seq[int], amax: int = -1): PalindromicTree =\n var amax = amax\n if amax < 0: amax = a.max\n result = init(amax)\n proc find_longest(pos: int, node: ref PalindromicTreeNode): ref PalindromicTreeNode =\n var ln = pos - node[].len - 1\n if ln >= 0 and a[ln] == a[pos]:\n return node\n return find_longest(pos, node[].suffix_link)\n var current_node = result.nodes[0]\n for i in 0..<a.len:\n current_node = find_longest(i, current_node)\n if current_node[].link[a[i]] == nil:\n current_node[].link[a[i]] = result.newPalindromicTreeNode(amax, current_node[].len + 2)\n if current_node == result.nodes[0]:\n current_node[].link[a[i]][].suffix_link = result.nodes[1]\n else:\n current_node[].link[a[i]][].suffix_link = find_longest(i, current_node[].suffix_link)[].link[a[i]]\n current_node = current_node[].link[a[i]]\n current_node[].count += 1\n\n proc initPalindromicTree*(s: string, c: char = 'a'): PalindromicTree =\n return initPalindromicTree(s.mapIt(int(it) - int(c)), 26)\n\n proc get_palindrome*(pt: PalindromicTree, node: ref PalindromicTreeNode): seq[int] =\n if node == pt.nodes[0] or node == pt.nodes[1]: return newSeq[int](0)\n var ans = newSeq[int](0)\n proc dfs(x: ref PalindromicTreeNode): bool =\n if x == node: return true\n for i in 0..<pt.amax:\n if x[].link[i] == nil: continue\n if dfs(x[].link[i]):\n ans.add(i)\n return true\n return false\n discard dfs(pt.nodes[0])\n discard dfs(pt.nodes[1])\n for i in ans.len..<node[].len:\n ans.add(ans[node[].len-1-i])\n return ans\n\n proc update_count*(pt: PalindromicTree) =\n for node in pt.nodes[1..<pt.nodes.len].reversed:\n node[].suffix_link[].count += node[].count\n" var s = stdin.readLine.reversed.join("") var pt = initPalindromicTree(s) pt.update_count var score = newSeqWith(pt.nodes.len, 0) for i in 1..<pt.nodes.len: var node = pt.nodes[i] score[i] = score[node[].suffix_link[].id] + node[].count * node[].len echo score.max