Submission #1025594

# Submission time Handle Problem Language Result Execution time Memory
1025594 2024-07-17T07:56:43 Z amirhoseinfar1385 Wiring (IOI17_wiring) C++17
Compilation error
0 ms 0 KB
#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
const long long maxn=200000+10;
long long dp[maxn],inf=1e16,vas[maxn];
long long n,m;
vector<long long>allind;

long long min_total_length(std::vector<int> r, std::vector<int> b) {
	n=(long long)r.size();
	m=(long long)b.size();
	allind.push_back(-1);
	for(auto x:r){
		allind.push_back(x);
	}
	for(auto x:b){
		allind.push_back(x);
	}
	sort(allind.begin(),allind.end());
	allind.resize(unique(allind.begin(),allind.end())-allind.begin());
	for(long long i=0;i<n;i++){
		r[i]=lower_bound(allind.begin(),allind.end(),r[i])-allind.begin();
		vas[r[i]]=1;
	}
	for(long long i=0;i<m;i++){
		b[i]=lower_bound(allind.begin(),allind.end(),b[i])-allind.begin();
		vas[b[i]]=2;
	}
	for(long long i=1;i<maxn;i++){
		dp[i]=inf;
	}
	dp[0]=0;
	if(sz!=n+m+1){
		exit(23);
	}
	long long sz=(long long)allind.size();
	for(long long i=1;i<sz;i++){
		long long av=allind[i],unnow=0,last=i,bar=0,akh;
		for(long long j=i-1;j>=1;j--){
			if(vas[j]==vas[i]&&vas[j]!=vas[j+1]){
				break;
			}
			if(vas[j]==vas[i]){
				last=j;
				unnow+=av;
				av=allind[j];
			}else{
				bar+=allind[j];
				akh=allind[last-1];
				long long ted1=i-last+1;
				long long ted2=(last-1)-j+1;
				dp[i]=min(dp[i],dp[j-1]+unnow-(bar-akh)+max(1ll,ted2-ted1+1)*av-max(1ll,ted1-ted2+1)*akh);
			}
		}
	}
	return dp[sz-1];
}

Compilation message

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:33:5: error: 'sz' was not declared in this scope
   33 |  if(sz!=n+m+1){
      |     ^~