이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long INFll = 1e18;
const int INFii = 1e9;
const long long mod = (long long) 1e9 + 7;
typedef long long ll;
typedef int ii;
typedef double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define maxn 110000
//LEMBRAR DE MUDAR
ii n, s[maxn];
string S;
ii dp[maxn][4][4][4][4];
ii sol(ii i, ii a1, ii a2, ii b1, ii b2) {
if(i == n) return 0;
if(dp[i][a1][a2][b1][b2] != -1) return dp[i][a1][a2][b1][b2];
set<ii> st1;
if(a1 != 0) st1.insert(a1);
if(a2 != 0) st1.insert(a2);
st1.insert(s[i]);
ii p1 = st1.size();
set<ii> st2;
if(b1 != 0) st2.insert(b1);
if(b2 != 0) st2.insert(b2);
st2.insert(s[i]);
ii p2 = st2.size();
dp[i][a1][a2][b1][b2] = max(p1 + sol(i+1, s[i], a1, b1, b2), p2 + sol(i+1, a1, a2, s[i], b1));
return dp[i][a1][a2][b1][b2];
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
//freopen("in.in", "r", stdin);
//freopen("____.out", "w", stdout);
cin >> n;
cin >> S;
for(ii i = 0; i <= n; i++) {
for(ii a = 0; a <= 4; a++)
for(ii b = 0; b <= 4; b++)
for(ii c = 0; c <= 4; c++)
for(ii d = 0; d <= 4; d++)
dp[i][a][b][c][d] = -1;
}
for(ii i = 0; i < n; i++) {
if(S[i] == 'M') s[i] = 1;
if(S[i] == 'F') s[i] = 2;
if(S[i] == 'B') s[i] = 3;
}
cout << sol(0, 0, 0, 0, 0) << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
miners.cpp: In function 'int main()':
miners.cpp:62:43: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations]
62 | dp[i][a][b][c][d] = -1;
| ~~~~~~~~~~~~~~~~~~^~~~
miners.cpp:61:37: note: within this loop
61 | for(ii d = 0; d <= 4; d++)
| ~~^~~~
miners.cpp:62:43: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations]
62 | dp[i][a][b][c][d] = -1;
| ~~~~~~~~~~~~~~~~~~^~~~
miners.cpp:60:33: note: within this loop
60 | for(ii c = 0; c <= 4; c++)
| ~~^~~~
miners.cpp:62:41: warning: array subscript 4 is above array bounds of 'ii [4]' {aka 'int [4]'} [-Warray-bounds]
62 | dp[i][a][b][c][d] = -1;
| ~~~~~~~~~~~~~~~~^
# | 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... |