Submission #250732

# Submission time Handle Problem Language Result Execution time Memory
250732 2020-07-19T00:01:03 Z WhaleVomit Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
60 / 100
500 ms 384504 KB
#include <bits/stdc++.h>
using namespace std;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
 
#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)
 
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<
 
template<class T> bool ckmin(T& a, const T& b) {return b < a ? a = b, 1 : 0;}
template<class T> bool ckmax(T& a, const T& b) {return a < b ? a = b, 1 : 0;}
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
 
const int MAX_N = 404;
int n;
int arr[MAX_N];
int pref[MAX_N][3];
vi idxOf[3];
int dp[MAX_N][3][MAX_N][MAX_N];
 
int getcost(int c, int cnt0, int cnt1, int cnt2) { // cost to get the next c
    int idx = -1;
    if(c == 0) {
        if(cnt0 >= sz(idxOf[0])) return 1e8;
        idx = idxOf[c][cnt0];
    } else if(c == 1) {
        if(cnt1 >= sz(idxOf[1])) return 1e8;
        idx = idxOf[c][cnt1];
    } else {
        if(cnt2 >= sz(idxOf[2])) return 1e8;
        idx = idxOf[c][cnt2];
    }
    int res = idx;
    res -= min(cnt0, pref[idx][0]);
    res -= min(cnt1, pref[idx][1]);
    res -= min(cnt2, pref[idx][2]);
    return res;
}
 
int main() { FAST
    string s;
    cin >> n >> s;
    M00(i, n) {
        if(s[i] == 'R') arr[i] = 0;
        else if(s[i] == 'Y') arr[i] = 1;
        else arr[i] = 2;
    }
    M00(c, 3) {
        pref[0][c] = (arr[0] == c);
        MOO(i, 1, n) pref[i][c] = pref[i-1][c] + (arr[i] == c);
    }
    M00(i, n) idxOf[arr[i]].pb(i);
    M00(i, n) M00(j, n) if(i+j <= n-1) M00(k, 3) dp[n-1][k][i][j] = getcost(k, i, j, n-1-i-j);
    M00d(idx, n-1) {
        M00(c, 3) {
            for(int cnt0 = 0; cnt0 <= idx; cnt0++) {
                for(int cnt1 = 0; cnt1 <= idx-cnt0; cnt1++) {
                    int cnt2 = idx-cnt0-cnt1;
                    dp[idx][c][cnt0][cnt1] = 1e8;
                    int cost = getcost(c, cnt0, cnt1, cnt2);

                    int cnt20 = cnt0; if(c == 0) cnt20++;
                    int cnt21 = cnt1; if(c == 1) cnt21++;
                    M00(c2, 3) if(c2 != c) {
                        ckmin(dp[idx][c][cnt0][cnt1], cost + dp[idx+1][c2][cnt20][cnt21]);
                    }
                }
            }
        }
    }
    int res = 1e8;
    M00(i, 3) ckmin(res, dp[0][i][0][0]);
    if(res == 1e8) {
        finish(-1);
    }
    finish(res);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 768 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 1 ms 1024 KB Output is correct
12 Correct 1 ms 1024 KB Output is correct
13 Correct 1 ms 1024 KB Output is correct
14 Correct 1 ms 1024 KB Output is correct
15 Correct 1 ms 1024 KB Output is correct
16 Correct 1 ms 1024 KB Output is correct
17 Correct 1 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 768 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 1 ms 1024 KB Output is correct
12 Correct 1 ms 1024 KB Output is correct
13 Correct 1 ms 1024 KB Output is correct
14 Correct 1 ms 1024 KB Output is correct
15 Correct 1 ms 1024 KB Output is correct
16 Correct 1 ms 1024 KB Output is correct
17 Correct 1 ms 1024 KB Output is correct
18 Correct 6 ms 9728 KB Output is correct
19 Correct 6 ms 9600 KB Output is correct
20 Correct 6 ms 9728 KB Output is correct
21 Correct 6 ms 9728 KB Output is correct
22 Correct 6 ms 9728 KB Output is correct
23 Correct 6 ms 9600 KB Output is correct
24 Correct 6 ms 9728 KB Output is correct
25 Correct 7 ms 9728 KB Output is correct
26 Correct 5 ms 9728 KB Output is correct
27 Correct 8 ms 9728 KB Output is correct
28 Correct 7 ms 9728 KB Output is correct
29 Correct 5 ms 9728 KB Output is correct
30 Correct 8 ms 9600 KB Output is correct
31 Correct 8 ms 9728 KB Output is correct
32 Correct 8 ms 9728 KB Output is correct
33 Correct 6 ms 9344 KB Output is correct
34 Correct 6 ms 9344 KB Output is correct
35 Correct 7 ms 9088 KB Output is correct
36 Correct 5 ms 9344 KB Output is correct
37 Correct 5 ms 8832 KB Output is correct
38 Correct 6 ms 9728 KB Output is correct
39 Correct 8 ms 9728 KB Output is correct
40 Correct 5 ms 9344 KB Output is correct
41 Correct 5 ms 9600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 416 ms 384504 KB Output is correct
3 Correct 425 ms 382560 KB Output is correct
4 Correct 440 ms 384480 KB Output is correct
5 Execution timed out 632 ms 384504 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 768 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 1 ms 1024 KB Output is correct
12 Correct 1 ms 1024 KB Output is correct
13 Correct 1 ms 1024 KB Output is correct
14 Correct 1 ms 1024 KB Output is correct
15 Correct 1 ms 1024 KB Output is correct
16 Correct 1 ms 1024 KB Output is correct
17 Correct 1 ms 1024 KB Output is correct
18 Correct 6 ms 9728 KB Output is correct
19 Correct 6 ms 9600 KB Output is correct
20 Correct 6 ms 9728 KB Output is correct
21 Correct 6 ms 9728 KB Output is correct
22 Correct 6 ms 9728 KB Output is correct
23 Correct 6 ms 9600 KB Output is correct
24 Correct 6 ms 9728 KB Output is correct
25 Correct 7 ms 9728 KB Output is correct
26 Correct 5 ms 9728 KB Output is correct
27 Correct 8 ms 9728 KB Output is correct
28 Correct 7 ms 9728 KB Output is correct
29 Correct 5 ms 9728 KB Output is correct
30 Correct 8 ms 9600 KB Output is correct
31 Correct 8 ms 9728 KB Output is correct
32 Correct 8 ms 9728 KB Output is correct
33 Correct 6 ms 9344 KB Output is correct
34 Correct 6 ms 9344 KB Output is correct
35 Correct 7 ms 9088 KB Output is correct
36 Correct 5 ms 9344 KB Output is correct
37 Correct 5 ms 8832 KB Output is correct
38 Correct 6 ms 9728 KB Output is correct
39 Correct 8 ms 9728 KB Output is correct
40 Correct 5 ms 9344 KB Output is correct
41 Correct 5 ms 9600 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 416 ms 384504 KB Output is correct
44 Correct 425 ms 382560 KB Output is correct
45 Correct 440 ms 384480 KB Output is correct
46 Execution timed out 632 ms 384504 KB Time limit exceeded
47 Halted 0 ms 0 KB -