QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632724 | #9454. String of CCPC | ucup-team133# | AC ✓ | 235ms | 4284kb | C++23 | 2.4kb | 2024-10-12 13:51:59 | 2024-10-12 13:52:00 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
using namespace std;
using ll = long long;
const int INF = 1e9, MAX = 10;
void solve() {
int n;
string s;
cin >> n >> s;
vector dp(MAX, vector<int>(1 << 3, -INF)), ndp(MAX, vector<int>(1 << 3, -INF));
auto get = [](int k, int i, int S, int nxt) -> int { return k + i >= 3 and S == 4 and nxt == 0; };
auto nxt = [](int S, int d) -> int { return (S >> 1) | (d << 2); };
dp[0][0] = 0;
for (int k = 0; k <= n; k++) {
for (int i = 0; i < MAX; i++) {
for (int S = 0; S < 1 << 3; S++) {
int& val = dp[i][S];
if (val == -INF) continue;
if (i + 1 < MAX) {
for (int d = 0; d < 2; d++) {
chmax(dp[i + 1][nxt(S, d)], val + get(k, i, S, d));
}
}
if (k < n) {
int d = (s[k] == 'P');
chmax(ndp[i][nxt(S, d)], val + get(k, i, S, d));
} else {
chmax(ndp[i][S], val);
}
val = -INF;
}
}
swap(dp, ndp);
}
int ans = -INF;
for (int i = 0; i < MAX; i++) {
for (int S = 0; S < 1 << 3; S++) {
chmax(ans, dp[i][S] - i * (i - 1) / 2);
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int T;
cin >> T;
for (; T--;) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 235ms
memory: 4284kb
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