답안 #544544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544544 2022-04-02T09:31:49 Z benson1029 Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
2982 ms 348616 KB
#include<bits/stdc++.h>
using namespace std;

int n;
string s;
long long a,b,c;
long long dp[2505][2505];
int nxt[2505][2505];
unordered_map< long long, vector<int> > hashes[2505];
long long mod = 888888877777777LL;
long long inf = 1e18;

int main() {
	cin >> n;
	cin >> s;
	cin >> a >> b >> c; 
	for(int i=0; i<s.length(); i++) hashes[i].reserve(n); 
	for(int i=0; i<s.length(); i++) {
		long long tmp = 0;
		for(int j=i; j<s.length(); j++) {
			tmp = (tmp * 27 + s[j] - 'a' + 1) % mod;
			hashes[j-i][tmp].push_back(i);
			nxt[i][j] = -1;
			dp[i][j] = inf;
		}
	}
	for(int i=0; i<s.length(); i++) {
		long long tmp = 0;
		for(int j=i; j<s.length(); j++) {
			tmp = (tmp * 27 + s[j] - 'a' + 1) % mod;
			if(hashes[j-i][tmp].size() > 0) {
				int ptr = 0;
				for(int k=0; k<hashes[j-i][tmp].size(); k++) {
					while(ptr < hashes[j-i][tmp].size() && hashes[j-i][tmp][ptr] - hashes[j-i][tmp][k] < j-i+1) ptr++;
					if(ptr < hashes[j-i][tmp].size()) {
						nxt[hashes[j-i][tmp][k]][hashes[j-i][tmp][k]+j-i] = hashes[j-i][tmp][ptr];
					}
				}
				hashes[j-i][tmp].clear();
			}
		}
	}
	
	for(int sz=0; sz<s.length(); sz++) {
		for(int i=0; i<s.length()-sz; i++) {
			int j = i + sz;
			if(sz!=0) {
				dp[i][j] = min(dp[i][j], dp[i+1][j] + a);
				dp[i][j] = min(dp[i][j], dp[i][j-1] + a);
			} else dp[i][j] = a;
			int ptr = i;
			int cnt = 1;
			while(nxt[ptr][ptr+sz] != -1) {
				ptr = nxt[ptr][ptr+sz];
				cnt++;
				dp[i][ptr+sz] = min(dp[i][ptr+sz], dp[i][j] + b + c*cnt + a*(ptr+sz-i+1-cnt*(j-i+1)));
			}
		}
	}
	
	cout << dp[0][s.length()-1] << "\n";
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i=0; i<s.length(); i++) hashes[i].reserve(n);
      |               ~^~~~~~~~~~~
copypaste3.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i=0; i<s.length(); i++) {
      |               ~^~~~~~~~~~~
copypaste3.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for(int j=i; j<s.length(); j++) {
      |                ~^~~~~~~~~~~
copypaste3.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i=0; i<s.length(); i++) {
      |               ~^~~~~~~~~~~
copypaste3.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int j=i; j<s.length(); j++) {
      |                ~^~~~~~~~~~~
copypaste3.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int k=0; k<hashes[j-i][tmp].size(); k++) {
      |                  ~^~~~~~~~~~~~~~~~~~~~~~~~
copypaste3.cpp:34:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |      while(ptr < hashes[j-i][tmp].size() && hashes[j-i][tmp][ptr] - hashes[j-i][tmp][k] < j-i+1) ptr++;
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
copypaste3.cpp:35:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |      if(ptr < hashes[j-i][tmp].size()) {
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
copypaste3.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int sz=0; sz<s.length(); sz++) {
      |                ~~^~~~~~~~~~~
copypaste3.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for(int i=0; i<s.length()-sz; i++) {
      |                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 526 ms 70816 KB Output is correct
4 Correct 646 ms 80816 KB Output is correct
5 Correct 762 ms 92624 KB Output is correct
6 Correct 920 ms 106388 KB Output is correct
7 Correct 1106 ms 122064 KB Output is correct
8 Correct 1094 ms 122048 KB Output is correct
9 Correct 1095 ms 122180 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 1 ms 688 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 728 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 596 KB Output is correct
28 Correct 1 ms 596 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 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 0 ms 468 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 1 ms 688 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 728 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 596 KB Output is correct
28 Correct 1 ms 596 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 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 0 ms 468 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 2 ms 1496 KB Output is correct
41 Correct 6 ms 2772 KB Output is correct
42 Correct 8 ms 4004 KB Output is correct
43 Correct 8 ms 4052 KB Output is correct
44 Correct 8 ms 4168 KB Output is correct
45 Correct 8 ms 4164 KB Output is correct
46 Correct 8 ms 4180 KB Output is correct
47 Correct 6 ms 2976 KB Output is correct
48 Correct 7 ms 3416 KB Output is correct
49 Correct 8 ms 3660 KB Output is correct
50 Correct 7 ms 3792 KB Output is correct
51 Correct 8 ms 3412 KB Output is correct
52 Correct 9 ms 3416 KB Output is correct
53 Correct 8 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
21 Correct 1 ms 688 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 728 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 596 KB Output is correct
28 Correct 1 ms 596 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 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 0 ms 468 KB Output is correct
38 Correct 0 ms 468 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 2 ms 1496 KB Output is correct
41 Correct 6 ms 2772 KB Output is correct
42 Correct 8 ms 4004 KB Output is correct
43 Correct 8 ms 4052 KB Output is correct
44 Correct 8 ms 4168 KB Output is correct
45 Correct 8 ms 4164 KB Output is correct
46 Correct 8 ms 4180 KB Output is correct
47 Correct 6 ms 2976 KB Output is correct
48 Correct 7 ms 3416 KB Output is correct
49 Correct 8 ms 3660 KB Output is correct
50 Correct 7 ms 3792 KB Output is correct
51 Correct 8 ms 3412 KB Output is correct
52 Correct 9 ms 3416 KB Output is correct
53 Correct 8 ms 4184 KB Output is correct
54 Correct 53 ms 14424 KB Output is correct
55 Correct 130 ms 25196 KB Output is correct
56 Correct 320 ms 60920 KB Output is correct
57 Correct 331 ms 61308 KB Output is correct
58 Correct 319 ms 61260 KB Output is correct
59 Correct 331 ms 61408 KB Output is correct
60 Correct 316 ms 61384 KB Output is correct
61 Correct 211 ms 38988 KB Output is correct
62 Correct 133 ms 25676 KB Output is correct
63 Correct 276 ms 52088 KB Output is correct
64 Correct 273 ms 52548 KB Output is correct
65 Correct 267 ms 42196 KB Output is correct
66 Correct 254 ms 42268 KB Output is correct
67 Correct 354 ms 61608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 526 ms 70816 KB Output is correct
14 Correct 646 ms 80816 KB Output is correct
15 Correct 762 ms 92624 KB Output is correct
16 Correct 920 ms 106388 KB Output is correct
17 Correct 1106 ms 122064 KB Output is correct
18 Correct 1094 ms 122048 KB Output is correct
19 Correct 1095 ms 122180 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 0 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 0 ms 468 KB Output is correct
34 Correct 0 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 468 KB Output is correct
37 Correct 0 ms 468 KB Output is correct
38 Correct 1 ms 688 KB Output is correct
39 Correct 1 ms 724 KB Output is correct
40 Correct 1 ms 728 KB Output is correct
41 Correct 1 ms 724 KB Output is correct
42 Correct 1 ms 724 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 1 ms 596 KB Output is correct
46 Correct 1 ms 724 KB Output is correct
47 Correct 1 ms 724 KB Output is correct
48 Correct 1 ms 724 KB Output is correct
49 Correct 1 ms 724 KB Output is correct
50 Correct 1 ms 724 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 468 KB Output is correct
54 Correct 0 ms 468 KB Output is correct
55 Correct 0 ms 468 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 2 ms 1496 KB Output is correct
58 Correct 6 ms 2772 KB Output is correct
59 Correct 8 ms 4004 KB Output is correct
60 Correct 8 ms 4052 KB Output is correct
61 Correct 8 ms 4168 KB Output is correct
62 Correct 8 ms 4164 KB Output is correct
63 Correct 8 ms 4180 KB Output is correct
64 Correct 6 ms 2976 KB Output is correct
65 Correct 7 ms 3416 KB Output is correct
66 Correct 8 ms 3660 KB Output is correct
67 Correct 7 ms 3792 KB Output is correct
68 Correct 8 ms 3412 KB Output is correct
69 Correct 9 ms 3416 KB Output is correct
70 Correct 8 ms 4184 KB Output is correct
71 Correct 53 ms 14424 KB Output is correct
72 Correct 130 ms 25196 KB Output is correct
73 Correct 320 ms 60920 KB Output is correct
74 Correct 331 ms 61308 KB Output is correct
75 Correct 319 ms 61260 KB Output is correct
76 Correct 331 ms 61408 KB Output is correct
77 Correct 316 ms 61384 KB Output is correct
78 Correct 211 ms 38988 KB Output is correct
79 Correct 133 ms 25676 KB Output is correct
80 Correct 276 ms 52088 KB Output is correct
81 Correct 273 ms 52548 KB Output is correct
82 Correct 267 ms 42196 KB Output is correct
83 Correct 254 ms 42268 KB Output is correct
84 Correct 354 ms 61608 KB Output is correct
85 Correct 991 ms 144600 KB Output is correct
86 Correct 2825 ms 346896 KB Output is correct
87 Correct 2982 ms 347620 KB Output is correct
88 Correct 2709 ms 348092 KB Output is correct
89 Correct 2745 ms 348456 KB Output is correct
90 Correct 2660 ms 348420 KB Output is correct
91 Correct 1310 ms 136244 KB Output is correct
92 Correct 1217 ms 125336 KB Output is correct
93 Correct 2160 ms 274040 KB Output is correct
94 Correct 2262 ms 291516 KB Output is correct
95 Correct 1943 ms 227072 KB Output is correct
96 Correct 1946 ms 227012 KB Output is correct
97 Correct 2494 ms 348616 KB Output is correct