답안 #550553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
550553 2022-04-18T13:28:18 Z fcmalkcin Copy and Paste 3 (JOI22_copypaste3) C++17
20 / 100
399 ms 305628 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define F(i,a,b) for(ll i=a;i<=b;i++)

const ll maxn=2e3+530;
const ll base=3e18;
const ll mod= 1e9+7 ;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

/// have medal in APIO
/// goal 2/8

ll n, a, b, c;
string s;
ll dp[maxn][maxn];
vector<int> gr[maxn*maxn];
ll cnt=0;
int nxt[maxn][27];
vector<int> adj[maxn];
void add(string s,ll l)
{
    ll nw=0;
    ll dep=0;
    for (auto to:s)
    {
        dep++;
        ll h=(to-'a'+1);
        if (!nxt[nw][h])
        {
            cnt++;
            nxt[nw][h]=cnt;
            adj[dep].pb(nxt[nw][h]);
        }
        nw=nxt[nw][h];
        gr[nw].pb(l);

    }
}
ll rt[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    cin>> n>> s>> a>> b>> c;
    s=" "+s;
    for (int i=1;i<=n;i++)
    {
        string t=s.substr(i,n-i+1);
        add(t,i);
    }
    for (int i=1;i<=n;i++)
    {
        for (int j=i;j<=n;j++)
        {
            dp[i][j]=a*(j-i+1);
        }
    }
    for (int len=1;len<=n;len++)
    {
        for (auto nw:adj[len])
        {
            vector<int> vt=gr[nw];

            ll pre=vt.size();
            for (int i=vt.size()-1;i>=0;i--)
            {
                while (vt[pre-1]-len+1>vt[i]) pre--;
                rt[i]=pre;

            }
            for (int i=0;i<vt.size();i++)
            {
                ll nw=rt[i];
                ll cnt=1;
                while (nw<vt.size())
                {
                    ll l=vt[i];
                    ll r=vt[nw]+len-1;
                    cnt++;
                    dp[l][r]=min(dp[l][r],(r-l+1-cnt*len)*a+b+dp[l][l+len-1]+c*cnt);
               /* if (len==1&&vt[0]==3&&i==0)
            {
                cout <<" chk1"<<endl;
                cout <<l<<" "<<r<<" "<<dp[l][r]<<" "<<dp[l][l+len-1]<<" "<<b*cnt<<" "<<c<<" chk1"<<endl;
            }*/
                    nw=rt[nw];
                }
            }
        }
        for (int i=1;i+len-1<=n;i++)
        {
            ll j=i+len-1;
            dp[i][j+1]=min(dp[i][j+1],dp[i][j]+a);
            dp[i-1][j]=min(dp[i-1][j],dp[i][j]+a);
        }
    }
    cout <<dp[1][n]<<endl;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |             for (int i=0;i<vt.size();i++)
      |                          ~^~~~~~~~~~
copypaste3.cpp:90:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |                 while (nw<vt.size())
      |                        ~~^~~~~~~~~~
copypaste3.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
copypaste3.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 150612 KB Output is correct
2 Correct 74 ms 150720 KB Output is correct
3 Correct 75 ms 150632 KB Output is correct
4 Correct 76 ms 150632 KB Output is correct
5 Correct 80 ms 150616 KB Output is correct
6 Correct 84 ms 150680 KB Output is correct
7 Correct 83 ms 150700 KB Output is correct
8 Correct 71 ms 150608 KB Output is correct
9 Correct 73 ms 150828 KB Output is correct
10 Correct 72 ms 150628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 150728 KB Output is correct
2 Correct 72 ms 150656 KB Output is correct
3 Correct 230 ms 180656 KB Output is correct
4 Correct 250 ms 184780 KB Output is correct
5 Correct 294 ms 189904 KB Output is correct
6 Correct 324 ms 195756 KB Output is correct
7 Correct 366 ms 202656 KB Output is correct
8 Correct 399 ms 202696 KB Output is correct
9 Correct 374 ms 202548 KB Output is correct
10 Correct 71 ms 150604 KB Output is correct
11 Correct 72 ms 150628 KB Output is correct
12 Correct 72 ms 150592 KB Output is correct
13 Correct 76 ms 150620 KB Output is correct
14 Correct 74 ms 150700 KB Output is correct
15 Correct 77 ms 150688 KB Output is correct
16 Correct 74 ms 150868 KB Output is correct
17 Correct 73 ms 150604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 150612 KB Output is correct
2 Correct 74 ms 150720 KB Output is correct
3 Correct 75 ms 150632 KB Output is correct
4 Correct 76 ms 150632 KB Output is correct
5 Correct 80 ms 150616 KB Output is correct
6 Correct 84 ms 150680 KB Output is correct
7 Correct 83 ms 150700 KB Output is correct
8 Correct 71 ms 150608 KB Output is correct
9 Correct 73 ms 150828 KB Output is correct
10 Correct 72 ms 150628 KB Output is correct
11 Correct 74 ms 150700 KB Output is correct
12 Correct 72 ms 150756 KB Output is correct
13 Correct 72 ms 150780 KB Output is correct
14 Correct 74 ms 150644 KB Output is correct
15 Correct 76 ms 150688 KB Output is correct
16 Correct 75 ms 150708 KB Output is correct
17 Correct 74 ms 150824 KB Output is correct
18 Correct 72 ms 150660 KB Output is correct
19 Correct 76 ms 150672 KB Output is correct
20 Correct 82 ms 150720 KB Output is correct
21 Correct 74 ms 150832 KB Output is correct
22 Correct 73 ms 150856 KB Output is correct
23 Correct 72 ms 150856 KB Output is correct
24 Correct 76 ms 150856 KB Output is correct
25 Correct 79 ms 150780 KB Output is correct
26 Correct 80 ms 150940 KB Output is correct
27 Correct 72 ms 150880 KB Output is correct
28 Correct 72 ms 150732 KB Output is correct
29 Correct 73 ms 150908 KB Output is correct
30 Correct 85 ms 150788 KB Output is correct
31 Correct 74 ms 150824 KB Output is correct
32 Correct 72 ms 150828 KB Output is correct
33 Correct 72 ms 150912 KB Output is correct
34 Correct 72 ms 150688 KB Output is correct
35 Correct 79 ms 150668 KB Output is correct
36 Correct 79 ms 150616 KB Output is correct
37 Correct 75 ms 150704 KB Output is correct
38 Correct 76 ms 150712 KB Output is correct
39 Correct 74 ms 150832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 150612 KB Output is correct
2 Correct 74 ms 150720 KB Output is correct
3 Correct 75 ms 150632 KB Output is correct
4 Correct 76 ms 150632 KB Output is correct
5 Correct 80 ms 150616 KB Output is correct
6 Correct 84 ms 150680 KB Output is correct
7 Correct 83 ms 150700 KB Output is correct
8 Correct 71 ms 150608 KB Output is correct
9 Correct 73 ms 150828 KB Output is correct
10 Correct 72 ms 150628 KB Output is correct
11 Correct 74 ms 150700 KB Output is correct
12 Correct 72 ms 150756 KB Output is correct
13 Correct 72 ms 150780 KB Output is correct
14 Correct 74 ms 150644 KB Output is correct
15 Correct 76 ms 150688 KB Output is correct
16 Correct 75 ms 150708 KB Output is correct
17 Correct 74 ms 150824 KB Output is correct
18 Correct 72 ms 150660 KB Output is correct
19 Correct 76 ms 150672 KB Output is correct
20 Correct 82 ms 150720 KB Output is correct
21 Correct 74 ms 150832 KB Output is correct
22 Correct 73 ms 150856 KB Output is correct
23 Correct 72 ms 150856 KB Output is correct
24 Correct 76 ms 150856 KB Output is correct
25 Correct 79 ms 150780 KB Output is correct
26 Correct 80 ms 150940 KB Output is correct
27 Correct 72 ms 150880 KB Output is correct
28 Correct 72 ms 150732 KB Output is correct
29 Correct 73 ms 150908 KB Output is correct
30 Correct 85 ms 150788 KB Output is correct
31 Correct 74 ms 150824 KB Output is correct
32 Correct 72 ms 150828 KB Output is correct
33 Correct 72 ms 150912 KB Output is correct
34 Correct 72 ms 150688 KB Output is correct
35 Correct 79 ms 150668 KB Output is correct
36 Correct 79 ms 150616 KB Output is correct
37 Correct 75 ms 150704 KB Output is correct
38 Correct 76 ms 150712 KB Output is correct
39 Correct 74 ms 150832 KB Output is correct
40 Runtime error 198 ms 305628 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 150612 KB Output is correct
2 Correct 74 ms 150720 KB Output is correct
3 Correct 75 ms 150632 KB Output is correct
4 Correct 76 ms 150632 KB Output is correct
5 Correct 80 ms 150616 KB Output is correct
6 Correct 84 ms 150680 KB Output is correct
7 Correct 83 ms 150700 KB Output is correct
8 Correct 71 ms 150608 KB Output is correct
9 Correct 73 ms 150828 KB Output is correct
10 Correct 72 ms 150628 KB Output is correct
11 Correct 74 ms 150700 KB Output is correct
12 Correct 72 ms 150756 KB Output is correct
13 Correct 72 ms 150780 KB Output is correct
14 Correct 74 ms 150644 KB Output is correct
15 Correct 76 ms 150688 KB Output is correct
16 Correct 75 ms 150708 KB Output is correct
17 Correct 74 ms 150824 KB Output is correct
18 Correct 72 ms 150660 KB Output is correct
19 Correct 76 ms 150672 KB Output is correct
20 Correct 82 ms 150720 KB Output is correct
21 Correct 74 ms 150832 KB Output is correct
22 Correct 73 ms 150856 KB Output is correct
23 Correct 72 ms 150856 KB Output is correct
24 Correct 76 ms 150856 KB Output is correct
25 Correct 79 ms 150780 KB Output is correct
26 Correct 80 ms 150940 KB Output is correct
27 Correct 72 ms 150880 KB Output is correct
28 Correct 72 ms 150732 KB Output is correct
29 Correct 73 ms 150908 KB Output is correct
30 Correct 85 ms 150788 KB Output is correct
31 Correct 74 ms 150824 KB Output is correct
32 Correct 72 ms 150828 KB Output is correct
33 Correct 72 ms 150912 KB Output is correct
34 Correct 72 ms 150688 KB Output is correct
35 Correct 79 ms 150668 KB Output is correct
36 Correct 79 ms 150616 KB Output is correct
37 Correct 75 ms 150704 KB Output is correct
38 Correct 76 ms 150712 KB Output is correct
39 Correct 74 ms 150832 KB Output is correct
40 Runtime error 198 ms 305628 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 150612 KB Output is correct
2 Correct 74 ms 150720 KB Output is correct
3 Correct 75 ms 150632 KB Output is correct
4 Correct 76 ms 150632 KB Output is correct
5 Correct 80 ms 150616 KB Output is correct
6 Correct 84 ms 150680 KB Output is correct
7 Correct 83 ms 150700 KB Output is correct
8 Correct 71 ms 150608 KB Output is correct
9 Correct 73 ms 150828 KB Output is correct
10 Correct 72 ms 150628 KB Output is correct
11 Correct 73 ms 150728 KB Output is correct
12 Correct 72 ms 150656 KB Output is correct
13 Correct 230 ms 180656 KB Output is correct
14 Correct 250 ms 184780 KB Output is correct
15 Correct 294 ms 189904 KB Output is correct
16 Correct 324 ms 195756 KB Output is correct
17 Correct 366 ms 202656 KB Output is correct
18 Correct 399 ms 202696 KB Output is correct
19 Correct 374 ms 202548 KB Output is correct
20 Correct 71 ms 150604 KB Output is correct
21 Correct 72 ms 150628 KB Output is correct
22 Correct 72 ms 150592 KB Output is correct
23 Correct 76 ms 150620 KB Output is correct
24 Correct 74 ms 150700 KB Output is correct
25 Correct 77 ms 150688 KB Output is correct
26 Correct 74 ms 150868 KB Output is correct
27 Correct 73 ms 150604 KB Output is correct
28 Correct 74 ms 150700 KB Output is correct
29 Correct 72 ms 150756 KB Output is correct
30 Correct 72 ms 150780 KB Output is correct
31 Correct 74 ms 150644 KB Output is correct
32 Correct 76 ms 150688 KB Output is correct
33 Correct 75 ms 150708 KB Output is correct
34 Correct 74 ms 150824 KB Output is correct
35 Correct 72 ms 150660 KB Output is correct
36 Correct 76 ms 150672 KB Output is correct
37 Correct 82 ms 150720 KB Output is correct
38 Correct 74 ms 150832 KB Output is correct
39 Correct 73 ms 150856 KB Output is correct
40 Correct 72 ms 150856 KB Output is correct
41 Correct 76 ms 150856 KB Output is correct
42 Correct 79 ms 150780 KB Output is correct
43 Correct 80 ms 150940 KB Output is correct
44 Correct 72 ms 150880 KB Output is correct
45 Correct 72 ms 150732 KB Output is correct
46 Correct 73 ms 150908 KB Output is correct
47 Correct 85 ms 150788 KB Output is correct
48 Correct 74 ms 150824 KB Output is correct
49 Correct 72 ms 150828 KB Output is correct
50 Correct 72 ms 150912 KB Output is correct
51 Correct 72 ms 150688 KB Output is correct
52 Correct 79 ms 150668 KB Output is correct
53 Correct 79 ms 150616 KB Output is correct
54 Correct 75 ms 150704 KB Output is correct
55 Correct 76 ms 150712 KB Output is correct
56 Correct 74 ms 150832 KB Output is correct
57 Runtime error 198 ms 305628 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -