답안 #479745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479745 2021-10-13T03:26:00 Z lightseba Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
451 ms 757448 KB
// I'm a paragraph. Click here to add your own text and edit me. It’s easy. 
// Just click “Edit Text” or double click me to add your own content 
// and make changes to the font. Feel free to drag and drop me anywhere 
// you like on your page. I’m a great place for you to tell a story 
// and let your users know a little more about you.

#include <bits/stdc++.h>
using namespace std;
#define filename ""

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) ((int) size(x))
#define all(x) begin(x), end(x)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;

const int oo = 1e8;
const int N = 400 + 1;
int dp[N][N][N][3];
vi pos[3];

int go(int i, int j, int k, int c) {
    bool place0 = i < sz(pos[0]);
    bool place1 = j < sz(pos[1]);
    bool place2 = k < sz(pos[2]);

    if (!place0 && !place1 && !place2)  
        return 0;

    if (dp[i][j][k][c] != -1)
        return dp[i][j][k][c];
    
    place0 &= c != 0;
    place1 &= c != 1;
    place2 &= c != 2;

    int p = i + j + k;
    int ans = oo;

    if (place0) ans = min(ans, abs(p - pos[0][i]) + go(i + 1, j, k, 0));
    if (place1) ans = min(ans, abs(p - pos[1][j]) + go(i, j + 1, k, 1));
    if (place2) ans = min(ans, abs(p - pos[2][k]) + go(i, j, k + 1, 2));

    return dp[i][j][k][c] = ans;
}

void solve() {   
    memset(dp, -1, sizeof(dp));
    
    int n;
    string s;
    cin >> n >> s;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') pos[0].push_back(i);
        if (s[i] == 'G') pos[1].push_back(i);
        if (s[i] == 'Y') pos[2].push_back(i);
    }

    int ans = min(go(0, 0, 0, 0), go(0, 0, 0, 1));

    if (ans >= oo)
        ans = -2;

    cout << ans / 2 << "\n";
} 

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	// freopen(filename ".in", "r", stdin); freopen(filename ".out", "w", stdout); 

	// int t; cin >> t; while (t--)
	solve();

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 451 ms 757368 KB Output is correct
2 Correct 360 ms 757404 KB Output is correct
3 Correct 334 ms 757336 KB Output is correct
4 Correct 361 ms 757348 KB Output is correct
5 Correct 361 ms 757332 KB Output is correct
6 Correct 373 ms 757388 KB Output is correct
7 Correct 332 ms 757312 KB Output is correct
8 Correct 337 ms 757404 KB Output is correct
9 Correct 361 ms 757292 KB Output is correct
10 Correct 352 ms 757320 KB Output is correct
11 Incorrect 397 ms 757308 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 451 ms 757368 KB Output is correct
2 Correct 360 ms 757404 KB Output is correct
3 Correct 334 ms 757336 KB Output is correct
4 Correct 361 ms 757348 KB Output is correct
5 Correct 361 ms 757332 KB Output is correct
6 Correct 373 ms 757388 KB Output is correct
7 Correct 332 ms 757312 KB Output is correct
8 Correct 337 ms 757404 KB Output is correct
9 Correct 361 ms 757292 KB Output is correct
10 Correct 352 ms 757320 KB Output is correct
11 Incorrect 397 ms 757308 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 757384 KB Output is correct
2 Correct 357 ms 757332 KB Output is correct
3 Correct 345 ms 757340 KB Output is correct
4 Correct 357 ms 757416 KB Output is correct
5 Correct 349 ms 757396 KB Output is correct
6 Correct 341 ms 757404 KB Output is correct
7 Correct 346 ms 757364 KB Output is correct
8 Correct 329 ms 757432 KB Output is correct
9 Correct 346 ms 757332 KB Output is correct
10 Correct 325 ms 757336 KB Output is correct
11 Correct 328 ms 757448 KB Output is correct
12 Correct 337 ms 757340 KB Output is correct
13 Correct 345 ms 757448 KB Output is correct
14 Correct 331 ms 757312 KB Output is correct
15 Correct 355 ms 757444 KB Output is correct
16 Correct 312 ms 757344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 451 ms 757368 KB Output is correct
2 Correct 360 ms 757404 KB Output is correct
3 Correct 334 ms 757336 KB Output is correct
4 Correct 361 ms 757348 KB Output is correct
5 Correct 361 ms 757332 KB Output is correct
6 Correct 373 ms 757388 KB Output is correct
7 Correct 332 ms 757312 KB Output is correct
8 Correct 337 ms 757404 KB Output is correct
9 Correct 361 ms 757292 KB Output is correct
10 Correct 352 ms 757320 KB Output is correct
11 Incorrect 397 ms 757308 KB Output isn't correct
12 Halted 0 ms 0 KB -