結果

問題 No.150 "良問"(良問とは言っていない
ユーザー tnakao0123tnakao0123
提出日時 2016-03-22 19:18:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,241 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 85,176 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 09:31:44
合計ジャッジ時間 1,414 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 150.cc: No.150 "良問"(良問とは言っていない - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int INF = 1 << 30;

const string g = "goodproblem";
const int gn = 11;

/* typedef */

/* global variables */

int dp[MAX_N + 1][gn + 1];

/* subroutines */

/* main */

int main() {
  int tn;
  cin >> tn;

  while (tn--) {
    string s;
    cin >> s;
    int sn = s.size();

    for (int i = 0; i <= sn; i++)
      for (int j = 0; j <= gn; j++) dp[i][j] = INF;
    dp[0][0] = 0;

    for (int i = 0; i < sn; i++)
      for (int j = 0; j <= gn; j++) {
	int d0 = dp[i][j];
	if (d0 < INF) {
	  if (j < gn) {
	    int d = (s[i] == g[j]) ? d0 : d0 + 1;
	    if (dp[i + 1][j + 1] > d) dp[i + 1][j + 1] = d;
	  }

	  if (j == 0 || j == 4 || j == 11)
	    if (dp[i + 1][j] > d0) dp[i + 1][j] = d0;
	}
      }

    printf("%d\n", dp[sn][gn]);
  }
  return 0;
}
0