Submission #555006

# Submission time Handle Problem Language Result Execution time Memory
555006 2022-04-29T21:24:47 Z UncoolAnon Copy and Paste 3 (JOI22_copypaste3) C++14
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>
#define int long long 
using namespace std; 
const int inf=1e9*1e5; 
int n,a,b,c; string s; 
vector<int> z(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int solve(string s){
	int n=s.size(); 
	vector<int> p=z(s),dp(n,inf); 
	vector<vector<int>> A(n+1); 
	set<int> cur;
	for(int i=1;i<n;i++){
		A[p[i]].push_back(i); 
		cur.insert(i); 
	}
	dp[0]=a; 
	for(int i=0;i<n;i++){	
		for(int x:A[i]) cur.erase(x); 
		if(i) dp[i]=min(dp[i],dp[i-1]+a); 
		int mx=1;
		int last=i;
		while(1){
			auto it = cur.lower_bound(last+1); 
			if(it==cur.end()) break; 
			last=*it+i;
			mx++;
			dp[last]=min(dp[last],dp[i]+b+c*mx+a*(last+1-mx*(i+1))); 
		}
	}
	return dp.back(); 
}
signed main(){
	ios_base::sync_with_stdio(0); 
	cin.tie(nullptr); 
	freopen("in.txt","r",stdin); 
	cin>>n>>s>>a>>b>>c; 
	reverse(s.begin(),s.end()); 
	int answer=a*n; 
	for(int i=0;i<n;i++){
		string ns;
		for(int j=i;j<n;j++)ns+=s[j]; 
		answer=min(answer,solve(ns)+a*i);
	}
	cout << answer; 
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  freopen("in.txt","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -