結果

問題 No.150 "良問"(良問とは言っていない
コンテスト
ユーザー 6soukiti29
提出日時 2017-09-18 12:59:56
言語 Nim
(2.2.6)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 852 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,478 ms
コンパイル使用メモリ 68,024 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-19 20:37:01
合計ジャッジ時間 3,295 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #
raw source code

import sequtils,strutils,math,algorithm

type
    item = tuple[index,cost : int]
var
    T = stdin.readline.parseInt
    s : string
    g = "good"
    p = "problem"
for t in 1..T:
    s = stdin.readline
    var
        a : item
        cnt : int
        A = newSeq[item](0)
        ans : int = int.high
    for i in 0..(s.high - 6):
        cnt = 0
        for j in 0..p.high:
            if s[i + j] != p[j]:
                cnt += 1
        a = (i, cnt)
        A.add(a)
    A = A.sortedByIt(it.cost)
    for i in 0..(s.high - 3):
        cnt = 0
        for j in 0..g.high:
            if s[i + j] != g[j]:
                cnt += 1
        var flag : bool
        for a in A:
            if a.index > i + 3:
                cnt += a.cost
                flag = true
                break
        if flag:
            ans = min(ans, cnt)
    echo ans
0