結果
| 問題 |
No.345 最小チワワ問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-10 11:21:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 936 bytes |
| コンパイル時間 | 1,568 ms |
| コンパイル使用メモリ | 171,168 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-02 16:14:56 |
| 合計ジャッジ時間 | 2,674 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
/**
@file 345.cpp
@title No.345 最小チワワ問題 - yukicoder
@url https://yukicoder.me/problems/no/345
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)
int main() {
string S;
cin >> S;
int N = (int)S.size();
vector<int> c;
vector<int> w;
REP(i, N) {
if (S.substr(i, 1) == "c") {
c.push_back(i);
} else if (S.substr(i, 1) == "w") {
w.push_back(i);
}
}
int ans = 1e4;
if ((int)c.size() == 0 || (int)w.size() < 2) {
cout << "-1" << endl;
} else {
for (int i = 0; i < (int)c.size(); i++) {
for (int j = 1; j < (int)w.size(); j++) {
if (w[j - 1] - c[i] > 0 && w[j] - c[i] > 0) {
ans = w[j] - c[i] + 1 < ans ? w[j] - c[i] + 1 : ans;
}
}
}
ans = ans == 1e4 ? -1 : ans;
cout << ans << endl;
}
return 0;
}