Submission #241036

# Submission time Handle Problem Language Result Execution time Memory
241036 2020-06-22T09:33:13 Z aggu_01000101 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
75 / 100
500 ms 757624 KB
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    const int N = n+1;
    int dp[N][N][N][3];
    int g[3][N];
    int cc[] = {0, 0, 0};
    int cmp[N][3];
    if(n==1){
        cout<<0<<"\n";
        return 0;
    }
    char c;
    for(int i = 1;i<=n;i++){
        cmp[i][0] = cc[0];
        cmp[i][1] = cc[1];
        cmp[i][2] = cc[2];
        cin>>c;
        if(c=='R') g[0][cc[0]++] = i;
        else if(c=='G') g[1][cc[1]++] = i;
        else g[2][cc[2]++] = i;
    }
    memset(dp , INF , sizeof(dp)) ;
    for(int i = n-1;i>=1;i--){
        for(int aused = n;aused>=0;aused--){
            for(int bused = n;bused >= 0 ;bused--){
                int cused = i - (aused + bused);
                int ause = INF, buse = INF, cuse = INF;
                if(aused>cc[0] || bused>cc[1] || cused>cc[2]) continue;
                if(cused<0) continue;
                int currind;
                //calculate use[0]
                if(cc[0] > aused) {
                    currind = g[0][aused] + max((int) 0, bused - cmp[g[0][aused]][1]) +
                              max((int) 0, cused - cmp[g[0][aused]][2]);
                    ause = (currind - (i + 1));
                    if(i<n-1) ause += dp[i + 1][aused + 1][bused][0];
                }
                //calculate buse
                if(cc[1] > bused) {
                    currind = g[1][bused] + max((int) 0, aused - cmp[g[1][bused]][0]) +
                              max((int) 0, cused - cmp[g[1][bused]][2]);
                    buse = (currind - (i + 1));
                    if(i<n-1) buse += dp[i + 1][aused][bused + 1][1];
                }
                //calculate cuse
                if(cc[2] > cused) {
                    currind = g[2][cused] + max((int) 0, aused - cmp[g[2][cused]][0]) +
                              max((int) 0, bused - cmp[g[2][cused]][1]);
                    cuse = (currind - (i + 1));
                    if(i<n-1) cuse += dp[i + 1][aused][bused][2];
                }
 
                dp[i][aused][bused][0] = min(buse, cuse);
                dp[i][aused][bused][1] = min(ause, cuse);
                dp[i][aused][bused][2] = min(buse, ause);
            }
        }
    }
    int ans = INF;
    if(cc[0]) {
        ans = min(ans, (g[0][0] - 1) + dp[1][1][0][0]);
    }
    if(cc[1]) {
        ans = min(ans, (g[1][0] - 1) + dp[1][0][1][1]);
    }
    if(cc[2]) {
        ans = min(ans, (g[2][0] - 1) + dp[1][0][0][2]);
    }
    if(ans>=INF) ans = -1;
    cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 308 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 308 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 2944 KB Output is correct
19 Correct 6 ms 2944 KB Output is correct
20 Correct 6 ms 2944 KB Output is correct
21 Correct 7 ms 2944 KB Output is correct
22 Correct 6 ms 2944 KB Output is correct
23 Correct 6 ms 2944 KB Output is correct
24 Correct 6 ms 2944 KB Output is correct
25 Correct 6 ms 2944 KB Output is correct
26 Correct 6 ms 2944 KB Output is correct
27 Correct 6 ms 3052 KB Output is correct
28 Correct 6 ms 2944 KB Output is correct
29 Correct 6 ms 2944 KB Output is correct
30 Correct 7 ms 2944 KB Output is correct
31 Correct 6 ms 2944 KB Output is correct
32 Correct 7 ms 2944 KB Output is correct
33 Correct 6 ms 2816 KB Output is correct
34 Correct 6 ms 2816 KB Output is correct
35 Correct 6 ms 2688 KB Output is correct
36 Correct 7 ms 2944 KB Output is correct
37 Correct 6 ms 2560 KB Output is correct
38 Correct 7 ms 2944 KB Output is correct
39 Correct 6 ms 2944 KB Output is correct
40 Correct 6 ms 2816 KB Output is correct
41 Correct 6 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 464 ms 757496 KB Output is correct
3 Correct 424 ms 751840 KB Output is correct
4 Correct 430 ms 757496 KB Output is correct
5 Correct 466 ms 757496 KB Output is correct
6 Correct 457 ms 757624 KB Output is correct
7 Correct 427 ms 751736 KB Output is correct
8 Correct 446 ms 752032 KB Output is correct
9 Correct 414 ms 746104 KB Output is correct
10 Correct 439 ms 757496 KB Output is correct
11 Correct 437 ms 757496 KB Output is correct
12 Correct 74 ms 104440 KB Output is correct
13 Correct 163 ms 244576 KB Output is correct
14 Correct 251 ms 426208 KB Output is correct
15 Correct 436 ms 757496 KB Output is correct
16 Correct 435 ms 757496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 308 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 2944 KB Output is correct
19 Correct 6 ms 2944 KB Output is correct
20 Correct 6 ms 2944 KB Output is correct
21 Correct 7 ms 2944 KB Output is correct
22 Correct 6 ms 2944 KB Output is correct
23 Correct 6 ms 2944 KB Output is correct
24 Correct 6 ms 2944 KB Output is correct
25 Correct 6 ms 2944 KB Output is correct
26 Correct 6 ms 2944 KB Output is correct
27 Correct 6 ms 3052 KB Output is correct
28 Correct 6 ms 2944 KB Output is correct
29 Correct 6 ms 2944 KB Output is correct
30 Correct 7 ms 2944 KB Output is correct
31 Correct 6 ms 2944 KB Output is correct
32 Correct 7 ms 2944 KB Output is correct
33 Correct 6 ms 2816 KB Output is correct
34 Correct 6 ms 2816 KB Output is correct
35 Correct 6 ms 2688 KB Output is correct
36 Correct 7 ms 2944 KB Output is correct
37 Correct 6 ms 2560 KB Output is correct
38 Correct 7 ms 2944 KB Output is correct
39 Correct 6 ms 2944 KB Output is correct
40 Correct 6 ms 2816 KB Output is correct
41 Correct 6 ms 2944 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 464 ms 757496 KB Output is correct
44 Correct 424 ms 751840 KB Output is correct
45 Correct 430 ms 757496 KB Output is correct
46 Correct 466 ms 757496 KB Output is correct
47 Correct 457 ms 757624 KB Output is correct
48 Correct 427 ms 751736 KB Output is correct
49 Correct 446 ms 752032 KB Output is correct
50 Correct 414 ms 746104 KB Output is correct
51 Correct 439 ms 757496 KB Output is correct
52 Correct 437 ms 757496 KB Output is correct
53 Correct 74 ms 104440 KB Output is correct
54 Correct 163 ms 244576 KB Output is correct
55 Correct 251 ms 426208 KB Output is correct
56 Correct 436 ms 757496 KB Output is correct
57 Correct 435 ms 757496 KB Output is correct
58 Correct 460 ms 757496 KB Output is correct
59 Correct 466 ms 757388 KB Output is correct
60 Correct 492 ms 746232 KB Output is correct
61 Correct 478 ms 751992 KB Output is correct
62 Correct 432 ms 757496 KB Output is correct
63 Correct 445 ms 757616 KB Output is correct
64 Correct 458 ms 757624 KB Output is correct
65 Correct 453 ms 751864 KB Output is correct
66 Correct 451 ms 740680 KB Output is correct
67 Correct 495 ms 757472 KB Output is correct
68 Correct 462 ms 751864 KB Output is correct
69 Execution timed out 506 ms 757496 KB Time limit exceeded
70 Halted 0 ms 0 KB -