提出 #56280686


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define pb push_back
#define sz(v) v.size()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=2e9;
const int MOD=998244353;
const int maxn=200005;
int n;
int s[maxn];
int dp[maxn][4];
int win[10],lose[10];
int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n;
	for(int i=1;i<=n;i++){
		char c;
		cin>>c;
		s[i]=(c=='R'?1:(c=='P'?2:3));
	}
	win[1]=2;
	win[2]=3;
	win[3]=1;
	lose[1]=3;
	lose[2]=1;
	lose[3]=2;
	dp[1][win[s[1]]]=1;
	for(int i=2;i<=n;i++){
		//lose
		dp[i][lose[s[i]]]=0;
		
		//win
		int p=win[s[i]];
		for(int j=1;j<=3;j++){
			if(j!=p){
				dp[i][p]=max(dp[i][p],dp[i-1][j]+1);
			}
		}
		
		//draw
		for(int j=1;j<=3;j++){
			if(j!=s[i]){
				dp[i][s[i]]=max(dp[i][s[i]],dp[i-1][j]);
			}
		}
//		cout<<dp[i][1]<<" "<<dp[i][2]<<" "<<dp[i][3]<<endl;
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
	return 0;
}

提出情報

提出日時
問題 D - AtCoder Janken 3
ユーザ HeXY
言語 C++ 23 (gcc 12.2)
得点 400
コード長 1078 Byte
結果 AC
実行時間 8 ms
メモリ 11424 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 3540 KiB
00_sample_01.txt AC 1 ms 3408 KiB
00_sample_02.txt AC 1 ms 3416 KiB
01_random_03.txt AC 8 ms 11232 KiB
01_random_04.txt AC 8 ms 11144 KiB
01_random_05.txt AC 6 ms 11264 KiB
01_random_06.txt AC 6 ms 11292 KiB
01_random_07.txt AC 8 ms 11220 KiB
01_random_08.txt AC 6 ms 11284 KiB
01_random_09.txt AC 6 ms 11420 KiB
01_random_10.txt AC 6 ms 11144 KiB
01_random_11.txt AC 7 ms 11260 KiB
01_random_12.txt AC 8 ms 11220 KiB
01_random_13.txt AC 8 ms 11280 KiB
01_random_14.txt AC 6 ms 11344 KiB
01_random_15.txt AC 6 ms 11208 KiB
01_random_16.txt AC 3 ms 5320 KiB
01_random_17.txt AC 4 ms 8776 KiB
01_random_18.txt AC 6 ms 10060 KiB
01_random_19.txt AC 7 ms 10248 KiB
01_random_20.txt AC 8 ms 11196 KiB
01_random_21.txt AC 3 ms 6372 KiB
01_random_22.txt AC 5 ms 10636 KiB
02_handmade_23.txt AC 1 ms 3408 KiB
02_handmade_24.txt AC 1 ms 3424 KiB
02_handmade_25.txt AC 1 ms 3400 KiB
02_handmade_26.txt AC 6 ms 11280 KiB
02_handmade_27.txt AC 6 ms 11424 KiB
02_handmade_28.txt AC 6 ms 11216 KiB
02_handmade_29.txt AC 6 ms 11344 KiB
02_handmade_30.txt AC 6 ms 11216 KiB
02_handmade_31.txt AC 6 ms 11212 KiB