제출 #556087

#제출 시각아이디문제언어결과실행 시간메모리
556087600MihneaCopy and Paste 3 (JOI22_copypaste3)C++17
25 / 100
3094 ms29576 KiB
#include <bits/stdc++.h>

bool home = 1;

using namespace std;

typedef long long ll;
const int N=2500+7;
const ll INF=(ll)1e18+7;
int n;
int v[N];
int lcp[N][N];
ll a, b, c, dp[N][N];

signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif

  home=0;

  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }


  cin>>n;

  {
    string str;
    cin>>str;
    assert((int)str.size()==n);

    for(int i=1;i<=n;i++){
      v[i]=str[i-1]-'a';
      assert(0<=v[i]&&v[i]<26);
    }
    cin>>a>>b>>c;
  }

  for (int i=n;i>=1;i--) {
    for (int j=n;j>=1;j--) {
      if (v[i]==v[j]){
        lcp[i][j]=1+lcp[i+1][j+1];
      }
    }
  }

  for (int l=n;l>=1;l--) {
    for (int r=l;r<=n;r++) {
      ll sol=INF;
      int i=l;
      for(int j=i;j<r;j++){
        int len=j-i+1,cnt=0;

        int k=l;

        while (k+len-1<=r) {
          if (lcp[k][i]>=len) {
            k+=len;
            cnt++;
          }else{
            k++;
          }
        }
        sol=min(sol,dp[i][j]+cnt*(c-a*len));
      }

      dp[l][r]=min(sol+a*(r-l+1)+b,min(dp[l+1][r],dp[l][r-1])+a);
    }
  }

  cout<<dp[1][n]<<"\n";
}

컴파일 시 표준 에러 (stderr) 메시지

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...