답안 #120114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120114 2019-06-23T12:03:27 Z MvC 전선 연결 (IOI17_wiring) C++14
0 / 100
26 ms 23936 KB
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#include "wiring.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const ll nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,i,j,t,g;
ll x,y,cur;
vector<ll>ans[nmax],mn[nmax],suf[nmax],bst[nmax],gr[nmax];
vector<pair<ll,int> >a;
ll min_total_length(vector<int>R,vector<int>B)
{
	n=R.size(),m=B.size();
	for(i=1;i<=n;i++)
	{
		x=R[i-1];
		a.pb(mkp(x,0));
	}
	for(i=1;i<=m;i++)
	{
		x=B[i-1];
		a.pb(mkp(x,1));
	}
	sort(a.begin(),a.end());
	for(i=0;i<n+m;i++)
	{
		if(!i || a[i-1].sc!=a[i].sc)g++;
		gr[g].pb(a[i].fr);
	}
	for(i=1;i<=g;i++)
	{
		for(j=gr[i].size()-1,t=0;j>=0;j--,t++)
		{
			suf[i].pb(0);
			ans[i].pb(0);
			bst[i].pb(0);
			mn[i].pb(0);
			suf[i][t]=gr[i].back()-gr[i][j];
			if(t)suf[i][t]+=suf[i][t-1];
		}
		if(i>1)
		{
			x=0;
			for(j=0;j<gr[i].size();j++)
			{
				x+=gr[i][j]-gr[i][0];
				y=1LL*(j+1)*(gr[i][0]-gr[i-1].back());
				cur=x+y+bst[i-1][min(j,(int)gr[i-1].size())];
				if(j+1<gr[i-1].size())cur=min(cur,x+mn[i-1][j+1]);
				ans[i][j]=cur;
			}
		}
		if(i<g)
		{
			for(j=gr[i].size()-1,t=0;j>=0;j--,t++)
			{
				bst[i][t]=suf[i][t];
				if(j)bst[i][t]+=ans[i][j-1];
				if(t)bst[i][t]=min(bst[i][t],bst[i][t-1]);
				mn[i][j]=suf[i][j]+1LL*(j+1)*(gr[i+1][0]-gr[i].back());
				if(t)mn[i][j]+=ans[i][t-1];
				if(j<gr[i].size()-1)mn[i][j]=min(mn[i][j],mn[i][j+1]);
			}
		}
	}
	return ans[g].back();
}

Compilation message

wiring.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("O3")
 
wiring.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization("unroll-loops")
 
wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:59:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(j=0;j<gr[i].size();j++)
            ~^~~~~~~~~~~~~
wiring.cpp:64:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(j+1<gr[i-1].size())cur=min(cur,x+mn[i-1][j+1]);
        ~~~^~~~~~~~~~~~~~~
wiring.cpp:77:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(j<gr[i].size()-1)mn[i][j]=min(mn[i][j],mn[i][j+1]);
        ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 23808 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21828'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 23808 KB 3rd lines differ - on the 1st token, expected: '904', found: '326'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 23936 KB 3rd lines differ - on the 1st token, expected: '316', found: '188'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 23808 KB 3rd lines differ - on the 1st token, expected: '27', found: '10'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 23808 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21828'
2 Halted 0 ms 0 KB -