이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int has(int a, int b, int c, int d) {
return 64*a+16*b+4*c+d;
}
int dis(int a, int b, int c) {
if (a==0) {
if (b==0) {
if (c==0) {
return 0;
}
return 1;
}
return 1+(b!=c);
}
if (b==0) {
if (a==0) {
if (c==0) {
return 0;
}
return 1;
}
return 1+(a!=c);
}
if (c==0) {
if (b==0) {
if (a==0) {
return 0;
}
return 1;
}
return 1+(a!=b);
}
if (a==b && b==c) {
return 1;
}
if (a==b || a==c || b==c) {
return 2;
}
return 3;
}
signed main() {
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int n;
cin >> n;
string s;
cin >> s;
int INF=1000000007;
vector<vector<int>> dp(n+1,vector<int>(256,-INF));
dp[0][has(0,0,0,0)] = 0;
//store the last two shipments to mine 1 and the last two shipments to mine 2
for (int ind=1; ind<=n; ind++) {
int cursh = s[ind-1];
int t=-10;
if (cursh=='M') {
t=1;
}
else if (cursh=='F') {
t=2;
}
else {
t=3;
}
for (int psh1=0; psh1<4; psh1++) {
for (int psh2=0; psh2<4; psh2++) {
for (int psh3=0; psh3<4; psh3++) {
for (int psh4=0; psh4<4; psh4++) {
int H=dp[ind-1][has(psh1,psh2,psh3,psh4)];
dp[ind][has(psh2,t,psh3,psh4)] = max(dp[ind][has(psh2,t,psh3,psh4)],H+dis(psh1,psh2,t));
dp[ind][has(psh1,psh2,psh4,t)] = max(dp[ind][has(psh1,psh2,psh4,t)],H+dis(psh3,psh4,t));
}
}
}
}
}
int ma=-1;
for (int psh1=0; psh1<4; psh1++) {
for (int psh2=0; psh2<4; psh2++) {
for (int psh3=0; psh3<4; psh3++) {
for (int psh4=0; psh4<4; psh4++) {
ma=max(ma,dp[n][has(psh1,psh2,psh3,psh4)]);
}
}
}
}
cout << ma << endl;
}
# | 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... |