Submission #895578

# Submission time Handle Problem Language Result Execution time Memory
895578 2023-12-30T10:34:03 Z hariaakas646 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
100 / 100
55 ms 41304 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t);
#define forr(i, l, r) for(int i=l; i<r; i++)
#define frange(i, l) forr(i, 0, l)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long lli;
typedef vector<vi> vvi;
typedef vector<lli> vll;
typedef vector<bool> vb;
typedef set<int> seti;

void usaco() {
	freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

lli inf = 1e18;

int main() {
	// usaco();
	int n;
	string str;
	cin >> n >> str;

	vi rv, gv, yv;
	rv.pb(0);
	gv.pb(0);
	yv.pb(0);
	int rc = 0, gc = 0, yc = 0;
	vi prr(n+1), prg(n+1), pry(n+1);

	str = ' ' + str;

	forr(i, 1, n+1) {
		prr[i] = prr[i-1];
		prg[i] = prg[i-1];
		pry[i] = pry[i-1];
		if(str[i] == 'R') {
			rc++;
			prr[i]++;
			rv.pb(i);
		}
		else if(str[i] == 'G') {
			gc++;
			prg[i]++;
			gv.pb(i);
		}
		else {
			yc++;
			pry[i]++;
			yv.pb(i);
		}
	}

	vector<vector<vvi>> dp(3, vector<vvi>(rc+1, vvi(gc+1, vi(yc+1, 2e9))));

	dp[0][0][0][0] = dp[1][0][0][0] = dp[2][0][0][0] = 0;

	forr(i, 0, rc+1) {
		forr(j, 0, gc+1) {
			forr(k, 0, yc+1) {
				if(i + j + k == 0) continue;
				frange(c, 3) {
					int v = 2e9;
					if(c == 0 && i > 0) {
						int tot = min(dp[1][i-1][j][k], dp[2][i-1][j][k]);
						tot += max(0, prg[rv[i]] - prg[gv[j]]) + max(0, pry[rv[i]] - pry[yv[k]]);
						v = min(v, tot);
					}
					if(c == 1 && j > 0) {
						int tot = min(dp[0][i][j-1][k], dp[2][i][j-1][k]);
						tot += max(0, prr[gv[j]] - prr[rv[i]]) + max(0, pry[gv[j]] - pry[yv[k]]);
						v = min(v, tot);
					}
					if(c == 2 && k > 0) {
						int tot = min(dp[0][i][j][k-1], dp[1][i][j][k-1]);
						tot += max(0, prr[yv[k]] - prr[rv[i]]) + max(0, prg[yv[k]] - prg[gv[j]]);
						v = min(v, tot);
					}
					dp[c][i][j][k] = v;
					// printf("%d ", v);
				}
			}
		}
	}
	int mi = 2e9;
	frange(i, 3) mi = min(mi, dp[i][rc][gc][yc]);
	if(mi < 2e9)
	printf("%d", mi);
	else printf("-1");
}

Compilation message

joi2019_ho_t3.cpp: In function 'void usaco()':
joi2019_ho_t3.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 432 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 9 ms 9320 KB Output is correct
3 Correct 9 ms 9052 KB Output is correct
4 Correct 9 ms 9112 KB Output is correct
5 Correct 9 ms 9308 KB Output is correct
6 Correct 9 ms 9128 KB Output is correct
7 Correct 9 ms 9052 KB Output is correct
8 Correct 9 ms 9248 KB Output is correct
9 Correct 9 ms 9048 KB Output is correct
10 Correct 10 ms 9304 KB Output is correct
11 Correct 10 ms 9308 KB Output is correct
12 Correct 3 ms 2652 KB Output is correct
13 Correct 5 ms 4440 KB Output is correct
14 Correct 6 ms 6744 KB Output is correct
15 Correct 10 ms 9332 KB Output is correct
16 Correct 9 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 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 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 432 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 9 ms 9320 KB Output is correct
44 Correct 9 ms 9052 KB Output is correct
45 Correct 9 ms 9112 KB Output is correct
46 Correct 9 ms 9308 KB Output is correct
47 Correct 9 ms 9128 KB Output is correct
48 Correct 9 ms 9052 KB Output is correct
49 Correct 9 ms 9248 KB Output is correct
50 Correct 9 ms 9048 KB Output is correct
51 Correct 10 ms 9304 KB Output is correct
52 Correct 10 ms 9308 KB Output is correct
53 Correct 3 ms 2652 KB Output is correct
54 Correct 5 ms 4440 KB Output is correct
55 Correct 6 ms 6744 KB Output is correct
56 Correct 10 ms 9332 KB Output is correct
57 Correct 9 ms 9308 KB Output is correct
58 Correct 53 ms 40796 KB Output is correct
59 Correct 54 ms 41304 KB Output is correct
60 Correct 52 ms 40024 KB Output is correct
61 Correct 54 ms 40796 KB Output is correct
62 Correct 11 ms 9048 KB Output is correct
63 Correct 14 ms 11420 KB Output is correct
64 Correct 30 ms 24668 KB Output is correct
65 Correct 39 ms 30812 KB Output is correct
66 Correct 52 ms 40272 KB Output is correct
67 Correct 54 ms 40296 KB Output is correct
68 Correct 55 ms 40272 KB Output is correct
69 Correct 53 ms 41304 KB Output is correct
70 Correct 54 ms 40796 KB Output is correct
71 Correct 52 ms 40284 KB Output is correct
72 Correct 14 ms 11144 KB Output is correct
73 Correct 3 ms 2904 KB Output is correct