답안 #1093392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093392 2024-09-26T18:26:55 Z ortsac Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
1 ms 444 KB
#include <bits/stdc++.h>

using namespace std;

#define fr first
#define se second

const int INF = 0x3f3f3f3f;

string blz = "RGY";
vector<int> s[3];
int val[3];

int32_t main() {
    //freopen("in", "r", stdin);
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        if (c == 'R') v[i] = 0;
        else if (c == 'G') v[i] = 1;
        else v[i] = 2;
    }
    // calc first batch
    for (int i = 0; i < 3; i++) {
        val[i] = INF;
        vector<int> x = v;
        for (int j = 0; j < n; j++) {
            if (v[j] == i) {
                x.erase(x.begin() + j);
                x.insert(x.begin(), i);
                val[i] = j;
                s[i] = x;
                break;
            }
        }
    }
    // calc all next ones
    for (int k = 1; k < n; k++) {
        vector<int> nVal(3, INF);
        vector<vector<int>> nS(3);
        for (int i = 0; i < 3; i++) {
            if (val[i] == INF) continue;
            for (int l = 0; l < 3; l++) {
                if (l == i) continue;
                vector<int> x = s[i];
                for (int j = k; j < n; j++) {
                    if (x[j] == l) {
                        int np = (val[i] + (j - k));
                        if (np < nVal[l]) {
                            x.erase(x.begin() + j);
                            x.insert(x.begin() + k, l);
                            nS[l] = x;
                            nVal[l] = np;
                        }
                        break;
                    }
                }
            }
        }
        for (int i = 0; i < 3; i++) {
            val[i] = nVal[i];
            s[i] = nS[i];
        }
    }
    // print ans
    int ans = min(val[0], min(val[1], val[2]));
    if (ans == INF) cout << "-1\n";
    else cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 432 KB Output is correct
3 Correct 1 ms 444 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -