# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
589812 | Zanite | Miners (IOI07_miners) | C++17 | 167 ms | 596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
const int INF = 2e9;
int N;
int shipments[maxN];
int dp[2][4][4][4][4];
inline void chmax(int &a, int b) {a = max(a, b);}
void resetDP(int i) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
for (int m = 0; m < 4; m++) {
dp[i][j][k][l][m] = -INF;
}
}
}
}
}
int main() {
scanf("%d", &N);
char _tmp;
for (int i = 1; i <= N; i++) {
scanf(" %c", &_tmp);
if (_tmp == 'M') {shipments[i] = 1;}
else if (_tmp == 'B') {shipments[i] = 2;}
else {shipments[i] = 3;}
}
resetDP(0);
dp[0][0][0][0][0] = 0;
for (int i = 0; i < N; i++) {
int cur = i & 1, nxt = cur ^ 1;
resetDP(nxt);
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
for (int m = 0; m < 4; m++) {
int A[4] = {}, B[4] = {};
A[j]++, A[k]++, B[l]++, B[m]++;
A[shipments[i+1]]++, B[shipments[i+1]]++;
int X = 0, Y = 0;
for (int i = 1; i <= 3; i++) {
if (A[i]) X++;
if (B[i]) Y++;
}
int D = dp[cur][j][k][l][m];
chmax(dp[nxt][k][shipments[i+1]][l][m], D + X);
chmax(dp[nxt][j][k][m][shipments[i+1]], D + Y);
}
}
}
}
}
int ans = -INF;
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
for (int m = 0; m < 4; m++) {
chmax(ans, dp[N & 1][j][k][l][m]);
}
}
}
}
printf("%d\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |