Submission #1066768

#TimeUsernameProblemLanguageResultExecution timeMemory
1066768KasymKMiners (IOI07_miners)C++17
100 / 100
274 ms118356 KiB
#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 f(int x, int a1, int a2, int b1, int b2){ if(x == n) return 0; int &res = dp[x][a1][a2][b1][b2]; if(~res) return res; int m1 = val({a1, a2, a[x]}); int m2 = val({b1, b2, a[x]}); return res = max(f(x+1, a[x], a1, b1, b2)+m1, f(x+1, a1, a2, a[x], b1)+m2); } int main(){ memset(dp, -1, sizeof dp); 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; } int answer = f(0, 0, 0, 0, 0); printf("%d\n", answer); return 0; }

Compilation message (stderr)

miners.cpp: In function 'int main()':
miners.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
#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...