結果

問題 No.150 "良問"(良問とは言っていない
ユーザー ei1333333ei1333333
提出日時 2016-02-25 18:20:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 976 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 159,960 KB
実行使用メモリ 7,632 KB
最終ジャッジ日時 2024-04-19 09:32:07
合計ジャッジ時間 1,985 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
7,500 KB
testcase_05 AC 2 ms
7,496 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
7,624 KB
testcase_11 AC 3 ms
7,628 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
7,632 KB
testcase_16 AC 3 ms
7,628 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const string temp[] = {"good", "problem"};
int unmatch[2][1000000];
bool late[1000000];

int main()
{ 
  int K;
  cin >> K;
  while(K--) {
    string S;
    cin >> S;
    for(int j = 0; j < 2; j++) {
      for(int i = 0; i <= S.size() - temp[j].size(); i++) {
        unmatch[j][i] = 0;
        for(int k = 0; k < temp[j].size(); k++) {
          unmatch[j][i] += S[i + k] != temp[j][k];
        }
        late[i] = unmatch[j][i] == 0;
      }
    }
    for(int i = 1; i <= S.size() - temp[0].size(); i++) {
      unmatch[0][i] = min(unmatch[0][i - 1], unmatch[0][i]);
    }
    for(int i = S.size() - temp[1].size() - 1; i >= 0; i--) {
      unmatch[1][i] = min(unmatch[1][i + 1], unmatch[1][i]);
    }
    int ret = INF;
    for(int i = 0; i + temp[0].size() <= S.size() - temp[1].size() ; i++) {
      ret = min(ret, unmatch[0][i] + unmatch[1][i + temp[0].size()]);
    }
    cout << ret << endl;
  }

}
0