제출 #556190

#제출 시각아이디문제언어결과실행 시간메모리
556190600MihneaCopy and Paste 3 (JOI22_copypaste3)C++17
100 / 100
1401 ms58444 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=1;l<=n;l++) {
    for (int r=l;r<=n;r++) {
      dp[l][r]=INF;
    }
  }

  for (int l=n;l>=1;l--) {
    for (int len=1;l+len<=n;len++) {
      vector<int> pivots;

      int k=l+len;

      while (k+len-1<=n) {
        if (lcp[l][k]>=len) {
          pivots.push_back(k);
          k+=len;
        }else{
          k++;
        }
      }
      for (int i=0;i<(int) pivots.size();i++) {
        int r=pivots[i]+len-1;
        dp[l][r]=min(dp[l][r],dp[r-len+1][r]+(i+2)*(c-a*len));
      }
    }
    for (int r=l;r<=n;r++){
      dp[l][r]=min(dp[l][r]+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...