Submission #580484

#TimeUsernameProblemLanguageResultExecution timeMemory
580484pragmatistMiners (IOI07_miners)C++17
100 / 100
180 ms101200 KiB
/*#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC target ("avx2") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops")*/ #include<bits/stdc++.h> #define sz(v) (int)v.size() #define ll long long #define pb push_back #define x first #define y second #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define nl "\n" using namespace std; using pii = pair<int, int>; const int N = (int)1e5 + 7; const int inf = (int)1e9 + 7; const ll INF = (ll)1e18 + 7; const ll MOD = (ll)998244353; pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int n, a[N], dp[N][4][4][4][4]; string s; void solve() { cin >> n >> s; for(int i = 1; i <= n; ++i) { if(s[i - 1] == 'M') a[i] = 1; if(s[i - 1] == 'F') a[i] = 2; if(s[i - 1] == 'B') a[i] = 3; for(int x = 0; x <= 3; ++x) { for(int y = 0; y <= 3; ++y) { for(int z = 0; z <= 3; ++z) { for(int w = 0; w <= 3; ++w) { dp[i][x][y][z][w] = -inf; } } } } } dp[1][0][a[1]][0][0] = 1; dp[1][0][0][0][a[1]] = 1; for(int i = 1; i < n; ++i) { for(int x = 0; x <= 3; ++x) { for(int y = 0; y <= 3; ++y) { for(int w = 0; w <= 3; ++w) { for(int z = 0; z <= 3; ++z) { int dis = (x != y) + (a[i + 1] != x && a[i + 1] != y) + 1; int sid = (w != z) + (a[i + 1] != w && a[i + 1] != z) + 1; dis -= (x == 0 || y == 0); sid -= (w == 0 || z == 0); dp[i + 1][y][a[i + 1]][w][z] = max(dp[i + 1][y][a[i + 1]][w][z], dp[i][x][y][w][z] + dis); dp[i + 1][x][y][z][a[i + 1]] = max(dp[i + 1][x][y][z][a[i + 1]], dp[i][x][y][w][z] + sid); } } } } } int ans = 0; for(int x = 0; x <= 3; ++x) { for(int y = 0; y <= 3; ++y) { for(int z = 0; z <= 3; ++z) { for(int w = 0; w <= 3; ++w) { ans = max(ans, dp[n][x][y][z][w]); } } } } cout << ans << nl; } signed main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int test = 1; //cin >> test; while(test--) { solve(); } return 0; }
#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...