QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#632753 | #9454. String of CCPC | ucup-team037# | AC ✓ | 100ms | 3724kb | C++20 | 2.9kb | 2024-10-12 13:54:15 | 2024-10-12 13:54:15 |
Judging History
answer
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return b < a ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
const int BLK = 5;
int t;
int n;
string s;
int dp[2][BLK][2][2][2];
inline int cost(int a, int b, int c, int d) {
return a == 0 && b == 0 && c == 1 && d == 0;
}
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> t;
while (t--) {
cin >> n;
cin >> s;
REP (j, 0, BLK) {
REP (x, 0, 2) {
REP (y, 0, 2) {
REP (z, 0, 2) {
dp[1][j][x][y][z] = -INF;
}
}
}
}
dp[1][0][1][1][1] = 0;
REP (i, 0, n) {
int c = s[i] == 'P';
REP (j, 0, BLK) {
REP (x, 0, 2) {
REP (y, 0, 2) {
REP (z, 0, 2) {
dp[i & 1][j][x][y][z] = -INF;
}
}
}
REP (x, 0, 2) {
REP (y, 0, 2) {
REP (z, 0, 2) {
mxto(dp[i & 1][j][y][z][c],
dp[i & 1 ^ 1][j][x][y][z] +
cost(x, y, z, c));
if (j) {
REP (c, 0, 2) {
mxto(dp[i & 1][j][y][z][c],
dp[i & 1][j - 1][x][y][z] +
cost(x, y, z, c));
}
}
}
}
}
}
}
int ans = 0;
REP (j, 0, BLK) {
REP (x, 0, 2) {
REP (y, 0, 2) {
REP (z, 0, 2) {
mxto(ans, dp[n & 1 ^ 1][j][x][y][z] - j * (j - 1) / 2);
}
}
}
}
cout << ans << '\n';
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 100ms
memory: 3724kb
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