답안 #958450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958450 2024-04-05T19:50:03 Z MarwenElarbi Copy and Paste 3 (JOI22_copypaste3) C++17
100 / 100
1338 ms 98652 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = (1LL << 61) - 1;
const int nax = 1e5+5;
const int MAX_VAL = 1e6+1;
double PI=3.14159265359;
int arx[8]={1,0,0,-1,-1,-1, 1, 1};
int ary[8]={0,1,-1, 0, 1,-1,-1, 1};
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
const int d=41;
int main(){
    optimise;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    //setIO("dec");
    ll n,a,b,c;
    string s;
    cin>>n>>s>>a>>b>>c;
    s="#"+s;
    long long hash[n+1][n+1];
    long long dp[n+1][n+1];
    memset(hash,0,sizeof hash);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = i; j <= n ; ++j)
        {
            hash[i][j]=(hash[i][j-1]*26+s[j]-'a')%MOD;
        }
        for (int j = 0; j <= n; ++j)
        {
            dp[i][j]=1e18;
        }
        dp[i][i]=a;
    }
    for (ll h = 1; h <= n; ++h)
    {
        vector<pair<ll,ll>> cand;
        for (int i = 1; i <= n-h+1; ++i)
        {
            dp[i][i+h-1]=min(dp[i][i+h-1],min(dp[i][i+h-2],dp[i+1][i+h-1])+a);
            cand.pb({hash[i][i+h-1],i});
        }
        sort(cand.begin(),cand.end());
        for(auto u:cand){
            ll x=1;
            ll i=u.se;
            while(true){
                int pos=lower_bound(cand.begin(),cand.end(),mp(u.fi,i+h))-cand.begin();
                if(pos<cand.size()&&cand[pos].fi==u.fi){
                    i=cand[pos].se;
                    x++;
                    //cout <<h<<" "<<i<<endl;
                    dp[u.se][i+h-1]=min(dp[u.se][i+h-1],dp[u.se][u.se+h-1] + b + c*x + a*(i+h-u.se-x*h));
                }else break;
            }
        }
    }
    cout <<dp[1][n]<<endl;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                 if(pos<cand.size()&&cand[pos].fi==u.fi){
      |                    ~~~^~~~~~~~~~~~
copypaste3.cpp: In function 'void setIO(std::string)':
copypaste3.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
copypaste3.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 620 ms 52888 KB Output is correct
4 Correct 744 ms 61664 KB Output is correct
5 Correct 918 ms 72276 KB Output is correct
6 Correct 1051 ms 84052 KB Output is correct
7 Correct 1277 ms 98620 KB Output is correct
8 Correct 1338 ms 98476 KB Output is correct
9 Correct 1302 ms 98472 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 516 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 460 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 516 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 460 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 3 ms 860 KB Output is correct
42 Correct 2 ms 860 KB Output is correct
43 Correct 2 ms 1100 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 2 ms 968 KB Output is correct
46 Correct 3 ms 860 KB Output is correct
47 Correct 3 ms 968 KB Output is correct
48 Correct 3 ms 860 KB Output is correct
49 Correct 3 ms 860 KB Output is correct
50 Correct 3 ms 860 KB Output is correct
51 Correct 4 ms 860 KB Output is correct
52 Correct 3 ms 860 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 516 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 460 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 3 ms 860 KB Output is correct
42 Correct 2 ms 860 KB Output is correct
43 Correct 2 ms 1100 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 2 ms 968 KB Output is correct
46 Correct 3 ms 860 KB Output is correct
47 Correct 3 ms 968 KB Output is correct
48 Correct 3 ms 860 KB Output is correct
49 Correct 3 ms 860 KB Output is correct
50 Correct 3 ms 860 KB Output is correct
51 Correct 4 ms 860 KB Output is correct
52 Correct 3 ms 860 KB Output is correct
53 Correct 2 ms 860 KB Output is correct
54 Correct 11 ms 3420 KB Output is correct
55 Correct 133 ms 16152 KB Output is correct
56 Correct 64 ms 15964 KB Output is correct
57 Correct 57 ms 16160 KB Output is correct
58 Correct 54 ms 15964 KB Output is correct
59 Correct 59 ms 16160 KB Output is correct
60 Correct 55 ms 15960 KB Output is correct
61 Correct 75 ms 15960 KB Output is correct
62 Correct 106 ms 15964 KB Output is correct
63 Correct 65 ms 15960 KB Output is correct
64 Correct 71 ms 16152 KB Output is correct
65 Correct 93 ms 15960 KB Output is correct
66 Correct 91 ms 16152 KB Output is correct
67 Correct 57 ms 16212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 620 ms 52888 KB Output is correct
14 Correct 744 ms 61664 KB Output is correct
15 Correct 918 ms 72276 KB Output is correct
16 Correct 1051 ms 84052 KB Output is correct
17 Correct 1277 ms 98620 KB Output is correct
18 Correct 1338 ms 98476 KB Output is correct
19 Correct 1302 ms 98472 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 516 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 460 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 464 KB Output is correct
58 Correct 3 ms 860 KB Output is correct
59 Correct 2 ms 860 KB Output is correct
60 Correct 2 ms 1100 KB Output is correct
61 Correct 2 ms 860 KB Output is correct
62 Correct 2 ms 968 KB Output is correct
63 Correct 3 ms 860 KB Output is correct
64 Correct 3 ms 968 KB Output is correct
65 Correct 3 ms 860 KB Output is correct
66 Correct 3 ms 860 KB Output is correct
67 Correct 3 ms 860 KB Output is correct
68 Correct 4 ms 860 KB Output is correct
69 Correct 3 ms 860 KB Output is correct
70 Correct 2 ms 860 KB Output is correct
71 Correct 11 ms 3420 KB Output is correct
72 Correct 133 ms 16152 KB Output is correct
73 Correct 64 ms 15964 KB Output is correct
74 Correct 57 ms 16160 KB Output is correct
75 Correct 54 ms 15964 KB Output is correct
76 Correct 59 ms 16160 KB Output is correct
77 Correct 55 ms 15960 KB Output is correct
78 Correct 75 ms 15960 KB Output is correct
79 Correct 106 ms 15964 KB Output is correct
80 Correct 65 ms 15960 KB Output is correct
81 Correct 71 ms 16152 KB Output is correct
82 Correct 93 ms 15960 KB Output is correct
83 Correct 91 ms 16152 KB Output is correct
84 Correct 57 ms 16212 KB Output is correct
85 Correct 176 ms 39512 KB Output is correct
86 Correct 478 ms 98640 KB Output is correct
87 Correct 440 ms 98384 KB Output is correct
88 Correct 407 ms 98644 KB Output is correct
89 Correct 410 ms 98384 KB Output is correct
90 Correct 396 ms 98472 KB Output is correct
91 Correct 663 ms 98652 KB Output is correct
92 Correct 779 ms 98640 KB Output is correct
93 Correct 492 ms 98388 KB Output is correct
94 Correct 505 ms 98480 KB Output is correct
95 Correct 808 ms 98476 KB Output is correct
96 Correct 808 ms 98476 KB Output is correct
97 Correct 394 ms 98480 KB Output is correct