結果

問題 No.150 "良問"(良問とは言っていない
ユーザー finefine
提出日時 2016-06-05 22:12:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 167,744 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 09:32:25
合計ジャッジ時間 2,296 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int hamming(string s1, string s2) {
    int l = s1.length();
    int res = 0;
    for (int i = 0; i < l; i++) {
        if (s1[i] != s2[i]) res++;
    }
    return res;
}

//int g[100], p[100];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        string s;
        cin >> s;
        int l = s.length();
        vector<int> g(l, 1000), p(l, 1000);
        for (int i = 3; i < l - 7; i++) {
            g[i] = min(g[i - 1], hamming("good", s.substr(i - 3, 4)));
        }
        for (int i = l - 7; i >= 4; i--) {
            p[i] = min(p[i + 1], hamming("problem", s.substr(i, 7)));
        }
        int ans = 1000;
        for (int i = 3; i < l - 7; i++) {
            ans = min(ans, g[i] + p[i + 1]);
        }
        cout << ans << "\n";
    }
    return 0;
}
0