Submission #1068258

#TimeUsernameProblemLanguageResultExecution timeMemory
1068258Halym2007Miners (IOI07_miners)C++17
100 / 100
245 ms111848 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define sz size() #define ff first #define ss second #define pb push_back #define pii pair <char, int> const int N = 1e5 + 5; int dp[N][4][4][4][4], n; string s; int jogap (int x, int y, int z) { int ret = 0; vector <int> v(4, 0); v[x] = 1;v[y] = 1;v[z] = 1; ret = v[1] + v[2] + v[3]; return ret; } int solve (int idx, int x, int y, int x1, int y1) { if (idx == n + 1) { return 0; } if (~dp[idx][x][y][x1][y1]) return dp[idx][x][y][x1][y1]; int val = 0; if (s[idx] == 'F') val = 1; else if (s[idx] == 'M') val = 2; else val = 3; int ans1 = solve(idx + 1, y, val, x1, y1) + jogap(x, y, val), ans2 = solve (idx + 1, x, y, y1, val) + jogap (x1, y1, val); return dp[idx][x][y][x1][y1] = max (ans1, ans2); } int main () { // freopen ("input.txt", "r", stdin); ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> s; s = " " + s; memset (dp, -1, sizeof(dp)); cout << solve (1, 0, 0, 0, 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...