結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-12 06:11:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 844 bytes |
| コンパイル時間 | 905 ms |
| コンパイル使用メモリ | 72,668 KB |
| 最終ジャッジ日時 | 2025-01-09 17:38:53 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
void solve() {
std::string s;
std::cin >> s;
int n = s.length();
std::vector<int> gdp(n, 0);
for (int i = 0; i + 4 <= n; ++i) {
for (int j = 0; j < 4; ++j) {
if (s[i + j] != "good"[j]) ++gdp[i];
}
}
std::vector<int> pdp(n, 0);
for (int i = 0; i + 7 <= n; ++i) {
for (int j = 0; j < 7; ++j) {
if (s[i + j] != "problem"[j]) ++pdp[i];
}
}
int ans = n;
for (int j = 0; j + 7 <= n; ++j) {
for (int i = 0; i + 4 <= j; ++i) {
ans = std::min(ans, gdp[i] + pdp[j]);
}
}
std::cout << ans << std::endl;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int q;
std::cin >> q;
while (q--) solve();
return 0;
}