이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n,dp[2][4][4][4][4],val,mx=0,hsh[4],kmp;
char str[100005];
int main()
{
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
dp[0][j][k][l][c]=-1e9;
}
}
}
}
dp[0][0][0][0][0]=0;
scanf("%d%s",&n,str+1);
for(int i=1;i<=n;i++)
{
//printf("%d\n",i);
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
dp[i%2][j][k][l][c]=-1e9;
}
}
}
}
if(str[i]=='M')
{
val=1;
}else if(str[i]=='F')
{
val=2;
}else
{
val=3;
}
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
memset(hsh,0,sizeof hsh);
hsh[j]=1;
hsh[k]=1;
hsh[val]=1;
kmp=0;
for(int d=1;d<=3;d++)
{
kmp+=hsh[d];
}
dp[i%2][k][val][l][c]=max(dp[i%2][k][val][l][c],dp[1-(i%2)][j][k][l][c]+kmp);
memset(hsh,0,sizeof hsh);
hsh[l]=1;
hsh[c]=1;
hsh[val]=1;
kmp=0;
for(int d=1;d<=3;d++)
{
kmp+=hsh[d];
}
dp[i%2][j][k][c][val]=max(dp[i%2][j][k][c][val],dp[1-(i%2)][j][k][l][c]+kmp);
}
}
}
}
/*for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
for(int c=0;c<4;c++)
{
printf("%d %d %d %d %d\n",j,k,l,c,dp[i%2][j][k][c][l]);
}
}
}
}*/
}
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
mx=max(mx,dp[n%2][i][j][k][l]);
}
}
}
}
printf("%d\n",mx);
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int main()':
miners.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d%s",&n,str+1);
| ~~~~~^~~~~~~~~~~~~~~~~
# | 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... |