Submission #566203

# Submission time Handle Problem Language Result Execution time Memory
566203 2022-05-22T06:09:25 Z 8e7 Copy and Paste 3 (JOI22_copypaste3) C++17
Compilation error
0 ms 0 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 205
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
bool same[maxn][maxn][maxn];
int nxt[maxn][maxn];
ll dp[maxn][maxn][maxn][maxn];
int main() {
	io
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll A, B, C;
	cin >> A >> B >> C;
	ll ans = 3* A;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[0]) {
		ans = min(ans, A + B + 2 * C + A);
	}
	if (s[0] == s[1] && s[1] == s[2]) ans = min(ans, A + B + 3 * C);
	cout << ans << endl;
	return 0;
	for (int len = 1;len < n;len++) {
		for (int i = 0;i <= n - len;i++) {
			same[len][i][i] = 1;
			for (int j = i + 1;j <= n - len;j++) {
				if (s.substr(i, len) == s.substr(j, len)) {
					same[len][i][j] = same[len][j][i] = 1;
					if (!nxt[len][i]) nxt[len][i] = j;	
				}
			}
		}
	}
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= n;j++) {
			g[i][j] = inf;
			for (int k = 0;k <= n;k++) {
				for (int l = 0;l <= n;l++) dp[i][j][k][l] = inf;
			}
		}
	}
	ll ans = inf;
	dp[0][0][0][0] = 0;	
	auto to = [&] (int i, int j, int k,int l, ll v) {
		dp[i][j][k][l] = min(dp[i][j][k][l], v);
	};
	for (int len = 0;len <= n;len++) {
		for (int i = 0;i <= n - len;i++) {
			int j = i + len;
			for (int k = 0;k <= j - i + 1;k++) {
				if (dp[i][j][k] == inf) continue;
				to(i, j+1, 0, dp[i][j][k] + A);
				if (k && nxt[k][j - k] != 0) {
					to(i, nxt[k][j-k] + k, dp[i][j][k] + C + A * (nxt[k][j-k] - j));
				}
				g[i][j] = min(g[i][j], dp[i][j][k]);
			}
		}
	}
	
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:53:4: error: 'g' was not declared in this scope
   53 |    g[i][j] = inf;
      |    ^
copypaste3.cpp:59:5: error: redeclaration of 'long long int ans'
   59 |  ll ans = inf;
      |     ^~~
copypaste3.cpp:33:5: note: 'long long int ans' previously declared here
   33 |  ll ans = 3* A;
      |     ^~~
copypaste3.cpp:68:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   68 |     if (dp[i][j][k] == inf) continue;
      |         ~~~~~~~~~~~~^~~~~~
copypaste3.cpp:69:34: error: no match for call to '(main()::<lambda(int, int, int, int, long long int)>) (int&, int, int, long long int*)'
   69 |     to(i, j+1, 0, dp[i][j][k] + A);
      |                                  ^
copypaste3.cpp:61:12: note: candidate: 'main()::<lambda(int, int, int, int, long long int)>'
   61 |  auto to = [&] (int i, int j, int k,int l, ll v) {
      |            ^
copypaste3.cpp:61:12: note:   candidate expects 5 arguments, 4 provided
copypaste3.cpp:71:68: error: no match for call to '(main()::<lambda(int, int, int, int, long long int)>) (int&, int, long long int*)'
   71 |      to(i, nxt[k][j-k] + k, dp[i][j][k] + C + A * (nxt[k][j-k] - j));
      |                                                                    ^
copypaste3.cpp:61:12: note: candidate: 'main()::<lambda(int, int, int, int, long long int)>'
   61 |  auto to = [&] (int i, int j, int k,int l, ll v) {
      |            ^
copypaste3.cpp:61:12: note:   candidate expects 5 arguments, 3 provided
copypaste3.cpp:73:5: error: 'g' was not declared in this scope
   73 |     g[i][j] = min(g[i][j], dp[i][j][k]);
      |     ^