제출 #1309051

#제출 시각아이디문제언어결과실행 시간메모리
1309051alsoyangShortcut (IOI16_shortcut)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 1000005;
const ll inf = 1e18;

ll x[maxn], d[maxn];
int n, C;
pair<ll, int> q[maxn];
int ans1, ans2;

bool can(ll diam)
{
// 	cout << "can " << diam << endl;
	bool needleft = false;
	ll maxsum = inf;
	ll minsum = -inf;
	ll maxdif = inf;
	ll mindif = -inf;
	pair<ll, ll> mostleft = {inf, -inf};
	pair<ll, ll> mostright = {-inf, -inf};
	int l = 0;
	int r = 0;
	for (int i = 0; i < n; i++)
	{
		// no need to check whether it is "small" or not, because in case of "small" its square is inside "big"'s square
		while (r > l && x[i] - q[l].fi + d[i] > diam)
		{
			int wh = q[l].se;
			l++;
			if (x[wh] - d[wh] < mostleft.fi - mostleft.se) mostleft = {x[wh], d[wh]};
			if (x[wh] + d[wh] > mostright.fi + mostright.se) mostright = {x[wh], d[wh]};
			needleft = true;
		}
		if (needleft)
		{
			maxsum = min(maxsum, (mostleft.fi + diam - C - d[i] - mostleft.se) + x[i]);
			minsum = max(minsum, (mostright.fi - (diam - C - d[i] - mostright.se)) + x[i]);
			maxdif = min(maxdif, x[i] - (mostright.fi - (diam - C - d[i] - mostright.se)));
			mindif = max(mindif, x[i] - (mostleft.fi + diam - C - d[i] - mostleft.se));
		}
		while (r > l && q[r - 1].fi > x[i] - d[i]) r--;
		q[r++] = {x[i] - d[i], i};
	}
// 	cout << minsum << ' ' << maxsum << ' ' << mindif << ' ' << maxdif << endl;
	if (maxsum < minsum || maxdif < mindif) return false;
	int curdif = 0;
	int cursum = n;
	for (int i = 0; i < n; i++)
	{
		while (curdif < n && x[curdif] - x[i] < mindif) curdif++;
		while (cursum > 0 && x[cursum - 1] + x[i] >= minsum) cursum--;
		int cur = max({cursum, curdif, i + 1});
		if (cur < n && x[cur] + x[i] <= maxsum && x[cur] - x[i] <= maxdif)
		{
			ans1 = i;
			ans2 = cur;
			return true;
		}
	}
	return false;
}

long long find_shortcut(int N, vector <int> L0, vector <int> L, int C_)
{
	n = N;
	C = C_;
	ll cursum = 0;
	for (int i = 0; i < n; i++)
	{
		d[i] = L[i];
		x[i] = cursum;
		if (i + 1 < n) cursum += L0[i];
	}
	ll l = 0;
	ll r = inf;
	while (r - l > 1)
	{
		ll mid = (l + r) / 2;
		if (can(mid)) r = mid;
		else l = mid;
	}
	can(r);
	return r;
}

// BEGIN CUT
int main()
{
	int n, c;
	scanf("%d%d", &n, &c);
	
	vector <int> l(n - 1);
	vector <int> d(n);
	for (int i = 0; i < n - 1; i++)
	    scanf("%d", &l[i]);
	for (int i = 0; i < n; i++)
	    scanf("%d", &d[i]);
	    
	long long t = find_shortcut(n, l, d, c);
	
	// BEGIN SECRET
    puts("14e047d7a2907b9034950b074822b302");
    // END SECRET
    
	printf("%lld\n", t);
	
	return 0;
}
// END CUT

컴파일 시 표준 에러 (stderr) 메시지

shortcut.cpp: In function 'int main()':
shortcut.cpp:109:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         scanf("%d%d", &n, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~
shortcut.cpp:114:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |             scanf("%d", &l[i]);
      |             ~~~~~^~~~~~~~~~~~~
shortcut.cpp:116:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |             scanf("%d", &d[i]);
      |             ~~~~~^~~~~~~~~~~~~
shortcut.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
shortcut_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
/usr/bin/ld: /tmp/ccHZgCbu.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccqj5peW.o:shortcut.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status