結果
問題 | No.252 "良問"(良問とは言っていない (2) |
ユーザー | paruki |
提出日時 | 2016-07-27 12:43:18 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,521 bytes |
コンパイル時間 | 1,453 ms |
コンパイル使用メモリ | 165,264 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-24 10:19:59 |
合計ジャッジ時間 | 3,680 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 1 ms
5,376 KB |
ソースコード
#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); } }