Submission #95101

# Submission time Handle Problem Language Result Execution time Memory
95101 2019-01-27T10:58:55 Z psmao Wiring (IOI17_wiring) C++14
13 / 100
38 ms 10752 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]);
	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]) 
			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)]);
		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);
			suf[d] = min(suf[d+1], dp[d] + pre[d] - s[i]*1ll*d);
			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 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 26 ms 5624 KB Output is correct
4 Correct 26 ms 5752 KB Output is correct
5 Correct 26 ms 6780 KB Output is correct
6 Correct 35 ms 8188 KB Output is correct
7 Correct 34 ms 8188 KB Output is correct
8 Correct 35 ms 8184 KB Output is correct
9 Correct 36 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 38 ms 10752 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '1202843397'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 292 KB Output is correct
2 Correct 30 ms 10372 KB Output is correct
3 Correct 31 ms 10588 KB Output is correct
4 Correct 32 ms 10488 KB Output is correct
5 Correct 32 ms 10616 KB Output is correct
6 Incorrect 2 ms 376 KB 3rd lines differ - on the 1st token, expected: '42', found: '34'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -