結果

問題 No.150 "良問"(良問とは言っていない
ユーザー knewknowlknewknowl
提出日時 2015-02-14 16:53:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 802 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 59,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 09:22:27
合計ジャッジ時間 1,175 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
using namespace std;

int differ(string s,string t){
  int cnt = 0;
  for(int i=0;i<s.length();++i) if(s[i]!=t[i]) ++cnt;
  return cnt;
}
int solve(string s){
  int tbl1[105] = {};
  int tbl2[105] = {};
  int n = s.length();
  for(int i=0;i<n;++i){
    if(i<3) tbl1[i] = 10;
    else{
      string sub = s.substr(i-3,4);
      tbl1[i] = min(tbl1[i-1],differ(sub,"good"));
    }
  }
  for(int i=n-1;i>=0;--i){
    if(i>n-7) tbl2[i] = 10;
    else{
      string sub = s.substr(i,7);
      tbl2[i] = min(tbl2[i+1],differ(sub,"problem"));
    }
  }

  int ret = n;
  for(int i=3;i<n-7;++i) ret = min(ret,tbl1[i]+tbl2[i+1]);
  return ret;
}

int main(){
  int t;
  cin >> t;
  while(t--){
    string s;
    cin >> s;
    cout << solve(s) << endl;
  }

  return 0;
}
0