結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー latte0119latte0119
提出日時 2016-02-25 13:38:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,264 bytes
コンパイル時間 2,410 ms
コンパイル使用メモリ 159,448 KB
実行使用メモリ 9,104 KB
最終ジャッジ日時 2023-10-23 19:59:18
合計ジャッジ時間 2,234 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
5,840 KB
testcase_01 AC 25 ms
5,836 KB
testcase_02 AC 20 ms
8,552 KB
testcase_03 AC 20 ms
9,104 KB
testcase_04 AC 20 ms
9,104 KB
testcase_05 AC 20 ms
9,104 KB
testcase_06 AC 2 ms
5,836 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

#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;
}
0