답안 #788798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788798 2023-07-20T15:57:33 Z anhduc2701 Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
374 ms 100784 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI acos(-1.0)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x, i) (1 & ((x) >> (i)))
#define MASK(x) (1LL << (x))
#define task "tnc"
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int mo = 998244353;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using pii = pair<pair<ll, ll>, ll>;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll n;
string s;
ll A, B, C;
ll z[2505][2505];
ll dp[2505][2505];
ll nxt[2505][2505];
signed main()
{
    cin.tie(0), cout.tie(0)->sync_with_stdio(0);
    //freopen("friends.out","w",stdout);
    cin >> n >> s;
    cin >> A >> B >> C;
    for (int i = 0; i < s.size(); i++)
    {
        int l = i;
        int r = i;
        for (int j = i + 1; j < s.size(); j++)
        {
            if (j < r)
            {
                z[i][j] = min(z[i][j - l + i], r - j);
            }
            while (j + z[i][j] < s.size() && s[j + z[i][j]] == s[i + z[i][j]])
            {
                z[i][j]++;
            }
            if (r < j + z[i][j])
            {
                l = j;
                r = j + z[i][j];
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        int l=i;
        for (int j = i; j < n; j++)
        {   
            if(l<=j) l=j+1;

            while(l<n && z[i][l]<j-i+1){

                l++;
            }
            nxt[i][j]=l;
            dp[i][j] = INF;
        }
    }
    
    for (int i = n - 1; i >= 0; i--)
    {
        dp[i][i] = A;
        for (int j = i; j < n; j++)
        {
            int len = j-i+1; 
            if(len>1){
                dp[i][j] = min({dp[i][j], dp[i + 1][j] + A, dp[i][j - 1] + A});
            }
            int last = i;
            int cnt=1;
            while(last<n){
                int r = nxt[last][last+len-1];
                
                if(r<n){
                    cnt++;
                    int en=r+len-1;
                    dp[i][en] = min(dp[i][en], dp[i][j] + B +  cnt * C + (en - i + 1 - cnt * len) * A);
                }
                
                last = r;
            }
        }
        // cout << "\n";
    }
    
    cout << dp[0][n - 1];
    
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:46:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
copypaste3.cpp:50:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j = i + 1; j < s.size(); j++)
      |                             ~~^~~~~~~~~~
copypaste3.cpp:56:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             while (j + z[i][j] < s.size() && s[j + z[i][j]] == s[i + z[i][j]])
      |                    ~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 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 Correct 161 ms 61516 KB Output is correct
4 Correct 194 ms 70016 KB Output is correct
5 Correct 235 ms 79504 KB Output is correct
6 Correct 301 ms 89672 KB Output is correct
7 Correct 346 ms 100784 KB Output is correct
8 Correct 374 ms 100784 KB Output is correct
9 Correct 344 ms 100780 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 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 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 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 588 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 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 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 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 588 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 1364 KB Output is correct
41 Correct 2 ms 3144 KB Output is correct
42 Correct 2 ms 3148 KB Output is correct
43 Correct 2 ms 3156 KB Output is correct
44 Correct 2 ms 3144 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 2 ms 3024 KB Output is correct
47 Correct 2 ms 3016 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 2 ms 3028 KB Output is correct
50 Correct 2 ms 3028 KB Output is correct
51 Correct 2 ms 3188 KB Output is correct
52 Correct 2 ms 3156 KB Output is correct
53 Correct 2 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 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 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 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 588 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 1364 KB Output is correct
41 Correct 2 ms 3144 KB Output is correct
42 Correct 2 ms 3148 KB Output is correct
43 Correct 2 ms 3156 KB Output is correct
44 Correct 2 ms 3144 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 2 ms 3024 KB Output is correct
47 Correct 2 ms 3016 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 2 ms 3028 KB Output is correct
50 Correct 2 ms 3028 KB Output is correct
51 Correct 2 ms 3188 KB Output is correct
52 Correct 2 ms 3156 KB Output is correct
53 Correct 2 ms 3028 KB Output is correct
54 Correct 6 ms 8076 KB Output is correct
55 Correct 35 ms 24116 KB Output is correct
56 Correct 19 ms 24032 KB Output is correct
57 Correct 18 ms 24004 KB Output is correct
58 Correct 16 ms 24020 KB Output is correct
59 Correct 16 ms 23880 KB Output is correct
60 Correct 18 ms 23564 KB Output is correct
61 Correct 15 ms 23760 KB Output is correct
62 Correct 28 ms 24020 KB Output is correct
63 Correct 15 ms 23764 KB Output is correct
64 Correct 16 ms 23744 KB Output is correct
65 Correct 23 ms 24020 KB Output is correct
66 Correct 19 ms 24016 KB Output is correct
67 Correct 17 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 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 Correct 161 ms 61516 KB Output is correct
14 Correct 194 ms 70016 KB Output is correct
15 Correct 235 ms 79504 KB Output is correct
16 Correct 301 ms 89672 KB Output is correct
17 Correct 346 ms 100784 KB Output is correct
18 Correct 374 ms 100784 KB Output is correct
19 Correct 344 ms 100780 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 1 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 596 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 588 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 1 ms 588 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 596 KB Output is correct
57 Correct 1 ms 1364 KB Output is correct
58 Correct 2 ms 3144 KB Output is correct
59 Correct 2 ms 3148 KB Output is correct
60 Correct 2 ms 3156 KB Output is correct
61 Correct 2 ms 3144 KB Output is correct
62 Correct 2 ms 3028 KB Output is correct
63 Correct 2 ms 3024 KB Output is correct
64 Correct 2 ms 3016 KB Output is correct
65 Correct 2 ms 3028 KB Output is correct
66 Correct 2 ms 3028 KB Output is correct
67 Correct 2 ms 3028 KB Output is correct
68 Correct 2 ms 3188 KB Output is correct
69 Correct 2 ms 3156 KB Output is correct
70 Correct 2 ms 3028 KB Output is correct
71 Correct 6 ms 8076 KB Output is correct
72 Correct 35 ms 24116 KB Output is correct
73 Correct 19 ms 24032 KB Output is correct
74 Correct 18 ms 24004 KB Output is correct
75 Correct 16 ms 24020 KB Output is correct
76 Correct 16 ms 23880 KB Output is correct
77 Correct 18 ms 23564 KB Output is correct
78 Correct 15 ms 23760 KB Output is correct
79 Correct 28 ms 24020 KB Output is correct
80 Correct 15 ms 23764 KB Output is correct
81 Correct 16 ms 23744 KB Output is correct
82 Correct 23 ms 24020 KB Output is correct
83 Correct 19 ms 24016 KB Output is correct
84 Correct 17 ms 23764 KB Output is correct
85 Correct 42 ms 48588 KB Output is correct
86 Correct 121 ms 100636 KB Output is correct
87 Correct 87 ms 100720 KB Output is correct
88 Correct 70 ms 100648 KB Output is correct
89 Correct 69 ms 100316 KB Output is correct
90 Correct 62 ms 99696 KB Output is correct
91 Correct 92 ms 100264 KB Output is correct
92 Correct 136 ms 100616 KB Output is correct
93 Correct 70 ms 99972 KB Output is correct
94 Correct 74 ms 100044 KB Output is correct
95 Correct 115 ms 100668 KB Output is correct
96 Correct 112 ms 100668 KB Output is correct
97 Correct 60 ms 99980 KB Output is correct