답안 #375989

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375989 2021-03-10T14:28:00 Z valerikk Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
460 ms 792192 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 407;

int dp[N][N][N][3];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<int> r, g, y;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R')
            r.push_back(i);
        if (s[i] == 'G')
            g.push_back(i);
        if (s[i] == 'Y')
            y.push_back(i);
    }
    int red = r.size(), green = g.size(), yellow = y.size();
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 0; i < 3; ++i)
        dp[0][0][0][i] = 0;
    for (int i = 0; i <= red; ++i) {
        for (int j = 0; j <= green; ++j) {
            for (int k = 0; k <= yellow; ++k) {
                for (int last = 0; last < 3; ++last) {
                    int pos = i + j + k;
                    int val = dp[i][j][k][last];
                    if (i < red && last != 0) dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], val + abs(pos - r[i]));
                    if (j < green && last != 1) dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1], val + abs(pos - g[j]));
                    if (k < yellow && last != 2) dp[i][j][k + 1][2] = min(dp[i][j][k + 1][2], val + abs(pos - y[k]));
                }
            }
        }
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0; i < 3; ++i)
        ans = min(ans, dp[red][green][yellow][i]);
    cout << ans / 2 << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 791916 KB Output is correct
2 Correct 460 ms 791892 KB Output is correct
3 Correct 411 ms 791916 KB Output is correct
4 Correct 412 ms 792172 KB Output is correct
5 Correct 414 ms 792192 KB Output is correct
6 Correct 413 ms 791916 KB Output is correct
7 Correct 417 ms 791916 KB Output is correct
8 Correct 418 ms 791916 KB Output is correct
9 Correct 414 ms 792044 KB Output is correct
10 Incorrect 409 ms 792044 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 791916 KB Output is correct
2 Correct 460 ms 791892 KB Output is correct
3 Correct 411 ms 791916 KB Output is correct
4 Correct 412 ms 792172 KB Output is correct
5 Correct 414 ms 792192 KB Output is correct
6 Correct 413 ms 791916 KB Output is correct
7 Correct 417 ms 791916 KB Output is correct
8 Correct 418 ms 791916 KB Output is correct
9 Correct 414 ms 792044 KB Output is correct
10 Incorrect 409 ms 792044 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 423 ms 791916 KB Output is correct
2 Correct 418 ms 791916 KB Output is correct
3 Correct 428 ms 791916 KB Output is correct
4 Correct 413 ms 791960 KB Output is correct
5 Correct 413 ms 792044 KB Output is correct
6 Correct 423 ms 791916 KB Output is correct
7 Correct 420 ms 792044 KB Output is correct
8 Correct 436 ms 791916 KB Output is correct
9 Correct 419 ms 792172 KB Output is correct
10 Correct 413 ms 791916 KB Output is correct
11 Correct 411 ms 792012 KB Output is correct
12 Correct 416 ms 792032 KB Output is correct
13 Correct 441 ms 792044 KB Output is correct
14 Correct 417 ms 792044 KB Output is correct
15 Incorrect 459 ms 791972 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 415 ms 791916 KB Output is correct
2 Correct 460 ms 791892 KB Output is correct
3 Correct 411 ms 791916 KB Output is correct
4 Correct 412 ms 792172 KB Output is correct
5 Correct 414 ms 792192 KB Output is correct
6 Correct 413 ms 791916 KB Output is correct
7 Correct 417 ms 791916 KB Output is correct
8 Correct 418 ms 791916 KB Output is correct
9 Correct 414 ms 792044 KB Output is correct
10 Incorrect 409 ms 792044 KB Output isn't correct
11 Halted 0 ms 0 KB -