結果
問題 | No.345 最小チワワ問題 |
ユーザー |
![]() |
提出日時 | 2020-04-18 21:35:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 743 bytes |
コンパイル時間 | 1,444 ms |
コンパイル使用メモリ | 168,084 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 00:22:34 |
合計ジャッジ時間 | 2,365 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; bool is_cww (const string &s) { bool c = false, w = false, ww = false; for (const char &ch : s) { if (!c and !w and !ww) { if (ch == 'c') c = true; } else if (c and !w and !ww) { if (ch == 'w') w = true; } else if (c and w and !ww) { if (ch == 'w') ww = true; } } return (c and w and ww); } int main() { string s; cin >> s; int ans = 111; for (int i = 0; i < s.length(); i++) { for (int len = 1; i + len <= s.length(); len++) { if (is_cww(s.substr(i, len))) ans = min(ans, len); } } if (ans == 111) ans = -1; cout << ans << '\n'; return 0; }