이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
const ll Mod = 1000000007;
const int maxN = 1e5 + 1;
int n;
int dp[maxN][4][4][4][4];
string s;
int distinct(int a, int b, int c){
if (a == 0){
if (b == 0){
if (c == 0) return 0;
return 1;
}
if (b == c || c == 0) return 1;
return 2;
}
if (b == 0){
if (c == 0 || a == c) return 1;
return 2;
}
if (c == 0){
if (a == b) return 1;
return 2;
}
if (a == b && a == c) return 1;
if (a == b || b == c || a == c) return 2;
return 3;
}
void operation(int i, int x){
for (int p = 0; p < 4; ++p){
for (int q = 0; q < 4; ++q){
for (int r = 0; r < 4; ++r){
for (int s = 0; s < 4; ++s){
dp[i][q][x][r][s] = max(dp[i][q][x][r][s],
dp[i - 1][p][q][r][s] + distinct(p, q, x));
dp[i][p][q][s][x] = max(dp[i][p][q][s][x],
dp[i - 1][p][q][r][s] + distinct(r, s, x));
}
}
}
}
}
void Init(){
cin >> n;
cin >> s;
for (int i = 0; i <= n; ++i){
for (int p = 0; p < 4; ++p){
for (int q = 0; q < 4; ++q){
for (int r = 0; r < 4; ++r){
for (int s = 0; s < 4; ++s) dp[i][p][q][r][s] = INT_MIN;
}
}
}
}
dp[0][0][0][0][0] = 0;
for (int i = 1; i <= n; ++i){
if (s[i - 1] == 'M') operation(i, 1);
if (s[i - 1] == 'F') operation(i, 2);
if (s[i - 1] == 'B') operation(i, 3);
}
int ans = 0;
for (int p = 0; p < 4; ++p){
for (int q = 0; q < 4; ++q){
for (int r = 0; r < 4; ++r){
for (int s = 0; s < 4; ++s){
ans = max(ans, dp[n][p][q][r][s]);
}
}
}
}
cout << ans;
}
int main(){
if (fopen(taskname".txt", "r")){
freopen(taskname".txt", "r", stdin);
}
faster
//freopen(taskname.inp, "r", stdin)
//freopen(taskname.out, "w", stdout)
Init();
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int main()':
miners.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(taskname".txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |