답안 #567750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567750 2022-05-24T06:37:24 Z maomao90 Copy and Paste 3 (JOI22_copypaste3) C++17
25 / 100
3000 ms 43576 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)

template <class T>
bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;

#ifndef DEBUG
#define cerr if(0) cerr
#endif

const int MAXN = 2505;
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MOD[2] = {1000000007, 998244353};
const int X[2] = {29, 31};

int n;
string s;
int a, b, c;
int hsh[2][MAXN][MAXN];
int nxt[MAXN][MAXN];
ll dp[MAXN][MAXN];
unordered_map<ll, int> mp;

int main() {
#ifndef DEBUG
	ios::sync_with_stdio(0), cin.tie(0);
#endif
	cin >> n;
	cin >> s;
	cin >> a >> b >> c;
	REP (z, 0, 2) {
		REP (i, 0, n) {
			hsh[z][i][0] = 0;
			REP (j, 1, n + 1 - i) {
				hsh[z][i][j] = (ll) hsh[z][i][j - 1] * X[z] % MOD[z] + 
					(s[i + j - 1] - 'a' + 1);
				if (hsh[z][i][j] >= MOD[z]) {
					hsh[z][i][j] -= MOD[z];
				}
			}
		}
	}
	REP (l, 1, n + 1) {
		mp.clear();
		RREP (i, n - l, 0) {
			if (i + l <= n - l) {
				ll x = (ll) hsh[0][i + l][l] * MOD[1] + hsh[1][i + l][l];
				mp[x] = i + l;
			}
			ll x = (ll) hsh[0][i][l] * MOD[1] + hsh[1][i][l];
			if (mp.find(x) == mp.end()) {
				nxt[l][i] = n;
			} else {
				nxt[l][i] = mp[x];
			}
		}
	}
	RREP (i, n - 1, 0) {
		REP (j, i, n) {
			dp[i][j] = min(dp[i + 1][j], dp[i][j - 1]) + a;
			REP (k, i, j) {
				ll cost = dp[i][k] + b;
				int len = k - i + 1;
				bool gpos = 1;
				{
					int l = j - len + 1;
					REP (m, 0, len) {
						if (s[i + m] != s[l + m]) {
							gpos = 0;
							break;
						}
					}
				}
				if (!gpos) {
					continue;
				}
				REP (l, i, j + 1) {
					bool pos = 1;
					if (l + len - 1 <= j) {
						REP (m, 0, len) {
							if (s[i + m] != s[l + m]) {
								pos = 0;
								break;
							}
						}
					} else {
						pos = 0;
					}
					if (pos) {
						l += len - 1;
						cost += c;
					} else {
						cost += a;
					}
				}
				mnto(dp[i][j], cost);
			}
			cerr << i << ' ' << j << ": " << dp[i][j] << '\n';
		}
	}
	cout << dp[0][n - 1] << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Execution timed out 3088 ms 43576 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1748 KB Output is correct
41 Correct 196 ms 3888 KB Output is correct
42 Correct 11 ms 3924 KB Output is correct
43 Correct 9 ms 3924 KB Output is correct
44 Correct 8 ms 3924 KB Output is correct
45 Correct 7 ms 3880 KB Output is correct
46 Correct 6 ms 3924 KB Output is correct
47 Correct 14 ms 3940 KB Output is correct
48 Correct 9 ms 3924 KB Output is correct
49 Correct 8 ms 3908 KB Output is correct
50 Correct 7 ms 3924 KB Output is correct
51 Correct 14 ms 3840 KB Output is correct
52 Correct 14 ms 3908 KB Output is correct
53 Correct 6 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 724 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 2 ms 1748 KB Output is correct
41 Correct 196 ms 3888 KB Output is correct
42 Correct 11 ms 3924 KB Output is correct
43 Correct 9 ms 3924 KB Output is correct
44 Correct 8 ms 3924 KB Output is correct
45 Correct 7 ms 3880 KB Output is correct
46 Correct 6 ms 3924 KB Output is correct
47 Correct 14 ms 3940 KB Output is correct
48 Correct 9 ms 3924 KB Output is correct
49 Correct 8 ms 3908 KB Output is correct
50 Correct 7 ms 3924 KB Output is correct
51 Correct 14 ms 3840 KB Output is correct
52 Correct 14 ms 3908 KB Output is correct
53 Correct 6 ms 3924 KB Output is correct
54 Correct 90 ms 9432 KB Output is correct
55 Execution timed out 3090 ms 20572 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Execution timed out 3088 ms 43576 KB Time limit exceeded
14 Halted 0 ms 0 KB -