結果
| 問題 |
No.252 "良問"(良問とは言っていない (2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-27 12:43:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,521 bytes |
| コンパイル時間 | 1,735 ms |
| コンパイル使用メモリ | 169,940 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 17:55:13 |
| 合計ジャッジ時間 | 4,246 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 2 RE * 4 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
static const int MAX_LEN = 100001;
string nstr(){
static char res_[MAX_LEN];
scanf("%s",res_);
return string(res_);
}
const int INF = INT_MAX;
const string G = "good", P = "problem";
int dp[MAX_LEN][5][8];
void solve(string &S){
const int N = sz(S);
rep(i, N + 1)rep(j, 5)rep(k, 8)dp[i][j][k] = INF;
dp[0][0][0] = 0;
rep(i, N)rep(j, 5)rep(k, 8)if(dp[i][j][k] != INF){
if(j == 0 && k == 7)continue;
int x = dp[i][j][k];
// good
if(j < 4)smin(dp[i + 1][j + 1][0], x + (S[i] != G[j]));
// problem
if(k < 7)smin(dp[i + 1][j == 4 ? 4 : 0][k + 1], x + (S[i] != P[k]));
// not
smin(dp[i + 1][j == 4 ? 4 : 0][k == 7 ? 7 : 0], x + ((j < 4 && S[i] == G[j]) || (k < 7 && S[i] == P[k])));
// comp
if(j == 4 && k == 7)smin(dp[i + 1][j][k], x);
}
cout << dp[N][4][7] << endl;
}
int main(){
int T;
cin >> T;
while(T--){
string S = nstr();
solve(S);
}
}