Submission #881587

# Submission time Handle Problem Language Result Execution time Memory
881587 2023-12-01T14:49:35 Z tsumondai Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
76 ms 269064 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 4e2 + 5;
 
const int oo = 1e18, mod = 1e9 + 7;
 
int n, p[N][3], dp[N][N][N][3];
string s;
vector<int> r,g,y;

void process() {
	cin >> n;
	cin >> s;
	s=' ' + s;
	foru(i,1,n) {
		if (s[i]=='R') r.pb(i);
		if (s[i]=='G') g.pb(i);
		if (s[i]=='Y') y.pb(i);
		p[i][0] = r.size();
        p[i][1] = g.size();
        p[i][2] = y.size();
	}

	foru(i,0,r.size()) foru(j,0,g.size()) foru(k,0,y.size()) {
        if(!i && !j && !k) continue;
 
        for(int l=0;l<3;l++) dp[i][j][k][l] = oo;
 
        int u = i+j+k;
        if(i) dp[i][j][k][0] = min(dp[i-1][j][k][1], dp[i-1][j][k][2]) + ((r[i-1] + max(0ll, j-p[r[i-1]][1]) + max(0ll, k-p[r[i-1]][2])) - u);
        if(j) dp[i][j][k][1] = min(dp[i][j-1][k][0], dp[i][j-1][k][2]) + ((g[j-1] + max(0ll, i-p[g[j-1]][0]) + max(0ll, k-p[g[j-1]][2])) - u);
        if(k) dp[i][j][k][2] = min(dp[i][j][k-1][0], dp[i][j][k-1][1]) + ((y[k-1] + max(0ll, i-p[y[k-1]][0]) + max(0ll, j-p[y[k-1]][1])) - u);
    }

    int ans = *min_element(dp[r.size()][g.size()][y.size()], dp[r.size()][g.size()][y.size()]+3);
    cout << (ans >= oo ? -1 : ans);
    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI 
Flow:

*/

Compilation message

joi2019_ho_t3.cpp: In function 'void process()':
joi2019_ho_t3.cpp:9:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define foru(i, l, r) for(int i = l; i <= r; i++)
......
   38 |  foru(i,0,r.size()) foru(j,0,g.size()) foru(k,0,y.size()) {
      |       ~~~~~~~~~~~~                      
joi2019_ho_t3.cpp:38:2: note: in expansion of macro 'foru'
   38 |  foru(i,0,r.size()) foru(j,0,g.size()) foru(k,0,y.size()) {
      |  ^~~~
joi2019_ho_t3.cpp:9:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define foru(i, l, r) for(int i = l; i <= r; i++)
......
   38 |  foru(i,0,r.size()) foru(j,0,g.size()) foru(k,0,y.size()) {
      |                          ~~~~~~~~~~~~   
joi2019_ho_t3.cpp:38:21: note: in expansion of macro 'foru'
   38 |  foru(i,0,r.size()) foru(j,0,g.size()) foru(k,0,y.size()) {
      |                     ^~~~
joi2019_ho_t3.cpp:9:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define foru(i, l, r) for(int i = l; i <= r; i++)
......
   38 |  foru(i,0,r.size()) foru(j,0,g.size()) foru(k,0,y.size()) {
      |                                             ~~~~~~~~~~~~
joi2019_ho_t3.cpp:38:40: note: in expansion of macro 'foru'
   38 |  foru(i,0,r.size()) foru(j,0,g.size()) foru(k,0,y.size()) {
      |                                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 1 ms 10584 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 14808 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 4 ms 21016 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 1 ms 8616 KB Output is correct
16 Correct 5 ms 22876 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 1 ms 10584 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 14808 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 4 ms 21016 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 1 ms 8616 KB Output is correct
16 Correct 5 ms 22876 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 14 ms 51804 KB Output is correct
19 Correct 5 ms 43612 KB Output is correct
20 Correct 12 ms 57948 KB Output is correct
21 Correct 6 ms 47704 KB Output is correct
22 Correct 6 ms 52020 KB Output is correct
23 Correct 5 ms 41560 KB Output is correct
24 Correct 3 ms 25184 KB Output is correct
25 Correct 17 ms 86620 KB Output is correct
26 Correct 9 ms 72280 KB Output is correct
27 Correct 7 ms 64076 KB Output is correct
28 Correct 5 ms 49756 KB Output is correct
29 Correct 5 ms 49804 KB Output is correct
30 Correct 5 ms 41564 KB Output is correct
31 Correct 4 ms 35420 KB Output is correct
32 Correct 5 ms 43648 KB Output is correct
33 Correct 6 ms 60248 KB Output is correct
34 Correct 5 ms 51800 KB Output is correct
35 Correct 6 ms 53832 KB Output is correct
36 Correct 5 ms 45660 KB Output is correct
37 Correct 4 ms 31332 KB Output is correct
38 Correct 4 ms 33372 KB Output is correct
39 Correct 5 ms 45660 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 3 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 76 ms 259104 KB Output is correct
3 Correct 57 ms 261716 KB Output is correct
4 Correct 62 ms 262452 KB Output is correct
5 Correct 57 ms 262480 KB Output is correct
6 Correct 58 ms 262484 KB Output is correct
7 Correct 58 ms 265044 KB Output is correct
8 Correct 57 ms 266832 KB Output is correct
9 Correct 57 ms 266064 KB Output is correct
10 Correct 59 ms 267600 KB Output is correct
11 Correct 60 ms 267604 KB Output is correct
12 Correct 22 ms 157784 KB Output is correct
13 Correct 31 ms 187220 KB Output is correct
14 Correct 41 ms 218960 KB Output is correct
15 Correct 57 ms 267348 KB Output is correct
16 Correct 59 ms 267368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 1 ms 10584 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 2 ms 14808 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 4 ms 21016 KB Output is correct
11 Correct 1 ms 10588 KB Output is correct
12 Correct 1 ms 10588 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 2 ms 12636 KB Output is correct
15 Correct 1 ms 8616 KB Output is correct
16 Correct 5 ms 22876 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 14 ms 51804 KB Output is correct
19 Correct 5 ms 43612 KB Output is correct
20 Correct 12 ms 57948 KB Output is correct
21 Correct 6 ms 47704 KB Output is correct
22 Correct 6 ms 52020 KB Output is correct
23 Correct 5 ms 41560 KB Output is correct
24 Correct 3 ms 25184 KB Output is correct
25 Correct 17 ms 86620 KB Output is correct
26 Correct 9 ms 72280 KB Output is correct
27 Correct 7 ms 64076 KB Output is correct
28 Correct 5 ms 49756 KB Output is correct
29 Correct 5 ms 49804 KB Output is correct
30 Correct 5 ms 41564 KB Output is correct
31 Correct 4 ms 35420 KB Output is correct
32 Correct 5 ms 43648 KB Output is correct
33 Correct 6 ms 60248 KB Output is correct
34 Correct 5 ms 51800 KB Output is correct
35 Correct 6 ms 53832 KB Output is correct
36 Correct 5 ms 45660 KB Output is correct
37 Correct 4 ms 31332 KB Output is correct
38 Correct 4 ms 33372 KB Output is correct
39 Correct 5 ms 45660 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 3 ms 27228 KB Output is correct
42 Correct 1 ms 4440 KB Output is correct
43 Correct 76 ms 259104 KB Output is correct
44 Correct 57 ms 261716 KB Output is correct
45 Correct 62 ms 262452 KB Output is correct
46 Correct 57 ms 262480 KB Output is correct
47 Correct 58 ms 262484 KB Output is correct
48 Correct 58 ms 265044 KB Output is correct
49 Correct 57 ms 266832 KB Output is correct
50 Correct 57 ms 266064 KB Output is correct
51 Correct 59 ms 267600 KB Output is correct
52 Correct 60 ms 267604 KB Output is correct
53 Correct 22 ms 157784 KB Output is correct
54 Correct 31 ms 187220 KB Output is correct
55 Correct 41 ms 218960 KB Output is correct
56 Correct 57 ms 267348 KB Output is correct
57 Correct 59 ms 267368 KB Output is correct
58 Correct 55 ms 213332 KB Output is correct
59 Correct 71 ms 232336 KB Output is correct
60 Correct 59 ms 225164 KB Output is correct
61 Correct 60 ms 221596 KB Output is correct
62 Correct 59 ms 269064 KB Output is correct
63 Correct 60 ms 267608 KB Output is correct
64 Correct 66 ms 266068 KB Output is correct
65 Correct 75 ms 256340 KB Output is correct
66 Correct 57 ms 222532 KB Output is correct
67 Correct 55 ms 216324 KB Output is correct
68 Correct 61 ms 224592 KB Output is correct
69 Correct 69 ms 222920 KB Output is correct
70 Correct 64 ms 215120 KB Output is correct
71 Correct 63 ms 209844 KB Output is correct
72 Correct 30 ms 154708 KB Output is correct
73 Correct 3 ms 16988 KB Output is correct