Submission #890245

# Submission time Handle Problem Language Result Execution time Memory
890245 2023-12-20T19:04:47 Z amirhoseinfar1385 Copy and Paste 3 (JOI22_copypaste3) C++17
Compilation error
0 ms 0 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const short maxn=2500+10;
short lcp[maxn][maxn],nxt[maxn][maxn],n;
long long dp[maxn][maxn],a,b,c,inf=1e15;
string s;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s;
	cin>>a>>b>>c;
	for(long long i=n-1;i>=0;i--){
		for(long long j=i+1;j<n;j++){
			if(s[i]==s[j]){
				lcp[i][j]=lcp[i+1][j+1]+1;
			}
		}
	}
	for(long long i=0;i<maxn;i++){
		for(long long j=0;j<maxn;j++){
			nxt[i][j]=n+3;
		}
	}
	for(long long i=0;i<n;i++){
		for(long long j=n-1;j>i;j--){
			nxt[i][min(lcp[i][j],j-i)]=j;
		}
		for(long long j=n;j>=0;j--){
			nxt[i][j]=min(nxt[i][j],nxt[i][j+1]);
		}
	}
	for(long long i=0;i<maxn;i++){
		for(long long j=0;j<maxn;j++){
			dp[i][j]=inf;
		}
	}
	for(long long i=n-1;i>=0;i--){
		dp[i][i]=a;
		for(long long j=i+1;j<n;j++){
			dp[i][j]=min(dp[i][j],min(dp[i+1][j],dp[i][j-1])+a);
		}
		for(long long j=1;j<n;j++){
			dp[i][j+i-1]=min(dp[i][j+i-1],min(dp[i+1][j+i-1],dp[i][j+i-2])+a);
			short ted=2;
			long long z=dp[i][j+i-1];
			for(long long h=nxt[i][j];h!=n+3;h=nxt[h][j]){
			//	cout<<i<<" "<<h<<" "<<j<<" "<<ted<<" "<<z<<" "<<endl;
				dp[i][h+j-1]=min(dp[i][h+j-1],z+c*ted+b+a*(h+j-i-(ted*j)));
				ted++;
			}
		}
		for(long long j=i+1;j<n;j++){
			dp[i][j]=min(dp[i][j],min(dp[i+1][j],dp[i][j-1])+a);
		}
	}
	cout<<dp[0][n-1]<<"\n";
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:29:28: error: no matching function for call to 'min(short int&, long long int)'
   29 |    nxt[i][min(lcp[i][j],j-i)]=j;
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from copypaste3.cpp:3:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
copypaste3.cpp:29:28: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'long long int')
   29 |    nxt[i][min(lcp[i][j],j-i)]=j;
      |                            ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from copypaste3.cpp:3:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
copypaste3.cpp:29:28: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'long long int')
   29 |    nxt[i][min(lcp[i][j],j-i)]=j;
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from copypaste3.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
copypaste3.cpp:29:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   29 |    nxt[i][min(lcp[i][j],j-i)]=j;
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from copypaste3.cpp:3:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
copypaste3.cpp:29:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   29 |    nxt[i][min(lcp[i][j],j-i)]=j;
      |                            ^