답안 #771573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771573 2023-07-03T06:36:29 Z PoonYaPat Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
882 ms 49696 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;

int n;
string s;
ll dp[2505][2505],nxt[2505],a,b,c,qs[2505],mul[2505],inv;
const ll mod=1e9+7, hs=997;

ll power(ll a, ll n) {
    ll ans=1;
    while (n) {
        if (n%2==1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        n/=2;
    }
    return ans;
}

ll hsh(int l, int r) {
    return ((qs[r]-qs[l-1]+mod)%mod * power(inv,l-1))%mod;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    for (int i=1; i<=2500; ++i) for (int j=1; j<=2500; ++j) dp[i][j]=1e18;
    cin>>n>>s>>a>>b>>c;
    s=" "+s;

    mul[0]=1;
    inv=power(hs,mod-2);
    for (int i=1; i<n; ++i) mul[i]=(mul[i-1]*hs)%mod;
    for (int i=1; i<=n; ++i) qs[i]=(qs[i-1]+mul[i-1]*(s[i]-'a'))%mod;

    for (ll siz=1; siz<=n;  ++siz) {

        //find next
        map<ll,int> bef;
        queue<pii> q;
        memset(nxt,0,sizeof(nxt));

        for (int l=n-siz+1; l>=1; --l) {
            int r=l+siz-1;
            while (q.size()>=siz)  {
                bef[q.front().first]=q.front().second;
                q.pop();
            }
            nxt[l]=bef[hsh(l,r)];
            q.push(pii(hsh(l,r),l));
        }

        //find dp
        for (ll l=1; l+siz-1<=n; ++l) {
            ll r=l+siz-1;
            if (siz==1) dp[l][r]=a;
            else dp[l][r]=min({dp[l][r],dp[l][r-1]+a,dp[l+1][r]+a});

            ll nl=l,nr=r,cnt=0;
            while (nl) {
                ++cnt;
                dp[l][nr]=min(dp[l][nr],dp[l][r]+ ((nr-l+1)-siz*cnt)*a+b+c*cnt);
                nl=nxt[nl];
                nr=nl+siz-1;
            }
        }
    }
    cout<<dp[1][n];
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:45:28: warning: comparison of integer expressions of different signedness: 'std::queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   45 |             while (q.size()>=siz)  {
      |                    ~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49356 KB Output is correct
3 Correct 19 ms 49352 KB Output is correct
4 Correct 19 ms 49360 KB Output is correct
5 Correct 19 ms 49324 KB Output is correct
6 Correct 20 ms 49312 KB Output is correct
7 Correct 19 ms 49364 KB Output is correct
8 Correct 19 ms 49364 KB Output is correct
9 Correct 19 ms 49364 KB Output is correct
10 Correct 22 ms 49336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 20 ms 49308 KB Output is correct
3 Correct 298 ms 49492 KB Output is correct
4 Correct 371 ms 49408 KB Output is correct
5 Correct 436 ms 49396 KB Output is correct
6 Correct 534 ms 49364 KB Output is correct
7 Correct 614 ms 49400 KB Output is correct
8 Correct 657 ms 49364 KB Output is correct
9 Correct 617 ms 49420 KB Output is correct
10 Correct 19 ms 49380 KB Output is correct
11 Correct 22 ms 49364 KB Output is correct
12 Correct 19 ms 49324 KB Output is correct
13 Correct 18 ms 49292 KB Output is correct
14 Correct 19 ms 49308 KB Output is correct
15 Correct 20 ms 49316 KB Output is correct
16 Correct 19 ms 49364 KB Output is correct
17 Correct 20 ms 49364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49356 KB Output is correct
3 Correct 19 ms 49352 KB Output is correct
4 Correct 19 ms 49360 KB Output is correct
5 Correct 19 ms 49324 KB Output is correct
6 Correct 20 ms 49312 KB Output is correct
7 Correct 19 ms 49364 KB Output is correct
8 Correct 19 ms 49364 KB Output is correct
9 Correct 19 ms 49364 KB Output is correct
10 Correct 22 ms 49336 KB Output is correct
11 Correct 19 ms 49240 KB Output is correct
12 Correct 19 ms 49372 KB Output is correct
13 Correct 19 ms 49328 KB Output is correct
14 Correct 21 ms 49320 KB Output is correct
15 Correct 21 ms 49348 KB Output is correct
16 Correct 20 ms 49280 KB Output is correct
17 Correct 20 ms 49364 KB Output is correct
18 Correct 19 ms 49300 KB Output is correct
19 Correct 19 ms 49364 KB Output is correct
20 Correct 19 ms 49340 KB Output is correct
21 Correct 19 ms 49364 KB Output is correct
22 Correct 19 ms 49364 KB Output is correct
23 Correct 21 ms 49320 KB Output is correct
24 Correct 19 ms 49364 KB Output is correct
25 Correct 20 ms 49260 KB Output is correct
26 Correct 20 ms 49308 KB Output is correct
27 Correct 23 ms 49380 KB Output is correct
28 Correct 19 ms 49280 KB Output is correct
29 Correct 19 ms 49364 KB Output is correct
30 Correct 21 ms 49352 KB Output is correct
31 Correct 20 ms 49372 KB Output is correct
32 Correct 19 ms 49364 KB Output is correct
33 Correct 20 ms 49276 KB Output is correct
34 Correct 19 ms 49364 KB Output is correct
35 Correct 20 ms 49328 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49336 KB Output is correct
38 Correct 19 ms 49316 KB Output is correct
39 Correct 22 ms 49364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49356 KB Output is correct
3 Correct 19 ms 49352 KB Output is correct
4 Correct 19 ms 49360 KB Output is correct
5 Correct 19 ms 49324 KB Output is correct
6 Correct 20 ms 49312 KB Output is correct
7 Correct 19 ms 49364 KB Output is correct
8 Correct 19 ms 49364 KB Output is correct
9 Correct 19 ms 49364 KB Output is correct
10 Correct 22 ms 49336 KB Output is correct
11 Correct 19 ms 49240 KB Output is correct
12 Correct 19 ms 49372 KB Output is correct
13 Correct 19 ms 49328 KB Output is correct
14 Correct 21 ms 49320 KB Output is correct
15 Correct 21 ms 49348 KB Output is correct
16 Correct 20 ms 49280 KB Output is correct
17 Correct 20 ms 49364 KB Output is correct
18 Correct 19 ms 49300 KB Output is correct
19 Correct 19 ms 49364 KB Output is correct
20 Correct 19 ms 49340 KB Output is correct
21 Correct 19 ms 49364 KB Output is correct
22 Correct 19 ms 49364 KB Output is correct
23 Correct 21 ms 49320 KB Output is correct
24 Correct 19 ms 49364 KB Output is correct
25 Correct 20 ms 49260 KB Output is correct
26 Correct 20 ms 49308 KB Output is correct
27 Correct 23 ms 49380 KB Output is correct
28 Correct 19 ms 49280 KB Output is correct
29 Correct 19 ms 49364 KB Output is correct
30 Correct 21 ms 49352 KB Output is correct
31 Correct 20 ms 49372 KB Output is correct
32 Correct 19 ms 49364 KB Output is correct
33 Correct 20 ms 49276 KB Output is correct
34 Correct 19 ms 49364 KB Output is correct
35 Correct 20 ms 49328 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49336 KB Output is correct
38 Correct 19 ms 49316 KB Output is correct
39 Correct 22 ms 49364 KB Output is correct
40 Correct 23 ms 49340 KB Output is correct
41 Correct 21 ms 49364 KB Output is correct
42 Correct 23 ms 49332 KB Output is correct
43 Correct 24 ms 49272 KB Output is correct
44 Correct 25 ms 49280 KB Output is correct
45 Correct 23 ms 49364 KB Output is correct
46 Correct 23 ms 49308 KB Output is correct
47 Correct 22 ms 49364 KB Output is correct
48 Correct 25 ms 49300 KB Output is correct
49 Correct 22 ms 49348 KB Output is correct
50 Correct 23 ms 49308 KB Output is correct
51 Correct 22 ms 49364 KB Output is correct
52 Correct 22 ms 49340 KB Output is correct
53 Correct 23 ms 49284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49356 KB Output is correct
3 Correct 19 ms 49352 KB Output is correct
4 Correct 19 ms 49360 KB Output is correct
5 Correct 19 ms 49324 KB Output is correct
6 Correct 20 ms 49312 KB Output is correct
7 Correct 19 ms 49364 KB Output is correct
8 Correct 19 ms 49364 KB Output is correct
9 Correct 19 ms 49364 KB Output is correct
10 Correct 22 ms 49336 KB Output is correct
11 Correct 19 ms 49240 KB Output is correct
12 Correct 19 ms 49372 KB Output is correct
13 Correct 19 ms 49328 KB Output is correct
14 Correct 21 ms 49320 KB Output is correct
15 Correct 21 ms 49348 KB Output is correct
16 Correct 20 ms 49280 KB Output is correct
17 Correct 20 ms 49364 KB Output is correct
18 Correct 19 ms 49300 KB Output is correct
19 Correct 19 ms 49364 KB Output is correct
20 Correct 19 ms 49340 KB Output is correct
21 Correct 19 ms 49364 KB Output is correct
22 Correct 19 ms 49364 KB Output is correct
23 Correct 21 ms 49320 KB Output is correct
24 Correct 19 ms 49364 KB Output is correct
25 Correct 20 ms 49260 KB Output is correct
26 Correct 20 ms 49308 KB Output is correct
27 Correct 23 ms 49380 KB Output is correct
28 Correct 19 ms 49280 KB Output is correct
29 Correct 19 ms 49364 KB Output is correct
30 Correct 21 ms 49352 KB Output is correct
31 Correct 20 ms 49372 KB Output is correct
32 Correct 19 ms 49364 KB Output is correct
33 Correct 20 ms 49276 KB Output is correct
34 Correct 19 ms 49364 KB Output is correct
35 Correct 20 ms 49328 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49336 KB Output is correct
38 Correct 19 ms 49316 KB Output is correct
39 Correct 22 ms 49364 KB Output is correct
40 Correct 23 ms 49340 KB Output is correct
41 Correct 21 ms 49364 KB Output is correct
42 Correct 23 ms 49332 KB Output is correct
43 Correct 24 ms 49272 KB Output is correct
44 Correct 25 ms 49280 KB Output is correct
45 Correct 23 ms 49364 KB Output is correct
46 Correct 23 ms 49308 KB Output is correct
47 Correct 22 ms 49364 KB Output is correct
48 Correct 25 ms 49300 KB Output is correct
49 Correct 22 ms 49348 KB Output is correct
50 Correct 23 ms 49308 KB Output is correct
51 Correct 22 ms 49364 KB Output is correct
52 Correct 22 ms 49340 KB Output is correct
53 Correct 23 ms 49284 KB Output is correct
54 Correct 41 ms 49364 KB Output is correct
55 Correct 80 ms 49384 KB Output is correct
56 Correct 134 ms 49364 KB Output is correct
57 Correct 135 ms 49388 KB Output is correct
58 Correct 137 ms 49448 KB Output is correct
59 Correct 143 ms 49440 KB Output is correct
60 Correct 137 ms 49448 KB Output is correct
61 Correct 120 ms 49396 KB Output is correct
62 Correct 89 ms 49384 KB Output is correct
63 Correct 129 ms 49416 KB Output is correct
64 Correct 129 ms 49424 KB Output is correct
65 Correct 122 ms 49388 KB Output is correct
66 Correct 125 ms 49416 KB Output is correct
67 Correct 137 ms 49440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 49364 KB Output is correct
2 Correct 19 ms 49356 KB Output is correct
3 Correct 19 ms 49352 KB Output is correct
4 Correct 19 ms 49360 KB Output is correct
5 Correct 19 ms 49324 KB Output is correct
6 Correct 20 ms 49312 KB Output is correct
7 Correct 19 ms 49364 KB Output is correct
8 Correct 19 ms 49364 KB Output is correct
9 Correct 19 ms 49364 KB Output is correct
10 Correct 22 ms 49336 KB Output is correct
11 Correct 19 ms 49364 KB Output is correct
12 Correct 20 ms 49308 KB Output is correct
13 Correct 298 ms 49492 KB Output is correct
14 Correct 371 ms 49408 KB Output is correct
15 Correct 436 ms 49396 KB Output is correct
16 Correct 534 ms 49364 KB Output is correct
17 Correct 614 ms 49400 KB Output is correct
18 Correct 657 ms 49364 KB Output is correct
19 Correct 617 ms 49420 KB Output is correct
20 Correct 19 ms 49380 KB Output is correct
21 Correct 22 ms 49364 KB Output is correct
22 Correct 19 ms 49324 KB Output is correct
23 Correct 18 ms 49292 KB Output is correct
24 Correct 19 ms 49308 KB Output is correct
25 Correct 20 ms 49316 KB Output is correct
26 Correct 19 ms 49364 KB Output is correct
27 Correct 20 ms 49364 KB Output is correct
28 Correct 19 ms 49240 KB Output is correct
29 Correct 19 ms 49372 KB Output is correct
30 Correct 19 ms 49328 KB Output is correct
31 Correct 21 ms 49320 KB Output is correct
32 Correct 21 ms 49348 KB Output is correct
33 Correct 20 ms 49280 KB Output is correct
34 Correct 20 ms 49364 KB Output is correct
35 Correct 19 ms 49300 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49340 KB Output is correct
38 Correct 19 ms 49364 KB Output is correct
39 Correct 19 ms 49364 KB Output is correct
40 Correct 21 ms 49320 KB Output is correct
41 Correct 19 ms 49364 KB Output is correct
42 Correct 20 ms 49260 KB Output is correct
43 Correct 20 ms 49308 KB Output is correct
44 Correct 23 ms 49380 KB Output is correct
45 Correct 19 ms 49280 KB Output is correct
46 Correct 19 ms 49364 KB Output is correct
47 Correct 21 ms 49352 KB Output is correct
48 Correct 20 ms 49372 KB Output is correct
49 Correct 19 ms 49364 KB Output is correct
50 Correct 20 ms 49276 KB Output is correct
51 Correct 19 ms 49364 KB Output is correct
52 Correct 20 ms 49328 KB Output is correct
53 Correct 19 ms 49364 KB Output is correct
54 Correct 19 ms 49336 KB Output is correct
55 Correct 19 ms 49316 KB Output is correct
56 Correct 22 ms 49364 KB Output is correct
57 Correct 23 ms 49340 KB Output is correct
58 Correct 21 ms 49364 KB Output is correct
59 Correct 23 ms 49332 KB Output is correct
60 Correct 24 ms 49272 KB Output is correct
61 Correct 25 ms 49280 KB Output is correct
62 Correct 23 ms 49364 KB Output is correct
63 Correct 23 ms 49308 KB Output is correct
64 Correct 22 ms 49364 KB Output is correct
65 Correct 25 ms 49300 KB Output is correct
66 Correct 22 ms 49348 KB Output is correct
67 Correct 23 ms 49308 KB Output is correct
68 Correct 22 ms 49364 KB Output is correct
69 Correct 22 ms 49340 KB Output is correct
70 Correct 23 ms 49284 KB Output is correct
71 Correct 41 ms 49364 KB Output is correct
72 Correct 80 ms 49384 KB Output is correct
73 Correct 134 ms 49364 KB Output is correct
74 Correct 135 ms 49388 KB Output is correct
75 Correct 137 ms 49448 KB Output is correct
76 Correct 143 ms 49440 KB Output is correct
77 Correct 137 ms 49448 KB Output is correct
78 Correct 120 ms 49396 KB Output is correct
79 Correct 89 ms 49384 KB Output is correct
80 Correct 129 ms 49416 KB Output is correct
81 Correct 129 ms 49424 KB Output is correct
82 Correct 122 ms 49388 KB Output is correct
83 Correct 125 ms 49416 KB Output is correct
84 Correct 137 ms 49440 KB Output is correct
85 Correct 334 ms 49612 KB Output is correct
86 Correct 880 ms 49696 KB Output is correct
87 Correct 859 ms 49688 KB Output is correct
88 Correct 882 ms 49580 KB Output is correct
89 Incorrect 850 ms 49572 KB Output isn't correct
90 Halted 0 ms 0 KB -