QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638558#9454. String of CCPChos_lyricAC ✓40ms3976kbC++142.7kb2024-10-13 16:13:562024-10-13 16:13:58

Judging History

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

  • [2024-10-13 16:13:58]
  • 评测
  • 测评结果:AC
  • 用时:40ms
  • 内存:3976kb
  • [2024-10-13 16:13:56]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


constexpr int INF = 1001001001;

// insert <= K
// next: cost 2, gain <= 2
constexpr int K = 2;

constexpr int TO[4][2] = {{1, 0}, {2, 0}, {2, 3}, {1, 0}};
constexpr int GAIN[4][2] = {{0, 0}, {0, 0}, {0, 0}, {1, 0}};

int N;
char S[1'000'010];

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d", &N);
    scanf("%s", S);
    
    int crt[K + 1][4], nxt[K + 1][4];
    for (int k = 0; k <= K; ++k) for (int u = 0; u < 4; ++u) crt[k][u] = -INF;
    crt[0][0] = 0;
    for (int i = 0; i <= N; ++i) {
      // insert
      for (int k = 0; k < K; ++k) for (int u = 0; u < 4; ++u) {
        for (int e = 0; e < 2; ++e) {
          chmax(crt[k + 1][TO[u][e]], crt[k][u] - k + GAIN[u][e]);
        }
      }
// for(int k=0;k<=K;++k){cerr<<i<<" "<<k<<": ";pv(crt[k],crt[k]+4);}
      // advance
      if (i < N) {
        const int e = string("CP").find(S[i]);
        for (int k = 0; k <= K; ++k) for (int u = 0; u < 4; ++u) nxt[k][u] = -INF;
        for (int k = 0; k <= K; ++k) for (int u = 0; u < 4; ++u) {
          chmax(nxt[k][TO[u][e]], crt[k][u] + GAIN[u][e]);
        }
        memcpy(crt, nxt, sizeof(nxt));
      }
    }
    
    int ans = -INF;
    for (int k = 0; k <= K; ++k) for (int u = 0; u < 4; ++u) {
      chmax(ans, crt[k][u]);
    }
    printf("%d\n", ans);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

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

详细

Test #1:

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

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 40ms
memory: 3976kb

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