結果
問題 |
No.345 最小チワワ問題
|
ユーザー |
|
提出日時 | 2017-11-07 16:31:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 743 bytes |
コンパイル時間 | 587 ms |
コンパイル使用メモリ | 68,408 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-25 12:05:29 |
合計ジャッジ時間 | 1,591 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string s; cin >> s; string tmp[100]; int t = 0; for(int i = 0; i < s.length(); i++) { if (s[i] == 'c') { int cntw = 0; for (int j = i; j < s.length(); j++) { if (s[j] == 'w') cntw++; if (cntw == 2) { tmp[t++] = s.substr(i,j - i + 1); break; } } } } int ans = 110; for (int i = 0; i < 100; i++) { // cout << tmp[i].length() << " "; t = tmp[i].length(); ans = !t ? ans : min(ans, t); } cout << (ans == 110 ? -1 : ans) << endl; return 0; }