답안 #854090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854090 2023-09-26T06:12:21 Z denniskim Copy and Paste 3 (JOI22_copypaste3) C++17
15 / 100
3000 ms 37432 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll n;
char s[2510];
ll A, B, C;
ll dp[2510][2510];
ll je[2510];
ll nu[2510];
ll hs = 79;
ll ss = 1000000007;

ll sqrmtp(ll X, ll Y)
{
	ll ret = 1;
	
	while(Y)
	{
		if(Y & 1)
			ret = ret * X % ss;
		
		X = X * X % ss;
		Y >>= 1;
	}
	
	return ret;
}

ll f(ll L, ll R)
{
	ll ret = (nu[R] - nu[L - 1]) % ss * sqrmtp(je[L], ss - 2) % ss;
	return (ret % ss + ss) % ss;
}

ll comp(ll L1, ll R1, ll L2, ll R2)
{
	return f(L1, R1) == f(L2, R2);
}

int main(void)
{
	fastio
	
	cin >> n;
	
	for(ll i = 1 ; i <= n ; i++)
		cin >> s[i];
	
	cin >> A;
	cin >> B;
	cin >> C;
	
	je[0] = 1;
	
	for(ll i = 1 ; i <= n ; i++)
		je[i] = je[i - 1] * hs % ss;
	
	for(ll i = 1 ; i <= n ; i++)
		nu[i] = (nu[i - 1] + je[i] * (s[i] - 'a' + 1) % ss) % ss;
	
	for(ll i = 1 ; i <= n ; i++)
		dp[i][i] = A;
	
	for(ll L = 1 ; L < n ; L++)
	{
		for(ll i = 1 ; i <= n - L ; i++)
		{
			ll j = i + L;
			
			dp[i][j] = (L + 1) * A;
			dp[i][j] = min(dp[i][j], dp[i][j - 1] + A);
			
			for(ll k = 1 ; k <= L ; k++)
			{
				ll sum = 0;
				ll p = i;
				
				while(1)
				{
					if(p > j - k)
						break;
					
					if(p + k - 1 <= j - k)
					{
						if(comp(p, p + k - 1, j - k + 1, j))
						{
							p += k;
							sum += C;
						}
						
						else
						{
							p++;
							sum += A;
						}
					}
					
					else
					{
						p++;
						sum += A;
					}
				}
				
				dp[i][j] = min(dp[i][j], dp[j - k + 1][j] + B + sum + C);
			}
		}
	}
	
	cout << dp[1][n];
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Execution timed out 3029 ms 37432 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 4 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 8 ms 2392 KB Output is correct
22 Correct 14 ms 2396 KB Output is correct
23 Correct 15 ms 2392 KB Output is correct
24 Correct 16 ms 2552 KB Output is correct
25 Correct 16 ms 2392 KB Output is correct
26 Correct 16 ms 2392 KB Output is correct
27 Correct 11 ms 2392 KB Output is correct
28 Correct 10 ms 2392 KB Output is correct
29 Correct 15 ms 2392 KB Output is correct
30 Correct 14 ms 2508 KB Output is correct
31 Correct 14 ms 2556 KB Output is correct
32 Correct 13 ms 2396 KB Output is correct
33 Correct 16 ms 2392 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 8 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 4 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 8 ms 2392 KB Output is correct
22 Correct 14 ms 2396 KB Output is correct
23 Correct 15 ms 2392 KB Output is correct
24 Correct 16 ms 2552 KB Output is correct
25 Correct 16 ms 2392 KB Output is correct
26 Correct 16 ms 2392 KB Output is correct
27 Correct 11 ms 2392 KB Output is correct
28 Correct 10 ms 2392 KB Output is correct
29 Correct 15 ms 2392 KB Output is correct
30 Correct 14 ms 2508 KB Output is correct
31 Correct 14 ms 2556 KB Output is correct
32 Correct 13 ms 2396 KB Output is correct
33 Correct 16 ms 2392 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 8 ms 2392 KB Output is correct
40 Correct 849 ms 2536 KB Output is correct
41 Execution timed out 3019 ms 4588 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 4 ms 2396 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 8 ms 2392 KB Output is correct
22 Correct 14 ms 2396 KB Output is correct
23 Correct 15 ms 2392 KB Output is correct
24 Correct 16 ms 2552 KB Output is correct
25 Correct 16 ms 2392 KB Output is correct
26 Correct 16 ms 2392 KB Output is correct
27 Correct 11 ms 2392 KB Output is correct
28 Correct 10 ms 2392 KB Output is correct
29 Correct 15 ms 2392 KB Output is correct
30 Correct 14 ms 2508 KB Output is correct
31 Correct 14 ms 2556 KB Output is correct
32 Correct 13 ms 2396 KB Output is correct
33 Correct 16 ms 2392 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 8 ms 2392 KB Output is correct
40 Correct 849 ms 2536 KB Output is correct
41 Execution timed out 3019 ms 4588 KB Time limit exceeded
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 2392 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Execution timed out 3029 ms 37432 KB Time limit exceeded
14 Halted 0 ms 0 KB -