Submission #403259

#TimeUsernameProblemLanguageResultExecution timeMemory
403259LoboMiners (IOI07_miners)C++17
100 / 100
1180 ms145460 KiB
#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; }

Compilation message (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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...