이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
int a[N], dp[N][4][4][4][4], n;
string s;
int val(vector<int> v){
int o = 0, o_ = 0, o__ = 0;
for(int &i : v){
if(i == 1)
o = 1;
else if(i == 2)
o_ = 1;
else if(i == 3)
o__ = 1;
}
return (o + o_ + o__);
}
int main(){
scanf("%d", &n);
cin >> s;
for(int i = 0; i < n; ++i){
if(s[i] == 'M')
a[i] = 1;
else if(s[i] == 'B')
a[i] = 2;
else
a[i] = 3;
}
for(int x = n-1; x >= 0; --x)
for(int a1 = 0; a1 <= 3; ++a1)
for(int a2 = 0; a2 <= 3; ++a2)
for(int b1 = 0; b1 <= 3; ++b1)
for(int b2 = 0; b2 <= 3; ++b2){
int m1 = val({a1, a2, a[x]});
int m2 = val({b1, b2, a[x]});
dp[x][a1][a2][b1][b2] = max(dp[x+1][a[x]][a1][b1][b2]+m1,
dp[x+1][a1][a2][a[x]][b1]+m2);
}
int answer = dp[0][0][0][0][0];
printf("%d\n", answer);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int main()':
miners.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | 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... |