結果
問題 | No.1646 Avoid Palindrome |
ユーザー | 👑 obakyan |
提出日時 | 2021-08-13 22:48:33 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 482 ms / 3,000 ms |
コード長 | 2,374 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 5,504 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-08 15:50:06 |
合計ジャッジ時間 | 13,938 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 3 ms
5,248 KB |
testcase_04 | AC | 339 ms
5,248 KB |
testcase_05 | AC | 335 ms
5,248 KB |
testcase_06 | AC | 339 ms
5,248 KB |
testcase_07 | AC | 364 ms
5,248 KB |
testcase_08 | AC | 364 ms
5,248 KB |
testcase_09 | AC | 316 ms
5,248 KB |
testcase_10 | AC | 327 ms
5,248 KB |
testcase_11 | AC | 336 ms
5,248 KB |
testcase_12 | AC | 335 ms
5,248 KB |
testcase_13 | AC | 339 ms
5,248 KB |
testcase_14 | AC | 418 ms
5,248 KB |
testcase_15 | AC | 428 ms
5,248 KB |
testcase_16 | AC | 418 ms
5,248 KB |
testcase_17 | AC | 434 ms
5,248 KB |
testcase_18 | AC | 424 ms
5,248 KB |
testcase_19 | AC | 436 ms
5,248 KB |
testcase_20 | AC | 432 ms
5,248 KB |
testcase_21 | AC | 453 ms
5,248 KB |
testcase_22 | AC | 440 ms
5,248 KB |
testcase_23 | AC | 446 ms
5,248 KB |
testcase_24 | AC | 482 ms
5,248 KB |
testcase_25 | AC | 450 ms
5,248 KB |
testcase_26 | AC | 452 ms
5,248 KB |
testcase_27 | AC | 454 ms
5,248 KB |
testcase_28 | AC | 445 ms
5,248 KB |
testcase_29 | AC | 293 ms
5,248 KB |
testcase_30 | AC | 328 ms
5,248 KB |
testcase_31 | AC | 453 ms
5,248 KB |
testcase_32 | AC | 299 ms
5,248 KB |
testcase_33 | AC | 298 ms
5,248 KB |
testcase_34 | AC | 464 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 1 ms
5,248 KB |
testcase_39 | AC | 1 ms
5,248 KB |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 1 ms
5,248 KB |
testcase_42 | AC | 1 ms
5,248 KB |
testcase_43 | AC | 292 ms
5,248 KB |
ソースコード
local mfl, mce = math.floor, math.ceil local mod = 998244353 local n = io.read("*n", "*l") local s = io.read() local t = {} for i = 1, n do t[i] = s:sub(i, i) if t[i] == "?" then t[i] = false else t[i] = t[i]:byte() - 96 end end for i = 1, n - 1 do if t[i] and t[i] == t[i + 1] then print(0) os.exit() end end for i = 1, n - 2 do if t[i] and t[i] == t[i + 2] then print(0) os.exit() end end if n == 1 then print(t[1] and 1 or 26) os.exit() end local dp1, dp2 = {}, {} if not t[1] and not t[2] then for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j dp1[v] = i == j and 0 or 1 end end elseif not t[1] then local i2 = t[2] for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j if i == i2 or j ~= i2 then dp1[v] = 0 else dp1[v] = 1 end end end elseif not t[2] then local i1 = t[1] for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j if i ~= i1 or j == i1 then dp1[v] = 0 else dp1[v] = 1 end end end else local i1 = t[1] local i2 = t[2] for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j if i ~= i1 or j ~= i2 then dp1[v] = 0 else dp1[v] = 1 end end end end for i = 3, n do local src = i % 2 == 1 and dp1 or dp2 local dst = i % 2 == 1 and dp2 or dp1 for j = 1, 676 do dst[j] = 0 end if t[i] then local z = t[i] for prvprv = 1, 26 do if prvprv ~= z then for prv = 1, 26 do if prv ~= z then local d = (prv - 1) * 26 + z dst[d] = dst[d] + src[(prvprv - 1) * 26 + prv] end end end end else local row = {} local col = {} for j = 1, 26 do row[j], col[j] = 0, 0 end local all = 0 for j = 1, 26 do for k = 1, 26 do local sz = src[(j - 1) * 26 + k] all = all + sz row[j] = row[j] + sz col[k] = col[k] + sz end end local z = t[i] for j = 1, 26 do for prv = 1, 26 do if prv ~= j then local v = col[prv] - src[(j - 1) * 26 + prv] local d = (prv - 1) * 26 + j dst[d] = v end end end end for j = 1, 676 do dst[j] = dst[j] % mod end end local tbl = n % 2 == 1 and dp2 or dp1 local ret = 0 for i = 1, 676 do ret = ret + tbl[i] end print(ret % mod) -- print(os.clock())