제출 #258637

#제출 시각아이디문제언어결과실행 시간메모리
258637HeheheMiners (IOI07_miners)C++14
100 / 100
233 ms201460 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define pi pair<long double, long double> #define sz(x) (int)((x).size()) //#define int long long const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll inf = 2e9; const ll mod = 1e9 + 7; const int N = 1e5 + 11; const ll INF64 = 3e18 + 1; const double eps = 1e-14; const double PI = acos(-1); //ifstream in(".in"); //ofstream out(".out"); int n, y[N]; string s; int dp[N][4][4][4][4], reach[N][4][4][4][4]; //dp[i][second last from the first mine][last from the first mine][second last from the second mne][last from the second mine] int val(int a, int b, int c){ int x = 0; for(int i = 1; i <= 3; i++){ if(i == a || i == b || i == c)x++; } return x; } void solve(){ cin >> n >> s; int ans = 0; s = '.' + s; for(int i = 1; i <= n; i++){ y[i] = (s[i] == 'B' ? 1 : (s[i] == 'F' ? 2 : 3)); } reach[0][0][0][0][0] = 1; for(int i = 1; i <= n; i++){ int x = y[i]; for(int a = 0; a < 4; a++){ for(int b = 0; b < 4; b++){ for(int c = 0; c < 4; c++){ for(int d = 0; d < 4; d++){ if(!reach[i - 1][a][b][c][d])continue; reach[i][x][a][c][d] = 1; reach[i][a][b][x][c] = 1; dp[i][x][a][c][d] = max(dp[i][x][a][c][d], dp[i - 1][a][b][c][d] + val(x, a, b)); dp[i][a][b][x][c] = max(dp[i][a][b][x][c], dp[i - 1][a][b][c][d] + val(x, c, d)); ans = max(ans, dp[i][a][b][x][c]); ans = max(ans, dp[i][x][a][c][d]); } } } } } cout << ans << '\n'; } int32_t main(){ ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); //cout << setprecision(6) << fixed; int T = 1; //cin >> T; while(T--){ solve(); } }
#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...