結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー 沙耶花沙耶花
提出日時 2022-03-22 22:19:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 4,375 ms
コンパイル使用メモリ 256,588 KB
実行使用メモリ 59,020 KB
最終ジャッジ日時 2024-04-18 23:07:55
合計ジャッジ時間 6,512 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
6,812 KB
testcase_01 AC 143 ms
6,816 KB
testcase_02 AC 128 ms
14,756 KB
testcase_03 AC 140 ms
58,872 KB
testcase_04 AC 141 ms
59,020 KB
testcase_05 AC 143 ms
58,908 KB
testcase_06 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

int get(string x,string y){
	if(x.size()!=y.size())return Inf;
	int ret= 0;
	rep(i,x.size()){
		if(x[i]!=y[i])ret++;
	}
	return ret;
}

int main(){
	
	int _t;
	cin>>_t;
	rep(_,_t){
		string s;
		cin>>s;
		int n = s.size();
		vector dp(n+1,vector<int>(2,Inf));
		dp[0][0] = 0;
		int ans = Inf;
		rep(i,n){
			{
				int cc = 0;
				if(s.substr(i,7)=="problem")cc = 1;
				dp[i+1][0] = min(dp[i+1][0],dp[i][0]+cc);
			}
			if(i+4<=n){
				dp[i+4][1] = min(dp[i+4][1], dp[i][0] + get(s.substr(i,4), "good"));
			}
			dp[i+1][1] = min(dp[i+1][1],dp[i][1]);
			ans = min(ans,dp[i][1] + get(s.substr(i,7), "problem"));
		}
		cout<<ans<<endl;
		
	}
	
	return 0;
}
0