Submission #95106

# Submission time Handle Problem Language Result Execution time Memory
95106 2019-01-27T11:17:34 Z psmao Wiring (IOI17_wiring) C++14
13 / 100
41 ms 10748 KB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;
 
void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 200050;

int n, m, s[maxn], belong[maxn], sz[maxn], col[maxn];
ll pre[maxn], dp[maxn], suf[maxn], pref[maxn];

int jud(int cur, int x)
{
	x = max(x, sz[cur-2] + 1);
	return x;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) 
{
	n = SZ(r); m = SZ(b);
	int i = 0, j = 0, tot = 0;
	while(i < n && j < m) //merge them together
	{
		if(r[i] < b[j]) {s[++tot] = r[i++]; col[tot] = 0;}
		else {s[++tot] = b[j++]; col[tot] = 1;}
	}
	while(i < n) {s[++tot] = r[i++]; col[tot] = 0;}
	while(j < m) {s[++tot] = b[j++]; col[tot] = 1;}
	fo(i,1,tot) pre[i] = pre[i-1] + s[i];
	int num = 0;
	fo(i,1,tot) 
	{
		++ num; sz[num] = sz[num - 1];
		int j = i;
		while(j <= tot && col[j] == col[i]) 
		{
			belong[j] = num;
			sz[num] ++;
			++ j;
		}
		i = j - 1;
	}
	fo(i,sz[1]+1,tot)
	{
		int cur = belong[i], d = sz[cur-1];
		//2d-i <= j <= d
		if(cur == 2) 
		{
			if(i - d >= d) dp[i] = pre[i] - 2 * pre[d] - s[d]*1ll*i + 2ll*s[d]*d;
			else dp[i] = pre[i] - 2 * pre[d] + 2ll*d*s[d+1] - 1ll*i*s[d+1];
			goto gg;
		}
		dp[i] = suf[jud(cur, 2*d-i)] + pre[i] - 2*pre[d] - s[d]*1ll*i + 2ll*s[d]*d;
		// j < 2d-i
		if(2*d-i >= sz[cur-2] + 1) 
			dp[i] = min(dp[i], pre[i] - 2*pre[d] + 2ll*d*s[d+1] - 1ll*i*s[d+1] + pref[jud(cur,2*d-i)]);
		if(i == 9) D("%lld\n",dp[sz[cur-2]]+pre[i]-pre[d]-(pre[i]-pre[sz[cur-2]]));
		if(i-d>=sz[cur-1]-sz[cur-2]) 
			dp[i] = min(dp[i], dp[sz[cur-2]] + pre[i] - 2*pre[d] + pre[sz[cur-2]] - 1ll*s[d]*(i-d-sz[cur-1]+sz[cur-2]));
		else
			dp[i] = min(dp[i], dp[sz[cur-2]] + pre[i] - 2*pre[d] + pre[sz[cur-2]] + 1ll*s[d+1]*(sz[cur-1]-sz[cur-2]-i+d));
		gg:; 
		if(belong[i+1] != belong[i])
		{
			suf[i] = INF;
			fd(j,i-1,d+1) suf[j] = min(suf[j+1], dp[j] + pre[j] - 1ll * s[i] * j);
			pref[d] = INF;
			fo(j,d+1,i-1) pref[j] = min(pref[j-1], dp[j] + pre[j] + 1ll * s[i+1] * j);
			// if(i == 4) cout << pref[1] << endl;
		}
		D("%d %lld\n",i,dp[i]);
	}
	return dp[tot];
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21937'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 26 ms 5624 KB Output is correct
4 Correct 25 ms 5624 KB Output is correct
5 Correct 27 ms 6776 KB Output is correct
6 Correct 34 ms 8184 KB Output is correct
7 Correct 35 ms 8312 KB Output is correct
8 Correct 34 ms 8188 KB Output is correct
9 Correct 35 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 41 ms 10748 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '1291754052'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB 3rd lines differ - on the 1st token, expected: '27', found: '23'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB 3rd lines differ - on the 1st token, expected: '25859', found: '21937'
2 Halted 0 ms 0 KB -