提出 #56264675


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

char win(char c) {
	if(c == 'R') return 'P';
	if(c == 'S') return 'R';
	if(c == 'P') return 'S';
	return c;
}
char draw(char c) {
	return c;
}

void solve() {
	int n; string s; cin >> n >> s;
	vector<vector<int>> dp(n + 1, vector<int>(2, -1));
	dp[1][0] = 0, dp[1][1] = 1;
	s = "%" + s;
	for(int i = 2; i <= n; ++i) {
		//win current:
		if(win(s[i]) != draw(s[i - 1])) dp[i][1] = max(dp[i][1], dp[i - 1][0] + 1);
		if(win(s[i]) != win(s[i - 1])) dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1);
		//draw current
		if(draw(s[i]) != draw(s[i - 1])) dp[i][0] = max(dp[i][0], dp[i - 1][0]);
		if(draw(s[i]) != win(s[i - 1])) dp[i][0] = max(dp[i][0], dp[i - 1][1]);
	}
	cout << max(dp[n][0], dp[n][1]);
}

int32_t main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}

提出情報

提出日時
問題 D - AtCoder Janken 3
ユーザ SlavicG
言語 C++ 20 (gcc 12.2)
得点 400
コード長 892 Byte
結果 AC
実行時間 11 ms
メモリ 14636 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 32
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3420 KiB
00_sample_01.txt AC 1 ms 3424 KiB
00_sample_02.txt AC 1 ms 3432 KiB
01_random_03.txt AC 11 ms 14536 KiB
01_random_04.txt AC 11 ms 14532 KiB
01_random_05.txt AC 10 ms 14464 KiB
01_random_06.txt AC 11 ms 14532 KiB
01_random_07.txt AC 11 ms 14612 KiB
01_random_08.txt AC 10 ms 14524 KiB
01_random_09.txt AC 10 ms 14356 KiB
01_random_10.txt AC 10 ms 14636 KiB
01_random_11.txt AC 11 ms 14520 KiB
01_random_12.txt AC 11 ms 14536 KiB
01_random_13.txt AC 11 ms 14632 KiB
01_random_14.txt AC 10 ms 14544 KiB
01_random_15.txt AC 10 ms 14564 KiB
01_random_16.txt AC 4 ms 5968 KiB
01_random_17.txt AC 7 ms 10672 KiB
01_random_18.txt AC 10 ms 12680 KiB
01_random_19.txt AC 10 ms 12880 KiB
01_random_20.txt AC 11 ms 14312 KiB
01_random_21.txt AC 4 ms 6940 KiB
01_random_22.txt AC 9 ms 13500 KiB
02_handmade_23.txt AC 1 ms 3484 KiB
02_handmade_24.txt AC 1 ms 3528 KiB
02_handmade_25.txt AC 1 ms 3400 KiB
02_handmade_26.txt AC 10 ms 14532 KiB
02_handmade_27.txt AC 10 ms 14540 KiB
02_handmade_28.txt AC 10 ms 14540 KiB
02_handmade_29.txt AC 10 ms 14560 KiB
02_handmade_30.txt AC 10 ms 14472 KiB
02_handmade_31.txt AC 10 ms 14568 KiB