답안 #1060978

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

using namespace std;

#define ll long long
#define int long long

const ll nx=2505, mod=1e9+9;

mt19937 rng(time(0));

ll n, a, b, c, s[nx], dp[nx][nx], pw[nx], mul;
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];

int32_t main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    mul=(rng()%30+30)%30+30;
    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;
                ll 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 'int32_t main()':
copypaste3.cpp:43:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |                 if (pts!=v.size()) pa[i]=pts;
      |                     ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 148308 KB Output is correct
2 Correct 40 ms 148180 KB Output is correct
3 Correct 38 ms 148312 KB Output is correct
4 Correct 39 ms 148204 KB Output is correct
5 Correct 41 ms 148308 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 40 ms 148304 KB Output is correct
8 Correct 43 ms 148308 KB Output is correct
9 Correct 45 ms 148316 KB Output is correct
10 Correct 40 ms 148308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 148312 KB Output is correct
2 Correct 53 ms 148164 KB Output is correct
3 Correct 392 ms 508552 KB Output is correct
4 Correct 458 ms 572900 KB Output is correct
5 Correct 601 ms 647228 KB Output is correct
6 Correct 670 ms 733840 KB Output is correct
7 Correct 820 ms 836492 KB Output is correct
8 Correct 776 ms 836496 KB Output is correct
9 Correct 782 ms 836492 KB Output is correct
10 Correct 42 ms 148304 KB Output is correct
11 Correct 43 ms 148304 KB Output is correct
12 Correct 47 ms 148316 KB Output is correct
13 Correct 40 ms 148304 KB Output is correct
14 Correct 39 ms 148216 KB Output is correct
15 Correct 42 ms 148308 KB Output is correct
16 Correct 42 ms 148308 KB Output is correct
17 Correct 43 ms 148188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 148308 KB Output is correct
2 Correct 40 ms 148180 KB Output is correct
3 Correct 38 ms 148312 KB Output is correct
4 Correct 39 ms 148204 KB Output is correct
5 Correct 41 ms 148308 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 40 ms 148304 KB Output is correct
8 Correct 43 ms 148308 KB Output is correct
9 Correct 45 ms 148316 KB Output is correct
10 Correct 40 ms 148308 KB Output is correct
11 Correct 42 ms 148316 KB Output is correct
12 Correct 40 ms 148304 KB Output is correct
13 Correct 39 ms 148192 KB Output is correct
14 Correct 39 ms 148316 KB Output is correct
15 Correct 40 ms 148308 KB Output is correct
16 Correct 41 ms 148316 KB Output is correct
17 Correct 42 ms 148304 KB Output is correct
18 Correct 41 ms 148308 KB Output is correct
19 Correct 39 ms 148212 KB Output is correct
20 Correct 41 ms 148316 KB Output is correct
21 Correct 42 ms 148308 KB Output is correct
22 Correct 38 ms 148304 KB Output is correct
23 Correct 42 ms 148308 KB Output is correct
24 Correct 41 ms 148304 KB Output is correct
25 Correct 39 ms 148308 KB Output is correct
26 Correct 42 ms 148304 KB Output is correct
27 Correct 42 ms 148308 KB Output is correct
28 Correct 44 ms 148564 KB Output is correct
29 Correct 42 ms 148268 KB Output is correct
30 Correct 42 ms 148316 KB Output is correct
31 Correct 45 ms 148304 KB Output is correct
32 Correct 44 ms 148392 KB Output is correct
33 Correct 54 ms 148392 KB Output is correct
34 Correct 49 ms 148304 KB Output is correct
35 Correct 43 ms 148312 KB Output is correct
36 Correct 40 ms 148304 KB Output is correct
37 Correct 39 ms 148304 KB Output is correct
38 Correct 40 ms 148160 KB Output is correct
39 Correct 40 ms 148308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 148308 KB Output is correct
2 Correct 40 ms 148180 KB Output is correct
3 Correct 38 ms 148312 KB Output is correct
4 Correct 39 ms 148204 KB Output is correct
5 Correct 41 ms 148308 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 40 ms 148304 KB Output is correct
8 Correct 43 ms 148308 KB Output is correct
9 Correct 45 ms 148316 KB Output is correct
10 Correct 40 ms 148308 KB Output is correct
11 Correct 42 ms 148316 KB Output is correct
12 Correct 40 ms 148304 KB Output is correct
13 Correct 39 ms 148192 KB Output is correct
14 Correct 39 ms 148316 KB Output is correct
15 Correct 40 ms 148308 KB Output is correct
16 Correct 41 ms 148316 KB Output is correct
17 Correct 42 ms 148304 KB Output is correct
18 Correct 41 ms 148308 KB Output is correct
19 Correct 39 ms 148212 KB Output is correct
20 Correct 41 ms 148316 KB Output is correct
21 Correct 42 ms 148308 KB Output is correct
22 Correct 38 ms 148304 KB Output is correct
23 Correct 42 ms 148308 KB Output is correct
24 Correct 41 ms 148304 KB Output is correct
25 Correct 39 ms 148308 KB Output is correct
26 Correct 42 ms 148304 KB Output is correct
27 Correct 42 ms 148308 KB Output is correct
28 Correct 44 ms 148564 KB Output is correct
29 Correct 42 ms 148268 KB Output is correct
30 Correct 42 ms 148316 KB Output is correct
31 Correct 45 ms 148304 KB Output is correct
32 Correct 44 ms 148392 KB Output is correct
33 Correct 54 ms 148392 KB Output is correct
34 Correct 49 ms 148304 KB Output is correct
35 Correct 43 ms 148312 KB Output is correct
36 Correct 40 ms 148304 KB Output is correct
37 Correct 39 ms 148304 KB Output is correct
38 Correct 40 ms 148160 KB Output is correct
39 Correct 40 ms 148308 KB Output is correct
40 Correct 44 ms 148564 KB Output is correct
41 Correct 42 ms 152016 KB Output is correct
42 Correct 43 ms 149840 KB Output is correct
43 Correct 44 ms 149592 KB Output is correct
44 Correct 41 ms 149340 KB Output is correct
45 Correct 42 ms 149332 KB Output is correct
46 Correct 48 ms 149332 KB Output is correct
47 Correct 47 ms 150096 KB Output is correct
48 Correct 45 ms 149592 KB Output is correct
49 Correct 42 ms 149764 KB Output is correct
50 Correct 48 ms 149804 KB Output is correct
51 Correct 45 ms 150628 KB Output is correct
52 Correct 42 ms 150476 KB Output is correct
53 Correct 44 ms 149328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 148308 KB Output is correct
2 Correct 40 ms 148180 KB Output is correct
3 Correct 38 ms 148312 KB Output is correct
4 Correct 39 ms 148204 KB Output is correct
5 Correct 41 ms 148308 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 40 ms 148304 KB Output is correct
8 Correct 43 ms 148308 KB Output is correct
9 Correct 45 ms 148316 KB Output is correct
10 Correct 40 ms 148308 KB Output is correct
11 Correct 42 ms 148316 KB Output is correct
12 Correct 40 ms 148304 KB Output is correct
13 Correct 39 ms 148192 KB Output is correct
14 Correct 39 ms 148316 KB Output is correct
15 Correct 40 ms 148308 KB Output is correct
16 Correct 41 ms 148316 KB Output is correct
17 Correct 42 ms 148304 KB Output is correct
18 Correct 41 ms 148308 KB Output is correct
19 Correct 39 ms 148212 KB Output is correct
20 Correct 41 ms 148316 KB Output is correct
21 Correct 42 ms 148308 KB Output is correct
22 Correct 38 ms 148304 KB Output is correct
23 Correct 42 ms 148308 KB Output is correct
24 Correct 41 ms 148304 KB Output is correct
25 Correct 39 ms 148308 KB Output is correct
26 Correct 42 ms 148304 KB Output is correct
27 Correct 42 ms 148308 KB Output is correct
28 Correct 44 ms 148564 KB Output is correct
29 Correct 42 ms 148268 KB Output is correct
30 Correct 42 ms 148316 KB Output is correct
31 Correct 45 ms 148304 KB Output is correct
32 Correct 44 ms 148392 KB Output is correct
33 Correct 54 ms 148392 KB Output is correct
34 Correct 49 ms 148304 KB Output is correct
35 Correct 43 ms 148312 KB Output is correct
36 Correct 40 ms 148304 KB Output is correct
37 Correct 39 ms 148304 KB Output is correct
38 Correct 40 ms 148160 KB Output is correct
39 Correct 40 ms 148308 KB Output is correct
40 Correct 44 ms 148564 KB Output is correct
41 Correct 42 ms 152016 KB Output is correct
42 Correct 43 ms 149840 KB Output is correct
43 Correct 44 ms 149592 KB Output is correct
44 Correct 41 ms 149340 KB Output is correct
45 Correct 42 ms 149332 KB Output is correct
46 Correct 48 ms 149332 KB Output is correct
47 Correct 47 ms 150096 KB Output is correct
48 Correct 45 ms 149592 KB Output is correct
49 Correct 42 ms 149764 KB Output is correct
50 Correct 48 ms 149804 KB Output is correct
51 Correct 45 ms 150628 KB Output is correct
52 Correct 42 ms 150476 KB Output is correct
53 Correct 44 ms 149328 KB Output is correct
54 Correct 60 ms 154708 KB Output is correct
55 Correct 132 ms 249084 KB Output is correct
56 Correct 134 ms 175100 KB Output is correct
57 Correct 133 ms 167980 KB Output is correct
58 Correct 138 ms 163288 KB Output is correct
59 Correct 122 ms 161192 KB Output is correct
60 Correct 131 ms 160592 KB Output is correct
61 Correct 127 ms 175184 KB Output is correct
62 Correct 125 ms 233584 KB Output is correct
63 Correct 136 ms 171088 KB Output is correct
64 Correct 139 ms 177488 KB Output is correct
65 Correct 146 ms 206544 KB Output is correct
66 Correct 151 ms 205920 KB Output is correct
67 Correct 122 ms 160592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 148308 KB Output is correct
2 Correct 40 ms 148180 KB Output is correct
3 Correct 38 ms 148312 KB Output is correct
4 Correct 39 ms 148204 KB Output is correct
5 Correct 41 ms 148308 KB Output is correct
6 Correct 42 ms 148308 KB Output is correct
7 Correct 40 ms 148304 KB Output is correct
8 Correct 43 ms 148308 KB Output is correct
9 Correct 45 ms 148316 KB Output is correct
10 Correct 40 ms 148308 KB Output is correct
11 Correct 40 ms 148312 KB Output is correct
12 Correct 53 ms 148164 KB Output is correct
13 Correct 392 ms 508552 KB Output is correct
14 Correct 458 ms 572900 KB Output is correct
15 Correct 601 ms 647228 KB Output is correct
16 Correct 670 ms 733840 KB Output is correct
17 Correct 820 ms 836492 KB Output is correct
18 Correct 776 ms 836496 KB Output is correct
19 Correct 782 ms 836492 KB Output is correct
20 Correct 42 ms 148304 KB Output is correct
21 Correct 43 ms 148304 KB Output is correct
22 Correct 47 ms 148316 KB Output is correct
23 Correct 40 ms 148304 KB Output is correct
24 Correct 39 ms 148216 KB Output is correct
25 Correct 42 ms 148308 KB Output is correct
26 Correct 42 ms 148308 KB Output is correct
27 Correct 43 ms 148188 KB Output is correct
28 Correct 42 ms 148316 KB Output is correct
29 Correct 40 ms 148304 KB Output is correct
30 Correct 39 ms 148192 KB Output is correct
31 Correct 39 ms 148316 KB Output is correct
32 Correct 40 ms 148308 KB Output is correct
33 Correct 41 ms 148316 KB Output is correct
34 Correct 42 ms 148304 KB Output is correct
35 Correct 41 ms 148308 KB Output is correct
36 Correct 39 ms 148212 KB Output is correct
37 Correct 41 ms 148316 KB Output is correct
38 Correct 42 ms 148308 KB Output is correct
39 Correct 38 ms 148304 KB Output is correct
40 Correct 42 ms 148308 KB Output is correct
41 Correct 41 ms 148304 KB Output is correct
42 Correct 39 ms 148308 KB Output is correct
43 Correct 42 ms 148304 KB Output is correct
44 Correct 42 ms 148308 KB Output is correct
45 Correct 44 ms 148564 KB Output is correct
46 Correct 42 ms 148268 KB Output is correct
47 Correct 42 ms 148316 KB Output is correct
48 Correct 45 ms 148304 KB Output is correct
49 Correct 44 ms 148392 KB Output is correct
50 Correct 54 ms 148392 KB Output is correct
51 Correct 49 ms 148304 KB Output is correct
52 Correct 43 ms 148312 KB Output is correct
53 Correct 40 ms 148304 KB Output is correct
54 Correct 39 ms 148304 KB Output is correct
55 Correct 40 ms 148160 KB Output is correct
56 Correct 40 ms 148308 KB Output is correct
57 Correct 44 ms 148564 KB Output is correct
58 Correct 42 ms 152016 KB Output is correct
59 Correct 43 ms 149840 KB Output is correct
60 Correct 44 ms 149592 KB Output is correct
61 Correct 41 ms 149340 KB Output is correct
62 Correct 42 ms 149332 KB Output is correct
63 Correct 48 ms 149332 KB Output is correct
64 Correct 47 ms 150096 KB Output is correct
65 Correct 45 ms 149592 KB Output is correct
66 Correct 42 ms 149764 KB Output is correct
67 Correct 48 ms 149804 KB Output is correct
68 Correct 45 ms 150628 KB Output is correct
69 Correct 42 ms 150476 KB Output is correct
70 Correct 44 ms 149328 KB Output is correct
71 Correct 60 ms 154708 KB Output is correct
72 Correct 132 ms 249084 KB Output is correct
73 Correct 134 ms 175100 KB Output is correct
74 Correct 133 ms 167980 KB Output is correct
75 Correct 138 ms 163288 KB Output is correct
76 Correct 122 ms 161192 KB Output is correct
77 Correct 131 ms 160592 KB Output is correct
78 Correct 127 ms 175184 KB Output is correct
79 Correct 125 ms 233584 KB Output is correct
80 Correct 136 ms 171088 KB Output is correct
81 Correct 139 ms 177488 KB Output is correct
82 Correct 146 ms 206544 KB Output is correct
83 Correct 151 ms 205920 KB Output is correct
84 Correct 122 ms 160592 KB Output is correct
85 Correct 305 ms 212136 KB Output is correct
86 Correct 706 ms 291268 KB Output is correct
87 Correct 695 ms 247568 KB Output is correct
88 Correct 644 ms 217120 KB Output is correct
89 Incorrect 624 ms 205376 KB Output isn't correct
90 Halted 0 ms 0 KB -