Submission #881586

# Submission time Handle Problem Language Result Execution time Memory
881586 2023-12-01T14:40:54 Z tsumondai Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
1 ms 6492 KB
#include <bits/stdc++.h>
using namespace std;

#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 = 1e9, mod = 1e9 + 7;
 
int n, m, k, p[3][N], 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);
		else if (s[i]=='G') g.pb(i);
		else 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;
 
        foru(l,0,2) 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(0, j-p[r[i-1]][1]) + max(0, 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(0, i-p[g[j-1]][0]) + max(0, 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(0, i-p[y[k-1]][0]) + max(0, 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:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #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:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #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:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #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 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 464 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 464 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 464 KB Output isn't correct
5 Halted 0 ms 0 KB -