結果
| 問題 | No.252 "良問"(良問とは言っていない (2) | 
| コンテスト | |
| ユーザー |  latte0119 | 
| 提出日時 | 2016-02-25 13:38:17 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 25 ms / 2,000 ms | 
| コード長 | 1,264 bytes | 
| コンパイル時間 | 1,382 ms | 
| コンパイル使用メモリ | 158,556 KB | 
| 実行使用メモリ | 8,604 KB | 
| 最終ジャッジ日時 | 2024-09-22 13:40:31 | 
| 合計ジャッジ時間 | 2,096 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 7 | 
コンパイルメッセージ
main.cpp:27:9: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   27 | char *g="good";
      |         ^~~~~~
main.cpp:28:9: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   28 | char *p="problem";
      |         ^~~~~~~~~
main.cpp: In function ‘void solve()’:
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     scanf("%s",S);
      |     ~~~~~^~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
            
            ソースコード
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ln <<endl
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}
int N;
char S[1111111];
int f[1111111];
char *g="good";
char *p="problem";
void solve(){
    scanf("%s",S);
    int mi=1145141919;
    int L=strlen(S);
    fill_n(f,L,1<<25);
    int ans=1<<25,la=0;
    rep(i,L){
        if(i+4<=L){
            int cnt=0;
            rep(j,4)cnt+=S[i+j]!=g[j];
            chmin(f[i+4],cnt);
        }
        if(i)chmin(f[i],f[i-1]);
        if(i+7<=L){
            int cnt=0;
            rep(j,7)cnt+=S[i+j]!=p[j];
            chmin(ans,cnt+f[i]+la);
            if(la)chmin(ans,cnt+la-1+3);
            if(cnt==0)la++;
        }
    }
    printf("%d\n",ans);
}
signed main(){
    scanf("%d",&N);
    while(N--)solve();
    return 0;
}
            
            
            
        