답안 #1060961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1060961 2024-08-16T05:02:27 Z 12345678 Copy and Paste 3 (JOI22_copypaste3) C++17
62 / 100
748 ms 836512 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll nx=2505, mod=1e9+7, mul=31;

ll n, a, b, c, s[nx], dp[nx][nx], pw[nx];
string stmp;

struct update
{
    ll l, r, cnta, cntc;
    update(ll l=0, ll r=0, ll cnta=0, ll cntc=0): l(l), r(r), cnta(cnta), cntc(cntc){}
};
vector<update> calc[nx][nx];

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>stmp>>a>>b>>c;
    pw[0]=1;
    for (int i=1; i<=n; i++) s[i]=stmp[i-1]-'a'+1, pw[i]=(pw[i-1]*mul)%mod;
    for (int sz=1; sz<=n; sz++)
    {
        map<ll, vector<ll>> mp;
        ll sm=0;
        for (int i=1; i<=sz; i++) sm=(sm+pw[sz-i]*s[i])%mod;
        mp[sm].push_back(1);
        for (int i=sz+1; i<=n; i++) sm=(sm*mul)%mod, sm=((sm-s[i-sz]*pw[sz])%mod+mod)%mod, sm=(sm+s[i])%mod, mp[sm].push_back(i-sz+1);
        for (auto &[_, v]:mp)
        {
            int csz=v.size(), pts=v.size();
            vector<int> pa(csz);
            for (int i=csz-1; i>=0; i--)
            {
                while (pts!=0&&v[i]+sz<=v[pts-1]) pts--;
                if (pts!=v.size()) pa[i]=pts;
                else pa[i]=-1; 
            }
            /*
            cout<<"string update ";
            for (int i=v[0]; i<v[0]+sz; i++) cout<<(char)(s[i]-1+'a');
            cout<<'\n';
            for (int i=0; i<csz; i++) cout<<pa[i]<<' ';
            cout<<'\n';*/
            for (int i=0; i<csz; i++)
            {
                if (pa[i]==-1) continue;
                auto tmp=pa[i], cnt=2;
                while (tmp!=-1) 
                {
                    calc[v[0]][v[0]+sz-1].push_back(update(v[i], v[tmp]+sz-1, v[tmp]+sz-v[i]-cnt*sz, cnt));
                    //cout<<"upd "<<v[i]<<' '<<v[tmp]+sz-1<<' '<<v[tmp]+sz-v[i]-cnt*sz<<' '<<cnt<<'\n';
                    cnt++;
                    tmp=pa[tmp];
                }
            }
        }
    }
    for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=1e18;
    for (int i=1; i<=n; i++) dp[i][i]=a;
    for (int sz=0; sz<=n; sz++)
    {
        for (int l=1; l+sz<=n; l++)
        {
            int r=l+sz;
            if (l!=r) dp[l][r]=min({dp[l][r], dp[l+1][r]+a, dp[l][r-1]+a});
            for (auto upd:calc[l][r]) dp[upd.l][upd.r]=min(dp[upd.l][upd.r], dp[l][r]+c*upd.cntc+a*upd.cnta+b);
            //cout<<"dp "<<l<<' '<<r<<' '<<dp[l][r]<<'\n';
        }
    }
    cout<<dp[1][n];
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:39:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                 if (pts!=v.size()) pa[i]=pts;
      |                     ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 148312 KB Output is correct
2 Correct 36 ms 148312 KB Output is correct
3 Correct 37 ms 148316 KB Output is correct
4 Correct 40 ms 148344 KB Output is correct
5 Correct 37 ms 148340 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 45 ms 148304 KB Output is correct
8 Correct 40 ms 148236 KB Output is correct
9 Correct 40 ms 148200 KB Output is correct
10 Correct 37 ms 148316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 148316 KB Output is correct
2 Correct 39 ms 148316 KB Output is correct
3 Correct 372 ms 508616 KB Output is correct
4 Correct 445 ms 573168 KB Output is correct
5 Correct 536 ms 647188 KB Output is correct
6 Correct 635 ms 733860 KB Output is correct
7 Correct 741 ms 836360 KB Output is correct
8 Correct 746 ms 836432 KB Output is correct
9 Correct 748 ms 836512 KB Output is correct
10 Correct 38 ms 148304 KB Output is correct
11 Correct 40 ms 148316 KB Output is correct
12 Correct 37 ms 148292 KB Output is correct
13 Correct 44 ms 148304 KB Output is correct
14 Correct 44 ms 148304 KB Output is correct
15 Correct 39 ms 148312 KB Output is correct
16 Correct 37 ms 148224 KB Output is correct
17 Correct 38 ms 148308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 148312 KB Output is correct
2 Correct 36 ms 148312 KB Output is correct
3 Correct 37 ms 148316 KB Output is correct
4 Correct 40 ms 148344 KB Output is correct
5 Correct 37 ms 148340 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 45 ms 148304 KB Output is correct
8 Correct 40 ms 148236 KB Output is correct
9 Correct 40 ms 148200 KB Output is correct
10 Correct 37 ms 148316 KB Output is correct
11 Correct 36 ms 148308 KB Output is correct
12 Correct 41 ms 148304 KB Output is correct
13 Correct 42 ms 148364 KB Output is correct
14 Correct 37 ms 148308 KB Output is correct
15 Correct 37 ms 148316 KB Output is correct
16 Correct 37 ms 148316 KB Output is correct
17 Correct 37 ms 148164 KB Output is correct
18 Correct 38 ms 148316 KB Output is correct
19 Correct 39 ms 148304 KB Output is correct
20 Correct 37 ms 148212 KB Output is correct
21 Correct 37 ms 148308 KB Output is correct
22 Correct 39 ms 148316 KB Output is correct
23 Correct 39 ms 148172 KB Output is correct
24 Correct 39 ms 148304 KB Output is correct
25 Correct 42 ms 148312 KB Output is correct
26 Correct 44 ms 148316 KB Output is correct
27 Correct 40 ms 148308 KB Output is correct
28 Correct 36 ms 148304 KB Output is correct
29 Correct 37 ms 148308 KB Output is correct
30 Correct 38 ms 148304 KB Output is correct
31 Correct 38 ms 148296 KB Output is correct
32 Correct 38 ms 148304 KB Output is correct
33 Correct 38 ms 148308 KB Output is correct
34 Correct 39 ms 148316 KB Output is correct
35 Correct 36 ms 148308 KB Output is correct
36 Correct 43 ms 148140 KB Output is correct
37 Correct 39 ms 148304 KB Output is correct
38 Correct 40 ms 148304 KB Output is correct
39 Correct 40 ms 148304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 148312 KB Output is correct
2 Correct 36 ms 148312 KB Output is correct
3 Correct 37 ms 148316 KB Output is correct
4 Correct 40 ms 148344 KB Output is correct
5 Correct 37 ms 148340 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 45 ms 148304 KB Output is correct
8 Correct 40 ms 148236 KB Output is correct
9 Correct 40 ms 148200 KB Output is correct
10 Correct 37 ms 148316 KB Output is correct
11 Correct 36 ms 148308 KB Output is correct
12 Correct 41 ms 148304 KB Output is correct
13 Correct 42 ms 148364 KB Output is correct
14 Correct 37 ms 148308 KB Output is correct
15 Correct 37 ms 148316 KB Output is correct
16 Correct 37 ms 148316 KB Output is correct
17 Correct 37 ms 148164 KB Output is correct
18 Correct 38 ms 148316 KB Output is correct
19 Correct 39 ms 148304 KB Output is correct
20 Correct 37 ms 148212 KB Output is correct
21 Correct 37 ms 148308 KB Output is correct
22 Correct 39 ms 148316 KB Output is correct
23 Correct 39 ms 148172 KB Output is correct
24 Correct 39 ms 148304 KB Output is correct
25 Correct 42 ms 148312 KB Output is correct
26 Correct 44 ms 148316 KB Output is correct
27 Correct 40 ms 148308 KB Output is correct
28 Correct 36 ms 148304 KB Output is correct
29 Correct 37 ms 148308 KB Output is correct
30 Correct 38 ms 148304 KB Output is correct
31 Correct 38 ms 148296 KB Output is correct
32 Correct 38 ms 148304 KB Output is correct
33 Correct 38 ms 148308 KB Output is correct
34 Correct 39 ms 148316 KB Output is correct
35 Correct 36 ms 148308 KB Output is correct
36 Correct 43 ms 148140 KB Output is correct
37 Correct 39 ms 148304 KB Output is correct
38 Correct 40 ms 148304 KB Output is correct
39 Correct 40 ms 148304 KB Output is correct
40 Correct 40 ms 148568 KB Output is correct
41 Correct 39 ms 151952 KB Output is correct
42 Correct 43 ms 149840 KB Output is correct
43 Correct 44 ms 149596 KB Output is correct
44 Correct 45 ms 149328 KB Output is correct
45 Correct 41 ms 149332 KB Output is correct
46 Correct 40 ms 149340 KB Output is correct
47 Correct 43 ms 150208 KB Output is correct
48 Correct 41 ms 149584 KB Output is correct
49 Correct 40 ms 149588 KB Output is correct
50 Correct 40 ms 149732 KB Output is correct
51 Correct 44 ms 150608 KB Output is correct
52 Correct 41 ms 150612 KB Output is correct
53 Correct 45 ms 149332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 148312 KB Output is correct
2 Correct 36 ms 148312 KB Output is correct
3 Correct 37 ms 148316 KB Output is correct
4 Correct 40 ms 148344 KB Output is correct
5 Correct 37 ms 148340 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 45 ms 148304 KB Output is correct
8 Correct 40 ms 148236 KB Output is correct
9 Correct 40 ms 148200 KB Output is correct
10 Correct 37 ms 148316 KB Output is correct
11 Correct 36 ms 148308 KB Output is correct
12 Correct 41 ms 148304 KB Output is correct
13 Correct 42 ms 148364 KB Output is correct
14 Correct 37 ms 148308 KB Output is correct
15 Correct 37 ms 148316 KB Output is correct
16 Correct 37 ms 148316 KB Output is correct
17 Correct 37 ms 148164 KB Output is correct
18 Correct 38 ms 148316 KB Output is correct
19 Correct 39 ms 148304 KB Output is correct
20 Correct 37 ms 148212 KB Output is correct
21 Correct 37 ms 148308 KB Output is correct
22 Correct 39 ms 148316 KB Output is correct
23 Correct 39 ms 148172 KB Output is correct
24 Correct 39 ms 148304 KB Output is correct
25 Correct 42 ms 148312 KB Output is correct
26 Correct 44 ms 148316 KB Output is correct
27 Correct 40 ms 148308 KB Output is correct
28 Correct 36 ms 148304 KB Output is correct
29 Correct 37 ms 148308 KB Output is correct
30 Correct 38 ms 148304 KB Output is correct
31 Correct 38 ms 148296 KB Output is correct
32 Correct 38 ms 148304 KB Output is correct
33 Correct 38 ms 148308 KB Output is correct
34 Correct 39 ms 148316 KB Output is correct
35 Correct 36 ms 148308 KB Output is correct
36 Correct 43 ms 148140 KB Output is correct
37 Correct 39 ms 148304 KB Output is correct
38 Correct 40 ms 148304 KB Output is correct
39 Correct 40 ms 148304 KB Output is correct
40 Correct 40 ms 148568 KB Output is correct
41 Correct 39 ms 151952 KB Output is correct
42 Correct 43 ms 149840 KB Output is correct
43 Correct 44 ms 149596 KB Output is correct
44 Correct 45 ms 149328 KB Output is correct
45 Correct 41 ms 149332 KB Output is correct
46 Correct 40 ms 149340 KB Output is correct
47 Correct 43 ms 150208 KB Output is correct
48 Correct 41 ms 149584 KB Output is correct
49 Correct 40 ms 149588 KB Output is correct
50 Correct 40 ms 149732 KB Output is correct
51 Correct 44 ms 150608 KB Output is correct
52 Correct 41 ms 150612 KB Output is correct
53 Correct 45 ms 149332 KB Output is correct
54 Correct 57 ms 154448 KB Output is correct
55 Correct 127 ms 248992 KB Output is correct
56 Correct 132 ms 175160 KB Output is correct
57 Correct 124 ms 167868 KB Output is correct
58 Correct 121 ms 163160 KB Output is correct
59 Correct 118 ms 161228 KB Output is correct
60 Correct 120 ms 160596 KB Output is correct
61 Correct 123 ms 175040 KB Output is correct
62 Correct 115 ms 233792 KB Output is correct
63 Correct 132 ms 171092 KB Output is correct
64 Correct 139 ms 177464 KB Output is correct
65 Correct 144 ms 206408 KB Output is correct
66 Correct 145 ms 206124 KB Output is correct
67 Correct 123 ms 160732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 148312 KB Output is correct
2 Correct 36 ms 148312 KB Output is correct
3 Correct 37 ms 148316 KB Output is correct
4 Correct 40 ms 148344 KB Output is correct
5 Correct 37 ms 148340 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 45 ms 148304 KB Output is correct
8 Correct 40 ms 148236 KB Output is correct
9 Correct 40 ms 148200 KB Output is correct
10 Correct 37 ms 148316 KB Output is correct
11 Correct 43 ms 148316 KB Output is correct
12 Correct 39 ms 148316 KB Output is correct
13 Correct 372 ms 508616 KB Output is correct
14 Correct 445 ms 573168 KB Output is correct
15 Correct 536 ms 647188 KB Output is correct
16 Correct 635 ms 733860 KB Output is correct
17 Correct 741 ms 836360 KB Output is correct
18 Correct 746 ms 836432 KB Output is correct
19 Correct 748 ms 836512 KB Output is correct
20 Correct 38 ms 148304 KB Output is correct
21 Correct 40 ms 148316 KB Output is correct
22 Correct 37 ms 148292 KB Output is correct
23 Correct 44 ms 148304 KB Output is correct
24 Correct 44 ms 148304 KB Output is correct
25 Correct 39 ms 148312 KB Output is correct
26 Correct 37 ms 148224 KB Output is correct
27 Correct 38 ms 148308 KB Output is correct
28 Correct 36 ms 148308 KB Output is correct
29 Correct 41 ms 148304 KB Output is correct
30 Correct 42 ms 148364 KB Output is correct
31 Correct 37 ms 148308 KB Output is correct
32 Correct 37 ms 148316 KB Output is correct
33 Correct 37 ms 148316 KB Output is correct
34 Correct 37 ms 148164 KB Output is correct
35 Correct 38 ms 148316 KB Output is correct
36 Correct 39 ms 148304 KB Output is correct
37 Correct 37 ms 148212 KB Output is correct
38 Correct 37 ms 148308 KB Output is correct
39 Correct 39 ms 148316 KB Output is correct
40 Correct 39 ms 148172 KB Output is correct
41 Correct 39 ms 148304 KB Output is correct
42 Correct 42 ms 148312 KB Output is correct
43 Correct 44 ms 148316 KB Output is correct
44 Correct 40 ms 148308 KB Output is correct
45 Correct 36 ms 148304 KB Output is correct
46 Correct 37 ms 148308 KB Output is correct
47 Correct 38 ms 148304 KB Output is correct
48 Correct 38 ms 148296 KB Output is correct
49 Correct 38 ms 148304 KB Output is correct
50 Correct 38 ms 148308 KB Output is correct
51 Correct 39 ms 148316 KB Output is correct
52 Correct 36 ms 148308 KB Output is correct
53 Correct 43 ms 148140 KB Output is correct
54 Correct 39 ms 148304 KB Output is correct
55 Correct 40 ms 148304 KB Output is correct
56 Correct 40 ms 148304 KB Output is correct
57 Correct 40 ms 148568 KB Output is correct
58 Correct 39 ms 151952 KB Output is correct
59 Correct 43 ms 149840 KB Output is correct
60 Correct 44 ms 149596 KB Output is correct
61 Correct 45 ms 149328 KB Output is correct
62 Correct 41 ms 149332 KB Output is correct
63 Correct 40 ms 149340 KB Output is correct
64 Correct 43 ms 150208 KB Output is correct
65 Correct 41 ms 149584 KB Output is correct
66 Correct 40 ms 149588 KB Output is correct
67 Correct 40 ms 149732 KB Output is correct
68 Correct 44 ms 150608 KB Output is correct
69 Correct 41 ms 150612 KB Output is correct
70 Correct 45 ms 149332 KB Output is correct
71 Correct 57 ms 154448 KB Output is correct
72 Correct 127 ms 248992 KB Output is correct
73 Correct 132 ms 175160 KB Output is correct
74 Correct 124 ms 167868 KB Output is correct
75 Correct 121 ms 163160 KB Output is correct
76 Correct 118 ms 161228 KB Output is correct
77 Correct 120 ms 160596 KB Output is correct
78 Correct 123 ms 175040 KB Output is correct
79 Correct 115 ms 233792 KB Output is correct
80 Correct 132 ms 171092 KB Output is correct
81 Correct 139 ms 177464 KB Output is correct
82 Correct 144 ms 206408 KB Output is correct
83 Correct 145 ms 206124 KB Output is correct
84 Correct 123 ms 160732 KB Output is correct
85 Correct 279 ms 212060 KB Output is correct
86 Correct 688 ms 291420 KB Output is correct
87 Correct 638 ms 246108 KB Output is correct
88 Correct 618 ms 217000 KB Output is correct
89 Correct 615 ms 205380 KB Output is correct
90 Incorrect 606 ms 201164 KB Output isn't correct
91 Halted 0 ms 0 KB -