Submission #567889

#TimeUsernameProblemLanguageResultExecution timeMemory
567889dantoh000Copy and Paste 3 (JOI22_copypaste3)C++14
0 / 100
1 ms596 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
string s;
int a,b,c;
ll mem[205][205];
ll dp(int i, int j){
    if (i == j){
        return a;
    }
    else if (mem[i][j] != -1) return mem[i][j];
    ll ans = min(dp(i+1,j) + a, dp(i, j-1) + a);
    for (int k = i; k < j; k++){
        int len = k-i+1;
        int cur = k+1;
        ll cons = dp(i,k);
        ll C = cons + b;
        while (cur+len <= j){
            bool can = true;
            for (int L = 0; L < len; L++){
                if (s[cur+L] != s[i+L]) can = false;
            }
            if (can){
                C += c;
                cur += len;
            }
            else{
                C += a;
                cur++;
            }
        }
        C += (ll)(j-cur+1)*a;
        ans = min(ans,C);
    }
    return mem[i][j] = ans;
}


int main(){
    scanf("%d",&n);
    cin >> s;
    scanf("%d%d%d",&a,&b,&c);
    memset(mem,-1,sizeof(mem));
    printf("%d\n",dp(0,n-1));
}

Compilation message (stderr)

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:45:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll' {aka 'long long int'} [-Wformat=]
   45 |     printf("%d\n",dp(0,n-1));
      |             ~^    ~~~~~~~~~
      |              |      |
      |              int    ll {aka long long int}
      |             %lld
copypaste3.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
copypaste3.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d%d%d",&a,&b,&c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...