QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632395 | #9454. String of CCPC | ucup-team052# | AC ✓ | 43ms | 4880kb | C++14 | 2.0kb | 2024-10-12 13:19:30 | 2024-10-12 13:19:32 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int T,n;
char s[200005];
int a[200005];
int tr[4][2],val[4][2];
int dp[4][4],ndp[4][4];
void trans(){
rep(p,0,2){
rep(q,0,3){
chkmax(dp[p + 1][tr[q][0]],dp[p][q] + val[q][0] - p);
chkmax(dp[p + 1][tr[q][1]],dp[p][q] + val[q][1] - p);
}
}
}
void dbg(){
rep(p,0,3){
rep(q,0,3) printf("(p=%d q=%d dp=%d)\n",p,q,dp[p][q]);
}
}
void solve(){
scanf("%d",&n);
scanf("%s",s + 1);
rep(i,1,n){
if(s[i] == 'C') a[i] = 0;
else a[i] = 1;
}
memset(dp,0xcf,sizeof(dp));
dp[0][0] = 0;
trans();
rep(i,1,n){
memset(ndp,0xcf,sizeof(ndp));
rep(p,0,3){
rep(q,0,3){
chkmax(ndp[p][tr[q][a[i]]],dp[p][q] + val[q][a[i]]);
}
}
rep(p,0,3){
rep(q,0,3) dp[p][q] = ndp[p][q];
}
trans();
// dbg();
}
int answer = -inf;
rep(p,0,3){
rep(q,0,3) chkmax(answer,dp[p][q]);
}
printf("%d\n",answer);
}
int main(){
// freopen("test.in","r",stdin);
tr[0][0] = 1;tr[0][1] = 0;
tr[1][0] = 2;tr[1][1] = 0;
tr[2][0] = 2;tr[2][1] = 3;
tr[3][0] = 1;tr[3][1] = 0;val[3][0] = 1;
scanf("%d",&T);
while(T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 43ms
memory: 4880kb
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