QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322377#6770. AntsYarema#WA 0ms3560kbC++142.1kb2024-02-06 22:39:202024-02-06 22:39:21

Judging History

This is the latest submission verdict.

  • [2024-02-06 22:39:21]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3560kb
  • [2024-02-06 22:39:20]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;


int n, L, R;
int len = 1'000'000'001;
VI a, d;

LL ht(int i, LL t)
{
	LL ds = a[i];
	if (d[i] == 1)
		ds += 2 * (len - a[i]);
	if (ds > t)
		return 0;
	return 1 + (t - ds) / (2 * len);
}


LL solve(int f)
{
	if (f)
	{
		swap(L, R);
		FOR (i, 0, n)
		{
			a[i] = len - a[i];
			d[i] = 1 - d[i];
		}
	}
	LL l = 0, r = 1e18;
	while (l + 1 < r)
	{
		LL m = (l + r) / 2;
		LL hits = 0;
		FOR (i, 0, n)
		{
			hits += ht(i, m);
		}
		if (hits >= L)
			r = m;
		else
			l = m;
	}
	if (f)
	{
		swap(L, R);
		FOR (i, 0, n)
		{
			a[i] = len - a[i];
			d[i] = 1 - d[i];
		}
	}
	return r;
}	

int pos(int i, LL t)
{
	t %= 2 * len;
	LL ps = a[i];
	int dir = d[i];
	//cerr << "POS\n";
	//cerr << ps << ' ' << dir << ' ' << t << '\n';
	if (d[i] == 0)
	{
		LL x = min(ps, t);
		ps -= x;
		t -= x;
		if (ps == 0)
			dir = 1;
		ps += t;
		if (ps >= len)
		{
			dir = 0;
			ps = 2 * len - ps;
		}
	}
	else
	{
		LL x = min(len - ps, t);
		ps += x;
		t -= x;
		if (ps == len)
			dir = 0;
		ps -= t;
		if (ps <= 0)
		{
			dir = 1;
			ps = abs(ps);
		}
	}
	//cerr << ps << ' ' << dir << ' ' << t << '\n';
	if (dir == 1)
		return 2 * (len - ps) + ps;
	return ps;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> L >> R;
	a.resize(n);
	d.resize(n);
	FOR (i, 0, n)
		cin >> a[i];
	FOR (i, 0, n)
		cin >> d[i];
	
	LL t1 = solve(0);
	LL t2 = solve(1);
	
	//cerr << t1 << ' ' << t2 << '\n';
	
	vector<LL> ans(n);
	FOR (i, 0, n)
	{
		ans[i] = t1 + pos(i, t1);
		a[i] = len - a[i];
		d[i] = 1 - d[i];
		ans[i] = min(ans[i], t2 + pos(i, t2));
	}
	cout << *max_element(ALL(ans)) << '\n';
	
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3524kb

input:

2 2 4
2 3
0 1

output:

4000000001

result:

ok single line: '4000000001'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3560kb

input:

1 1000000000 1000000000
500000000
0

output:

1000000000499999999

result:

wrong answer 1st lines differ - expected: '2000000002500000000', found: '1000000000499999999'