Submission #887507

# Submission time Handle Problem Language Result Execution time Memory
887507 2023-12-14T16:41:56 Z MinaRagy06 Copy and Paste 3 (JOI22_copypaste3) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int a, b, c;
	cin >> a >> b >> c;
	bool cmp[n][n]{};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j + i < n; j++) {
			cmp[i][j] = (0 <= i - 1? cmp[i - 1][j] : 1) && (s[i] == s[j + i]);
		}
	}
	ll dp[n + 1]{};
	for (int i = 0; i <= n; i++) {
		dp[i] = 1e18;
	}
	for (int i = n - 1; i >= 0; i--) {
		dp[i] = dp[i + 1] + a;
		ll dp2[n + 1]{};
		for (int j = n - 1; j >= 0; j--) {
			dp2[j] = min(dp2[j + 1] + a, dp[j]);
			if (i - 1 >= 0 && cmp[i - 1][j] && j + i + 1 < n) {
				dp2[j] = min(dp2[j], dp2[j + i + 1] + c);
			}
		}
		dp[i] = min(dp[i], dp2[0] + b);
	}
	cout << dp[0] << '\n';
	return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -