結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー nanasilinanasili
提出日時 2015-07-31 13:50:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,881 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 85,160 KB
実行使用メモリ 12,592 KB
最終ジャッジ日時 2023-09-24 22:27:28
合計ジャッジ時間 1,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

int main() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    char s[1000001];
    scanf("%s", s);
    int l = strlen(s);
    char g[5] = "good", p[8] = "problem";
    int a[l-4-7+1], b[l-7+1];
    int gcnt = 0, pcnt = 0;
    for (int j = 0; j < l-4-7+1; j++) {
      int cnt = 0;
      for (int k = 0; k < 4; k++) {
	cnt += s[j+k] != g[k];
      }
      a[j] = cnt+gcnt;
      if (cnt == 0) gcnt++;
    }
    for (int j = 0; j < l-7+1; j++) {
      int cnt = 0;
      for (int k = 0; k < 7; k++) {
	cnt += s[j+k] != p[k];
      }
      b[j] = cnt+pcnt;
      if (cnt == 0) pcnt++;
    }
    for (int j = 0; j < l-7+1; j++) {
      int cnt = 0;
      for (int k = -6; k <= 6; k++) {
	if (j+k < 0 || j+k >= l-7+1 || k == 0) continue;
	cnt += b[j+k] == 0;
      }
      b[j] -= cnt;
    }

    int ans = 11;
    for (int j = 1; j < l-4-7+1; j++) {
      int cnt = 0;
      for (int k = -6; k <= 3; k++) {
	if (j+k < 0 || j+k >= l-7+1 || k == 0) continue;
	cnt += b[j+k] == 0;
      }
      for (int k = -3; k <= 3; k++) {
	if (j+k < 0 || j+k >= l-4-7+1 || k == 0) continue;
	cnt += a[j+k] == 0;
      }
      a[j] = min(a[j]-cnt, a[j-1]);
    }
    for (int j = 4; j < l-7+1; j++) {
      ans = min(ans, a[j-4]+b[j]);
    }

    // for (int j = 0; j < l-4-7+1; j++) {
    //   printf("%d ", a[j]);
    // }
    // puts("");
    // for (int j = 0; j < l-7+1; j++) {
    //   printf("%d ", b[j]);  
    // }
    // puts("");

    printf("%d\n", ans);
  }

}
0