Submission #56303154
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
void justDoIt();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
justDoIt();
return 0;
}
void justDoIt() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == 'R') {
a[i] = 0;
}
if (c == 'S') {
a[i] = 1;
}
if (c == 'P') {
a[i] = 2;
}
}
vector<vector<int>> dp(n, vector<int>(3, -1));
for (int i = 0; i < n; i++) {
for (int j1 = 0; j1 < 3; j1++) {
if ((a[i] + 1) % 3 == j1) {
dp[i][j1] = -1;
continue;
}
int score = (j1 != a[i]);
if (i == 0) {
dp[i][j1] = score;
continue;
}
for (int j2 = 0; j2 < 3; j2++) {
if (j1 != j2 && dp[i - 1][j2] != -1) {
dp[i][j1] = max(dp[i][j1], dp[i - 1][j2] + score);
}
}
}
}
int res = 0;
for (int j = 0; j < 3; j++) {
res = max(res, dp[n - 1][j]);
}
cout << res;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - AtCoder Janken 3 |
| User | SanguineChame |
| Language | C++ 20 (gcc 12.2) |
| Score | 400 |
| Code Size | 1240 Byte |
| Status | AC |
| Exec Time | 17 ms |
| Memory | 14960 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 02_handmade_23.txt, 02_handmade_24.txt, 02_handmade_25.txt, 02_handmade_26.txt, 02_handmade_27.txt, 02_handmade_28.txt, 02_handmade_29.txt, 02_handmade_30.txt, 02_handmade_31.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3440 KiB |
| 00_sample_01.txt | AC | 1 ms | 3584 KiB |
| 00_sample_02.txt | AC | 1 ms | 3440 KiB |
| 01_random_03.txt | AC | 16 ms | 14656 KiB |
| 01_random_04.txt | AC | 17 ms | 14608 KiB |
| 01_random_05.txt | AC | 14 ms | 14616 KiB |
| 01_random_06.txt | AC | 16 ms | 14960 KiB |
| 01_random_07.txt | AC | 16 ms | 14724 KiB |
| 01_random_08.txt | AC | 14 ms | 14824 KiB |
| 01_random_09.txt | AC | 13 ms | 14900 KiB |
| 01_random_10.txt | AC | 13 ms | 14620 KiB |
| 01_random_11.txt | AC | 15 ms | 14660 KiB |
| 01_random_12.txt | AC | 16 ms | 14656 KiB |
| 01_random_13.txt | AC | 16 ms | 14648 KiB |
| 01_random_14.txt | AC | 13 ms | 14640 KiB |
| 01_random_15.txt | AC | 13 ms | 14624 KiB |
| 01_random_16.txt | AC | 5 ms | 5928 KiB |
| 01_random_17.txt | AC | 9 ms | 10960 KiB |
| 01_random_18.txt | AC | 13 ms | 13160 KiB |
| 01_random_19.txt | AC | 14 ms | 13136 KiB |
| 01_random_20.txt | AC | 16 ms | 14724 KiB |
| 01_random_21.txt | AC | 5 ms | 7284 KiB |
| 01_random_22.txt | AC | 12 ms | 13856 KiB |
| 02_handmade_23.txt | AC | 1 ms | 3500 KiB |
| 02_handmade_24.txt | AC | 1 ms | 3436 KiB |
| 02_handmade_25.txt | AC | 1 ms | 3500 KiB |
| 02_handmade_26.txt | AC | 13 ms | 14580 KiB |
| 02_handmade_27.txt | AC | 14 ms | 14584 KiB |
| 02_handmade_28.txt | AC | 13 ms | 14672 KiB |
| 02_handmade_29.txt | AC | 13 ms | 14956 KiB |
| 02_handmade_30.txt | AC | 13 ms | 14640 KiB |
| 02_handmade_31.txt | AC | 14 ms | 14668 KiB |