Submission #498024

# Submission time Handle Problem Language Result Execution time Memory
498024 2021-12-24T09:44:32 Z Ziel Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
23 ms 53124 KB
/**
 * LES GREATEABLES BRO TEAM
**/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");

string to_string(const string s) {
	return '"' + s + '"';
}
string to_string(const char c) {
 	return char(39) + string(1, c) + char(39);
}
string to_string(const char* s) {
 	return to_string(string(s));
}
string to_string(bool f) {
	return (f ? "true" : "false");
}
template<class A, class B>
string to_string(const pair<A, B> x) {
	return "(" + to_string(x.first) + ", " + to_string(x.second) + ")";
}
template<class A, class B, class C>
string to_string(const tuple<A, B, C> x) {
	return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ")";
}
template<class A, class B, class C, class D>
string to_string(const tuple<A, B, C, D> x) {
	return "(" + to_string(get<0>(x)) + ", " + to_string(get<1>(x)) + ", " + to_string(get<2>(x)) + ", " + to_string(get<3>(x)) + ")";
}
template<class T>
string to_string(const T v) {
	string res = "{"; bool f = true;
	for (auto x: v)
		res += (f ? to_string(x) : ", " + to_string(x)), f = false;
	return res + "}";
}
void debug_args() { cerr << "]\n"; }
template<class H, class... T>
void debug_args(H x, T... y) {
	cerr << to_string(x);
	if (sizeof... (y))
	cerr << ", ";
	debug_args(y...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: [", debug_args(__VA_ARGS__);
#else
#define debug(...) 47
#endif

const int N = 150;
int a1[N], b1[N], c1[N], dp[N][N][N][4];

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, y = 0, g = 0;
    vector<int> av, bv, cv;
    for (int i = 0; i < n; i++) {
    	if (s[i] == 'R') {
    		a1[i] = r++;
			av.push_back(i);
    	} else if (s[i] == 'Y') {
    		c1[i] = y++;
    		cv.push_back(i);
    	} else {
    		b1[i] = g++;
			bv.push_back(i);
    	}
    }
    memset(dp, 100000000, sizeof dp);
    for (int a = 0; a <= r; a++) {
    	for (int b = 0; b <= g; b++) {
    		for (int c = 0; c <= y; c++) {
    			if (a > 0) {
    				dp[a][b][c][0] = min(dp[a - 1][b][c][1], dp[a - 1][b][c][2]) + (av[a - 1] - a1[av[a - 1]]);
    			}
    			if (b > 0) {
    				dp[a][b][c][1] = min(dp[a][b - 1][c][0], dp[a][b - 1][c][2]) + (bv[b - 1] - b1[bv[b - 1]]);
    			}
    			if (c > 0) {
    				dp[a][b][c][2] = min(dp[a][b][c - 1][0], dp[a][b][c - 1][1]) + (cv[c - 1] - c1[cv[c - 1]]);
    			}
    		}
    	}
    }
    cout << min({dp[r][y][g][0], dp[r][y][g][1], dp[r][g][y][2]});
    debug(dp[1][0][0][0], dp[2][1][0][0], dp[2][1][0][1], dp[2][1][0][2]);
}

signed main() {
    setIO();
    
    int tt = 1;
    if (FLAG) {
    	cin >> tt;
    }
    while (tt--) {
    	solve();
    }
    
    return 0;
}

void setIO(const string &f) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen((f + ".in").c_str(), "r")) {
        freopen((f + ".in").c_str(), "r", stdin);
        freopen((f + ".out").c_str(), "w", stdout);
    }
}

Compilation message

joi2019_ho_t3.cpp: In function 'void solve()':
joi2019_ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
   57 | #define debug(...) 47
      |                    ^~
joi2019_ho_t3.cpp:99:5: note: in expansion of macro 'debug'
   99 |     debug(dp[1][0][0][0], dp[2][1][0][0], dp[2][1][0][1], dp[2][1][0][2]);
      |     ^~~~~
joi2019_ho_t3.cpp: In function 'void setIO(const string&)':
joi2019_ho_t3.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:121:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 53068 KB Output is correct
2 Correct 21 ms 53124 KB Output is correct
3 Correct 21 ms 53068 KB Output is correct
4 Incorrect 23 ms 53068 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 53068 KB Output is correct
2 Correct 21 ms 53124 KB Output is correct
3 Correct 21 ms 53068 KB Output is correct
4 Incorrect 23 ms 53068 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 53068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 53068 KB Output is correct
2 Correct 21 ms 53124 KB Output is correct
3 Correct 21 ms 53068 KB Output is correct
4 Incorrect 23 ms 53068 KB Output isn't correct
5 Halted 0 ms 0 KB -