이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
using namespace std;
#define MAX_N 100000
#define INF 1000000000
int N;
string str;
int arr[MAX_N+1];
int dp1[4][4][4][4], dp2[4][4][4][4];
int main(){
scanf("%d", &N);
cin>>str;
for(int i=0; i<N; i++){
if(str[i]=='M') arr[i] = 1;
else if(str[i]=='F') arr[i] = 2;
else arr[i] = 3;
}
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
for(int k=0; k<4; k++){
for(int t=0; t<4; t++){
dp1[i][j][k][t] = -INF;
}
}
}
}
dp1[0][0][0][0] = 0;
for(int T=0; T<N; T++){
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
for(int k=0; k<4; k++){
for(int t=0; t<4; t++){
dp2[i][j][k][t] = -INF;
}
}
}
}
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
for(int k=0; k<4; k++){
for(int t=0; t<4; t++){
if(dp1[i][j][k][t]==-INF) continue;
if(k==0){
if(t==0){
dp2[i][j][0][arr[T]] = max(dp2[i][j][0][arr[T]], dp1[i][j][k][t]+1);
}
else if(t==arr[T]){
dp2[i][j][t][arr[T]] = max(dp2[i][j][t][arr[T]], dp1[i][j][k][t]+1);
}else{
dp2[i][j][t][arr[T]] = max(dp2[i][j][t][arr[T]], dp1[i][j][k][t]+2);
}
}else{
int cnt = 0;
cnt+=(k==t);
cnt+=(k==arr[T]);
cnt+=(t==arr[T]);
if(cnt==0){
dp2[i][j][t][arr[T]] = max(dp2[i][j][t][arr[T]], dp1[i][j][k][t]+3);
}else if(cnt==1){
dp2[i][j][t][arr[T]] = max(dp2[i][j][t][arr[T]], dp1[i][j][k][t]+2);
}else{
dp2[i][j][t][arr[T]] = max(dp2[i][j][t][arr[T]], dp1[i][j][k][t]+1);
}
}
if(i==0){
if(j==0){
dp2[0][arr[T]][k][t] = max(dp2[0][arr[T]][k][t], dp1[i][j][k][t]+1);
}else if(arr[T]==j){
dp2[j][arr[T]][k][t] = max(dp2[j][arr[T]][k][t], dp1[i][j][k][t]+1);
}else{
dp2[j][arr[T]][k][t] = max(dp2[j][arr[T]][k][t], dp1[i][j][k][t]+2);
}
}else{
int cnt = 0;
cnt+=(i==j);
cnt+=(i==arr[T]);
cnt+=(j==arr[T]);
if(cnt==0){
dp2[j][arr[T]][k][t] = max(dp2[j][arr[T]][k][t], dp1[i][j][k][t]+3);
}else if(cnt==1){
dp2[j][arr[T]][k][t] = max(dp2[j][arr[T]][k][t], dp1[i][j][k][t]+2);
}else{
dp2[j][arr[T]][k][t] = max(dp2[j][arr[T]][k][t], dp1[i][j][k][t]+1);
}
}
}
}
}
}
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
for(int k=0; k<4; k++){
for(int t=0; t<4; t++){
dp1[i][j][k][t] = dp2[i][j][k][t];
}
}
}
}
}
int ans = 0;
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
for(int k=0; k<4; k++){
for(int t=0; t<4; t++){
ans = max(ans, dp1[i][j][k][t]);
}
}
}
}
printf("%d", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int main()':
miners.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |