結果
問題 | No.150 "良問"(良問とは言っていない |
ユーザー |
![]() |
提出日時 | 2015-02-12 23:40:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 729 ms |
コンパイル使用メモリ | 74,788 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 01:46:08 |
合計ジャッジ時間 | 1,528 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 20 |
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <set> using namespace std; string good = "good"; string problem = "problem"; int main(){ int T; cin >> T; while(T--){ string s; cin >> s; auto a = s.find(good); auto b = s.find(problem); if((a!=string::npos) && (b!=string::npos) && (a < b)){ cout << 0 << endl; continue; }else{ int ans = 1<<30; for(int i=0; i+good.size()+problem.size()<=s.size(); i++){ int cost = 0; for(int j=0; j<good.size(); j++){ if(s[i+j] != good[j]) cost++; } int cost_ = 1<<30; for(int j=i+4; j+problem.size()<=s.size(); j++){ int cost__ = 0; for(int k=0; k<problem.size(); k++){ if(s[j+k] != problem[k]) cost__++; } cost_ = min(cost_, cost__); } ans = min(ans, cost+cost_); } cout << ans << endl; } } return 0; }