이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 1e5+5;
int nw[26], A[3], vis[N];
pair<int,pii> dp[N][5];
int T(char c){
if (c == 'M') return 0;
if (c == 'B') return 1;
return 2;
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
int mx = 0, x = 0, y = 0;
for (int i = 1; i < n; i++){
for (int j = i-1; j >= 0; j--){
int p = T(s[j]);
for (int k = 0; k < 3; k++){
if (dp[j][k].ff == 0) continue;
A[k] = 1;
A[T(s[i])] = 1;
A[p] = 1;
int cnt = (A[0]+A[1]+A[2]);
if (dp[i][p].ff < cnt+dp[j][k].ff){
dp[i][p] = {cnt+dp[j][k].ff, {j, k}};
}
A[0] = A[1] = A[2] = 0;
}
if (dp[i][p].ff < (s[i]!=s[j])+2){
dp[i][p] = {(s[i]!=s[j])+2, {j, -1e9}};
}
if (mx <= dp[i][p].ff){
mx = dp[i][p].ff;
x = i;
y = p;
}
}
}
int ans = 0;
ans += mx;
while(1){
vis[x] = 1;
if (x == 0) break;
int new_x, new_y;
new_x = dp[x][y].ss.ff;
new_y = dp[x][y].ss.ss;
x = new_x;
y = new_y;
}
string str = "";
for (int i = 0; i < n; i++) if (vis[i] == 0) str += s[i];
for (int i = 0; i < str.size(); i++){
for (int j = i; j > max(i-3, -1); j--){
A[T(str[j])] = 1;
}
ans += A[0]+A[1]+A[2];
A[0] = A[1] = A[2] = 0;
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int main()':
miners.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int i = 0; i < str.size(); i++){
| ~~^~~~~~~~~~~~
# | 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... |