제출 #469457

#제출 시각아이디문제언어결과실행 시간메모리
469457flashmtMiners (IOI07_miners)C++17
100 / 100
578 ms604 KiB
#include <bits/stdc++.h> using namespace std; const int oo = 1 << 30; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m[256]; string s; cin >> n >> s; m['M'] = 0; m['F'] = 1; m['B'] = 2; auto cost = [&](int x, int y, int z) { return __builtin_popcount(1 << x | 1 << y | 1 << z); }; vector<vector<vector<vector<int>>>> f(4, vector<vector<vector<int>>>(4, vector<vector<int>>(4, vector<int>(4, -oo)))); f[3][3][3][3] = 0; for (int i = 0; i < n; i++) { int x = m[s[i]]; vector<vector<vector<vector<int>>>> newF(4, vector<vector<vector<int>>>(4, vector<vector<int>>(4, vector<int>(4, -oo)))); for (int p = 0; p < 10; p++) for (int q = 0; q < 10; q++) if (p != 9 || q != 9 || !i) { int a = p / 3, b = p % 3; int c = q / 3, d = q % 3; if (p == 9 && q == 9) newF[3][3][x][x] = newF[x][x][3][3] = 1; else if (p == 9) { newF[x][x][c][d] = max(newF[x][x][c][d], f[3][3][c][d] + 1); newF[3][3][d][x] = max(newF[3][3][d][x], f[3][3][c][d] + cost(c, d, x)); } else if (q == 9) { newF[a][b][x][x] = max(newF[a][b][x][x], f[a][b][3][3] + 1); newF[b][x][3][3] = max(newF[b][x][3][3], f[a][b][3][3] + cost(a, b, x)); } else { newF[b][x][c][d] = max(newF[b][x][c][d], f[a][b][c][d] + cost(a, b, x)); newF[a][b][d][x] = max(newF[a][b][d][x], f[a][b][c][d] + cost(c, d, x)); } } swap(f, newF); } int ans = n; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) for (int p = 0; p < 4; p++) for (int q = 0; q < 4; q++) ans = max(ans, f[i][j][p][q]); cout << ans << endl; }

컴파일 시 표준 에러 (stderr) 메시지

miners.cpp: In function 'int main()':
miners.cpp:25:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |     int x = m[s[i]];
      |                   ^
#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...