이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
int code (char ch) {
if (ch == 'M')
return 1;
if (ch == 'F')
return 2;
return 3;
}
const int MAX_MASK = (1 << 6) - 1;
inline int get_dist (int mask) {
vector <int> f (4, 0);
while (mask) {
f[mask & 3] = 1;
mask /= 4;
}
return f[1] + f[2] + f[3];
}
inline int add (int mask, int x) {
return (mask * 4 + x) & MAX_MASK;
}
inline void upd (int &a, int b) {
if (a < b)
a = b;
}
int dp[MAX_MASK][MAX_MASK];
int new_dp[MAX_MASK][MAX_MASK];
int main () {
ios::sync_with_stdio (false);
cin.tie (); cout.tie (0);
int n;
cin >> n;
string shipments_order;
cin >> shipments_order;
for (int first_mine = 0; first_mine < MAX_MASK; first_mine++)
for (int second_mine = 0; second_mine < MAX_MASK; second_mine++)
dp[first_mine][second_mine] = -1;
dp[0][0] = 0;
for (char shipment : shipments_order) {
int x = code (shipment);
for (int first_mine = 0; first_mine < MAX_MASK; first_mine++)
for (int second_mine = 0; second_mine < MAX_MASK; second_mine++)
new_dp[first_mine][second_mine] = -1;
for (int first_mine = 0; first_mine < MAX_MASK; first_mine++)
for (int second_mine = 0; second_mine < MAX_MASK; second_mine++) {
int value = dp[first_mine][second_mine];
if (value >= 0) {
int new_first_mine = add (first_mine, x);
int new_second_mine = add (second_mine, x);
upd (new_dp[new_first_mine][second_mine], value + get_dist (new_first_mine));
upd (new_dp[first_mine][new_second_mine], value + get_dist (new_second_mine));
}
}
for (int first_mine = 0; first_mine < MAX_MASK; first_mine++)
for (int second_mine = 0; second_mine < MAX_MASK; second_mine++)
dp[first_mine][second_mine] = new_dp[first_mine][second_mine];
}
int ans = 0;
for (int first_mine = 0; first_mine < MAX_MASK; first_mine++)
for (int second_mine = 0; second_mine < MAX_MASK; second_mine++)
upd (ans, dp[first_mine][second_mine]);
cout << ans << "\n";
return 0;
}
# | 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... |