# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
54603 | imeimi2000 | Miners (IOI07_miners) | C++17 | 87 ms | 704 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
const int inf = 1e8;
int tr[256];
int dp1[16][16];
int dp2[16][16];
int nxt[16][4];
int cnt[16][4];
pii getCoal(int x, int p) {
static int cnt[4];
cnt[1] = cnt[2] = cnt[3] = 0;
int nxt = (x << 2 | p) & 15;
cnt[p] = 1;
cnt[x & 3] = 1;
cnt[x >> 2] = 1;
return pii(nxt, cnt[1] + cnt[2] + cnt[3]);
}
int imax(int x, int y) {
return x < y ? y : x;
}
int n;
char str[100001];
int main() {
tr['M'] = 1;
tr['F'] = 2;
tr['B'] = 3;
for (int i = 0; i < 16; ++i) {
for (int j = 1; j <= 3; ++j) {
tie(nxt[i][j], cnt[i][j]) = getCoal(i, j);
}
}
scanf("%d%s", &n, str);
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
dp1[i][j] = -inf;
dp2[i][j] = -inf;
}
}
dp1[0][0] = 0;
for (int it = 0; it < n; ++it) {
int i = tr[str[it]];
for (int j = 0; j < 16; ++j) {
for(int k = 0; k < 16; ++k) {
if (dp1[j][k] < 0) continue;
dp2[nxt[j][i]][k] = imax(dp2[nxt[j][i]][k], dp1[j][k] + cnt[j][i]);
dp2[j][nxt[k][i]] = imax(dp2[j][nxt[k][i]], dp1[j][k] + cnt[k][i]);
}
}
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
dp1[j][k] = dp2[j][k];
dp2[j][k] = -inf;
}
}
}
int ans = 0;
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
ans = imax(ans, dp1[i][j]);
}
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (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... |