結果
| 問題 |
No.2738 CPC To F
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 11:35:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,129 bytes |
| コンパイル時間 | 2,200 ms |
| コンパイル使用メモリ | 198,044 KB |
| 最終ジャッジ日時 | 2025-02-21 06:14:53 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll LINF=0x1fffffffffffffff;
const ll MINF=0x7fffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
const int MOD2=998244353;
const ld EPS=1e-9;
const ld PI=3.14159265358979323846;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())
#define nep(x) next_permutation(ALL(x))
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<VV<T>>;
template <class T>
using VVVV = V<VVV<T>>;
template <class T>
using V_p = V<pair<T,T>>;
template <class T>
using n_pq = priority_queue<T>;
template <class T>
using r_pq = priority_queue<T,vector<T>,greater<T>>;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template <class T>ostream &operator<<(ostream &o,const deque<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template <class T>ostream &operator<<(ostream &o,const set<T>&v)
{o<<"{";for(auto i:v)o<<" "<<i;o<<"}";return o;}
ll pow_ll(ll x, ll n) {
long long ret = 1;
while (n > 0) {
if (n & 1) ret *= x; // n の最下位bitが 1 ならば x^(2^i) をかける
x *= x;
n >>= 1; // n を1bit 左にずらす
}
return ret;
}
////////////////////////////////////////////////////
int main() {
ll N;
cin >> N;
string S;
cin >> S;
VV<ll> dp(N+1,V<ll>(6,-1));
dp[0][0] = 0;
ll max_case;
max_case = 0;
rep(i,N) {
if (S[i] == 'C') {
dp[i+1][1] = max_case;
if (dp[i][2] >= 0) {
dp[i+1][3] = max(dp[i+1][3],dp[i][2]);
}
}
else if (S[i] == 'P') {
if (dp[i][1] >= 0) {
dp[i+1][2] = max(dp[i+1][2],dp[i][1]);
}
}
else if (S[i] == 'T') {
if (dp[i][3] >= 0) {
dp[i+1][4] = max(dp[i+1][4],dp[i][3]);
}
}
else if (S[i] == 'F') {
if (dp[i][4]>=0) {
dp[i+1][0] = max(dp[i+1][0],dp[i][4]+1);
max_case = max(max_case,dp[i+1][0]);
}
}
if (i+3<=N && dp[i][4] >= 0) {
if (S.substr(i,3) == "CPC") {
dp[i+3][0] = max(dp[i+3][0],dp[i][4]+1);
max_case = max(max_case,dp[i+3][0]);
}
}
}
cout << max_case << endl;
}