結果
問題 | No.150 "良問"(良問とは言っていない |
ユーザー | tottoripaper |
提出日時 | 2015-03-03 22:17:28 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 947 bytes |
コンパイル時間 | 581 ms |
コンパイル使用メモリ | 56,520 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-19 09:23:56 |
合計ジャッジ時間 | 1,317 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 5 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 3 ms
6,944 KB |
testcase_11 | AC | 3 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 3 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 3 ms
6,940 KB |
testcase_19 | AC | 3 ms
6,944 KB |
testcase_20 | AC | 3 ms
6,940 KB |
ソースコード
#include <iostream> #include <cstdio> const int INF = 1001001001; const std::string G = "good", P = "problem"; std::string S; int L; int cost(int index, int offset, const std::string& s){ if(index+offset < 0 || index+offset+s.size() > L){return INF;} int res = 0; for(int i=0;i<s.size();i++){ if(S[index+offset+i] != s[i]){res += 1;} } return res; } int solve2(int index){ if(index+7 > L){return INF;} return cost(index, 0, P); } int solve(int index){ if(index+11 > L){return INF;} int res = INF; for(int i=index+4;i<L;i++){ res = std::min(res, cost(index, 0, G) + solve2(i)); } return res; } int main(){ int N; std::cin >> N; while(N--){ std::cin >> S; L = S.size(); int res = INF; for(int i=0;i<L;i++){ res = std::min(res, solve(i)); } std::cout << res << std::endl; } }