結果
問題 |
No.345 最小チワワ問題
|
ユーザー |
|
提出日時 | 2020-04-04 22:32:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 615 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 66,980 KB |
最終ジャッジ日時 | 2025-01-09 14:08:49 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <iostream> #include <string> void solve() { std::string s; std::cin >> s; int n = s.length(); int ans = n + 1; for (int k = 0; k < n; ++k) { for (int j = 0; j < k; ++j) { for (int i = 0; i < j; ++i) { if (s[i] != 'c' || s[j] != 'w' || s[k] != 'w') continue; ans = std::min(ans, k - i + 1); } } } std::cout << (ans == n + 1 ? -1 : ans) << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }