Submission #380234

# Submission time Handle Problem Language Result Execution time Memory
380234 2021-03-20T16:05:08 Z peijar Snowball (JOI21_ho_t2) C++17
100 / 100
1304 ms 17004 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 1e18;

signed main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int nbBonhommes, nbNeiges;
	cin >> nbBonhommes >> nbNeiges;
	vector<int> posBonhommes(nbBonhommes);
	for (auto &v : posBonhommes) cin >> v;

	vector<int> quantiteNeige(nbNeiges);
	for (auto &v : quantiteNeige)
		cin >> v;

	vector<int> cumulNeige(nbNeiges+1);
	vector<int> maxNeige(nbNeiges+1);
	vector<int> minNeige(nbNeiges+1);
	for (int iNeige = 0; iNeige < nbNeiges; ++iNeige) 
	{
		cumulNeige[iNeige+1] = cumulNeige[iNeige] + quantiteNeige[iNeige];
		minNeige[iNeige+1] = min(minNeige[iNeige], cumulNeige[iNeige+1]);
		maxNeige[iNeige+1] = max(maxNeige[iNeige], cumulNeige[iNeige+1]);
	}

	vector<int> tailleFinale(nbBonhommes);
	for (int iBonhomme(0); iBonhomme < nbBonhommes; ++iBonhomme)
	{
		int extremGauche(INF), extremDroite(INF);
		// A gauche ? 
		if (!iBonhomme)
			extremGauche = min(posBonhommes[iBonhomme], posBonhommes[iBonhomme] + minNeige[nbNeiges]);
		else
		{
			int lo(posBonhommes[iBonhomme-1]), up(posBonhommes[iBonhomme]);
			while (lo < up)
			{
				int mid = lo + (up - lo) / 2;
				if (minNeige[nbNeiges] + posBonhommes[iBonhomme] > mid)
				{
					lo = mid+1;
					continue;
				}
				int loBis(0), upBis(nbNeiges);
				while (loBis < upBis)
				{
					int midBis = (loBis + upBis) / 2;
					if (minNeige[midBis] + posBonhommes[iBonhomme] > mid)
						loBis = midBis + 1;
					else
						upBis = midBis;
				}
				int premierDepassement = loBis;
				if (premierDepassement and maxNeige[premierDepassement-1] + posBonhommes[iBonhomme-1] >= mid+1)
				{
					lo = mid+1;
					continue;
				}
				if (posBonhommes[iBonhomme-1] + cumulNeige[premierDepassement] >= mid + 1 
						and mid+1 - (posBonhommes[iBonhomme-1] + cumulNeige[premierDepassement-1]) < (posBonhommes[iBonhomme] + cumulNeige[premierDepassement-1]) - mid)
					lo = mid+1;
				else
					up = mid;
			}
			extremGauche = lo;
		}
		if (iBonhomme == nbBonhommes-1)
			extremDroite = max(posBonhommes[iBonhomme], posBonhommes[iBonhomme] + maxNeige[nbNeiges]);
		else
		{
			int lo(posBonhommes[iBonhomme]), up(posBonhommes[iBonhomme+1]);
			while (lo < up)
			{
				int mid = lo + (up - lo + 1) / 2;
				if (maxNeige[nbNeiges] + posBonhommes[iBonhomme] < mid)
				{
					up = mid-1;
					continue;
				}
				int premierDepassement = 
					lower_bound(maxNeige.begin(), maxNeige.end(), mid - posBonhommes[iBonhomme]) - maxNeige.begin();
				if (premierDepassement and minNeige[premierDepassement-1] + posBonhommes[iBonhomme+1] <= mid-1)
				{
					up = mid-1;
					continue;
				}
				if ( posBonhommes[iBonhomme+1] + cumulNeige[premierDepassement] <= mid - 1 and   posBonhommes[iBonhomme+1] + cumulNeige[premierDepassement-1] - mid -1< mid- (posBonhommes[iBonhomme] + cumulNeige[premierDepassement-1]))
					up = mid-1;
				else
					lo = mid;
			}
			extremDroite = lo;
		}
		tailleFinale[iBonhomme] = extremDroite - extremGauche;	
	}
	for (auto v : tailleFinale)
		cout << v << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 7 ms 492 KB Output is correct
6 Correct 6 ms 492 KB Output is correct
7 Correct 5 ms 492 KB Output is correct
8 Correct 5 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 8 ms 492 KB Output is correct
16 Correct 7 ms 492 KB Output is correct
17 Correct 4 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 7 ms 492 KB Output is correct
6 Correct 6 ms 492 KB Output is correct
7 Correct 5 ms 492 KB Output is correct
8 Correct 5 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 8 ms 492 KB Output is correct
16 Correct 7 ms 492 KB Output is correct
17 Correct 4 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 34 ms 8684 KB Output is correct
21 Correct 33 ms 8556 KB Output is correct
22 Correct 42 ms 8300 KB Output is correct
23 Correct 44 ms 8292 KB Output is correct
24 Correct 150 ms 8684 KB Output is correct
25 Correct 1304 ms 15076 KB Output is correct
26 Correct 1282 ms 15084 KB Output is correct
27 Correct 1176 ms 14736 KB Output is correct
28 Correct 1166 ms 14900 KB Output is correct
29 Correct 1037 ms 14444 KB Output is correct
30 Correct 606 ms 13740 KB Output is correct
31 Correct 103 ms 13164 KB Output is correct
32 Correct 77 ms 13292 KB Output is correct
33 Correct 89 ms 1900 KB Output is correct
34 Correct 1097 ms 15556 KB Output is correct
35 Correct 1087 ms 14956 KB Output is correct
36 Correct 1247 ms 15084 KB Output is correct
37 Correct 1117 ms 14884 KB Output is correct
38 Correct 1137 ms 14976 KB Output is correct
39 Correct 1145 ms 14956 KB Output is correct
40 Correct 533 ms 14860 KB Output is correct
41 Correct 38 ms 9324 KB Output is correct
42 Correct 79 ms 13420 KB Output is correct
43 Correct 312 ms 16620 KB Output is correct
44 Correct 38 ms 9196 KB Output is correct
45 Correct 502 ms 14972 KB Output is correct
46 Correct 311 ms 16748 KB Output is correct
47 Correct 316 ms 16876 KB Output is correct
48 Correct 187 ms 17004 KB Output is correct