結果

問題 No.150 "良問"(良問とは言っていない
ユーザー cureskolcureskol
提出日時 2020-04-07 19:25:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 643 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 165,180 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 05:51:07
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int dp[150][3];

int problem(string s){
  string t="problem";
  int res=0;
  for(int i=0;i<7;i++)res+=s[i]!=t[i];
  return res;
}
int good(string s){
  string t="good";
  int res=0;
  for(int i=0;i<4;i++)res+=s[i]!=t[i];
  return res;
}

signed main(){
  int t;cin>>t;
  while(t--){
    string s;cin>>s;
    for(int i=0;i<150;i++)for(int j=1;j<3;j++)dp[i][j]=20;
    dp[0][0]=0;
    for(int i=0;i<s.size()-6;i++){
      if(i>=3)dp[i+1][2]=min(dp[i][2],dp[i-3][1]+problem(s.substr(i,7)));
      dp[i+1][1]=min(dp[i][1],dp[i][0]+good(s.substr(i,4)));
    }
    cout<<dp[s.size()-6][2]<<endl;
  }
}
0