結果
問題 | No.252 "良問"(良問とは言っていない (2) |
ユーザー | mkawa2 |
提出日時 | 2020-01-30 21:53:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 502 ms / 2,000 ms |
コード長 | 1,913 bytes |
コンパイル時間 | 327 ms |
コンパイル使用メモリ | 87,172 KB |
実行使用メモリ | 95,720 KB |
最終ジャッジ日時 | 2023-10-14 08:51:43 |
合計ジャッジ時間 | 4,381 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 474 ms
80,040 KB |
testcase_01 | AC | 408 ms
82,052 KB |
testcase_02 | AC | 450 ms
94,652 KB |
testcase_03 | AC | 446 ms
95,720 KB |
testcase_04 | AC | 500 ms
95,664 KB |
testcase_05 | AC | 502 ms
95,608 KB |
testcase_06 | AC | 108 ms
77,376 KB |
ソースコード
import sys sys.setrecursionlimit(10 ** 6) from bisect import * from collections import * from heapq import * int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline()[:-1] def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] def main(): inf = 10 ** 9 n = II() for _ in range(n): s = SI() n = len(s) # 各位置でのproblemとの変更回数を求める cntp = [inf] * n for i in range(n - 6): ch = 0 for c0, c1 in zip("problem", s[i:i + 7]): if c0 != c1: ch += 1 cntp[i] = ch #print(cntp) # 左から何個のproblemがあるか数えておく zero = 0 cnt_zero = [0] * n for i in range(n): if cntp[i] == 0: zero += 1 cnt_zero[i] = zero #print(cnt_zero) # ある位置から右を見たときのproblemの変更最小値 for i in range(n - 1, 0, -1): if cntp[i] < cntp[i - 1]: cntp[i - 1] = cntp[i] #print(cntp) # 各位置にgoodの先頭を持って行ったときの変更回数を求め、最小値を求める ans=inf for i in range(n - 10): ch = 0 for c0, c1 in zip("good", s[i:i + 4]): if c0 != c1: ch += 1 cur=ch+cntp[i+4]+(cnt_zero[i-7] if i>=7 else 0) if cur<ans:ans=cur print(ans) main()