結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー kou_kkk
提出日時 2023-08-25 12:33:00
言語 Nim
(2.2.8)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 315 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,534 ms
コンパイル使用メモリ 68,152 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-29 18:26:16
合計ジャッジ時間 4,075 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sequtils

let s = readLine stdin
var cs, ws = newSeq[int]()

for i, v in s:
  if v == 'c': cs.add i
  if v == 'w': ws.add i

if cs.len == 0:
  echo -1
  quit()

var ans = int.high

for c in cs:
  ws.keepItIf(it > c)
  if ws.len >= 2:
    ans = ans.min succ ws[1].pred c

echo if ans == int.high: -1 else: ans
0