Submission #586455

#TimeUsernameProblemLanguageResultExecution timeMemory
586455Do_you_copyMiners (IOI07_miners)C++14
100 / 100
177 ms100812 KiB
#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(); }

Compilation message (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 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...