結果

問題 No.2738 CPC To F
ユーザー Yusuke.TYusuke.T
提出日時 2024-04-20 16:17:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,525 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 122,496 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 16:17:17
合計ジャッジ時間 1,878 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <iomanip>

constexpr int MAX_INT = 2147483647;
constexpr int MIN_INT = -2147483648;

#define rep(n, a, b) for (int (n) = (a); (n) < (b); (n)++)
#define rrep(n, a, b) for (int (n) = (a); (n) >= (b); (n)--)
#define llrep(n, a, b) for (long long (n) = (a); (n) < (b); (n)++)
#define llrrep(n, a, b) for (long long (n) = (a); (n) >= (b); (n)--)
#define itrAll(x) (x).begin(), (x).end()
#define inputvec(v) for (auto& x : v) {std::cin >> x;}
using namespace std;

using uint = unsigned int;
using ushort = unsigned short;
using byte = unsigned char;
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
using ipair = pair<int, int>;
using llpair = pair<long long, long long>;

int main() {
    int N;
    string S;
    cin >> N >> S;

    vector<int> cpc;
    rep(i, 0, N - 2) {
        if (S[i] == 'C' && S[i + 1] == 'P' && S[i + 2] == 'C') {
            cpc.push_back(i);
        }
    }

    if (!cpc.size()) {
        cout << 0 << endl;
        return 0;
    }

    /// <summary>
    /// [i] := {
    ///     [first]: i+1番目のCPCまでの部分文字列のうち, 少なくともi番目のCPCを変換したときのCPCTFの個数の最大値.
    ///     [second]: 〃のうち, i番目のCPCを変換していないときの〃.
    /// }
    /// </summary>
    vector<pair<int, int>> cnt(cpc.size());
    cnt[0] = { 0,0 };

    for (int i = 1; i < cpc.size(); i++) {
        int l = cpc[i - 1] + 3;
        int r = cpc[i] + 2;

        if (r - l >= 4 && S[l] == 'T' && S[l + 1] == 'F') {
            int v = cnt[i - 1].second + 1;
            cnt[i] = { v,v };
        }
        else if (r - l == 3 && S[l] == 'T') {
            cnt[i] = { cnt[i - 1].second + 1, max(cnt[i - 1].first, cnt[i - 1].second) };
        }
        else if (r - l == 1) {
            cnt[i] = { cnt[i - 1].second, max(cnt[i - 1].first, cnt[i - 1].second) };
        }
        else {
            int v = max(cnt[i - 1].first, cnt[i - 1].second);
            cnt[i] = { v,v };
        }
    }

    int l = cpc[cpc.size() - 1] + 3;
    auto& p = cnt[cpc.size() - 1];
    if (N - l >= 2 && S[l] == 'T' && S[l + 1] == 'F') {
        cout << max(p.first, p.second + 1) << endl;
    }
    else {
        cout << max(p.first, p.second) << endl;
    }

    return 0;
}
0