QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#632544#9454. String of CCPCucup-team055#AC ✓41ms3980kbC++202.9kb2024-10-12 13:32:382024-10-12 13:32:38

Judging History

你现在查看的是最新测评结果

  • [2024-10-12 13:32:38]
  • 评测
  • 测评结果:AC
  • 用时:41ms
  • 内存:3980kb
  • [2024-10-12 13:32:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}
template<class T> bool inside(T l,T x,T r){return l<=x&&x<r;}



void solve();
// CYAN / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    string B = "CCPC";
    vector<int> toC = {1, 2, 2, 1};
    vector<int> toP = {0, 0, 3, 0};
    vector<int> dp1(4, -INF), dp2(4, -INF);
    dp1[0] = 0;
    rep(i, 0, N + 1){
        rep(j, 0, 4){
            if (j == 3){
                chmax(dp2[toC[j]], dp1[j] + 1);
            }
            else{
                chmax(dp2[toC[j]], dp1[j]);
            }
            chmax(dp2[toP[j]], dp1[j]);
        }
        if (i == N) break;
        vector<int> n_dp1(4, -INF), n_dp2(4, -INF);
        rep(j, 0, 4){
            if (S[i] == 'C'){
                chmax(n_dp1[toC[j]], dp1[j] + (j == 3 ? 1 : 0));
                chmax(n_dp2[toC[j]], dp2[j] + (j == 3 ? 1 : 0));
            }
            else{
                chmax(n_dp1[toP[j]], dp1[j]);
                chmax(n_dp2[toP[j]], dp2[j]);
            }
        }
        swap(n_dp1, dp1);
        swap(n_dp2, dp2);
    }
    int ans = 0;
    chmax(ans, vec_max(dp1));
    chmax(ans, vec_max(dp2));
    cout << ans << "\n";
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 41ms
memory: 3980kb

input:

20003
5
PCCPC
10
CPPPPCPCPC
4
CPPC
11
CCPPCPPPCCP
17
PPPPCPCCCCCPCCCCC
10
PPCCPCPPCP
9
CPCCCCPPC
11
PCPPPPCCPPP
15
CPCPPPPCCPCPCCC
11
PCCPPCCPCPP
9
PCPCCPPCP
10
CCPCPPPCPP
14
CCCCPPPCPCPCPP
2
CC
12
CCPCPPPPPCPP
6
CPPPPP
12
PCCPCCCCCPCC
16
CPCCPCCPPCCCCPPC
7
CPPPCPC
16
PPPPPCCPCPCPCPPC
13
PPPCPCCCCPP...

output:

1
1
0
1
2
1
1
1
2
2
1
1
1
0
1
0
3
2
1
2
1
2
2
0
1
2
3
1
1
3
1
2
2
1
0
0
0
3
1
0
0
1
1
2
0
1
1
0
1
2
0
1
0
1
0
3
1
1
0
2
1
3
2
2
0
2
2
0
0
2
1
1
3
3
1
3
1
2
0
1
1
0
1
2
2
1
1
2
1
3
1
1
3
1
2
2
0
1
0
3
0
1
1
2
2
0
2
1
1
2
2
0
3
1
1
1
1
2
1
2
0
1
1
0
3
0
3
1
1
0
0
1
0
3
0
1
1
1
1
2
2
1
1
0
0
1
2
0
1
2
...

result:

ok 20003 lines

Extra Test:

score: 0
Extra Test Passed