Submission #43178

# Submission time Handle Problem Language Result Execution time Memory
43178 2018-03-10T11:26:35 Z yusufake Wiring (IOI17_wiring) C++
0 / 100
7 ms 6792 KB
#include<bits/stdc++.h>
 
using namespace std;

#define pb push_back
#define mp make_pair
#define st first
#define nd second  
 
typedef long long ll;

const ll inf = 1e18 + 1; 
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

pair < ll , int > T[N];
ll L[N],R[N],t,dp[N],p[N];

void bld(ll l, ll r, ll x, ll y){
	ll i,sz,p=0;
	for(sz=1,i=r; i>=l ;i--, sz++){
		p += T[i].st;
		L[sz] = min(dp[i],dp[i-1]) - p + sz*x;
		R[sz] = min(dp[i],dp[i-1]) - p - sz*y;
	}
}	

ll min_total_length(vector < int > a, vector < int > b){
	int n,m,i,j;
	n = a.size();  m = b.size();
	for(i=j=0; i<n || j<m ;){
		if(j == m || (i < n && a[i]<b[j])) T[++t] = mp(a[i++],1);
		else T[++t] = mp(b[j++],2);
    }
	
	ll l,r,x,y,sz,mn,k;
	memset(L , 22 , sizeof L);
	memset(R , 22 , sizeof R);
	for(i=1;T[i].nd == T[i+1].nd ; i++) dp[i] = inf;
	l = 1; r = i;
	for(i++;i<=t;i = r+1){
		for(j=i ;T[j].nd == T[j+1].nd ; j++);
		x = T[i].st;
		y = T[i-1].st;
		bld(l,r,x,y);
		
		mn = inf;
		for(sz=1,k=i;k<=j;k++,sz++){
			p[sz] = p[sz-1] + T[k].st;
			mn = min(mn , R[sz]);
			dp[k] = mn + p[sz] + sz*y;
		}
		mn = inf;
		for(sz=j-i+1,k=j; k>=i ;k--,sz--){
			mn = min(mn , L[sz]);
			dp[k] = min(dp[k] , mn + p[sz] - sz*x);
		}
		
		for(k=1;k<=r-l;k++) L[i] = R[i] = inf;
		l = i; r = j;
	}
    
    return dp[t];
}

//int main(){
//    cout << min_total_length({1, 2, 3, 7}, {0, 4, 5, 9, 10});
//}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 6520 KB 3rd lines differ - on the 1st token, expected: '25859', found: '22448'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 6624 KB 3rd lines differ - on the 1st token, expected: '904', found: '1810'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 6720 KB Output is correct
2 Incorrect 6 ms 6772 KB 3rd lines differ - on the 1st token, expected: '17703', found: '18016'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 6792 KB 3rd lines differ - on the 1st token, expected: '27', found: '18'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 6520 KB 3rd lines differ - on the 1st token, expected: '25859', found: '22448'
2 Halted 0 ms 0 KB -