답안 #412998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412998 2021-05-28T01:14:00 Z joseacaz Snowball (JOI21_ho_t2) C++17
33 / 100
2500 ms 5648 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

const int MAXN = (int)2e5 + 5;
const ll INF = (1LL << 62LL);
int N, Q;
ll a[MAXN], spacesL[MAXN], spacesR[MAXN], W[MAXN];
ll l[MAXN], r[MAXN], pos;
ll finalL[MAXN], finalR[MAXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> Q;
	for(int i = 1; i <= N; i++)
		cin >> a[i];
	a[0] = -INF, a[N + 1] = INF;
	for(int i = 0; i <= N + 1; i++)
	{
		if(i < N + 1)
			spacesR[i] = a[i + 1] - a[i];
		if(i > 0)
			spacesL[i] = a[i] - a[i - 1];
	}
	
	for(int q = 1; q <= Q; q++)
	{
		cin >> W[q];
		pos += W[q];
		l[q] = min(l[q - 1], pos);
		r[q] = max(r[q - 1], pos);
		
		if(l[q] < l[q - 1])
		{
			//cerr << l[q] << " " << r[q] << "\n";
			ll delta = l[q - 1] - l[q];
			for(int i = 1; i <= N + 1; i++)
			{
				if(spacesL[i] > 0 && spacesL[i] - delta <= 0)
					finalL[i] = a[i] + l[q - 1] - spacesL[i];
				spacesL[i] -= delta;
				//cerr << spacesL[i] << " ";
			}
			//cerr << "\n";

			for(int i = 0; i <= N; i++)
			{
				if(spacesR[i] > 0 && spacesR[i] - delta <= 0)
					finalR[i] = a[i] + r[q - 1];
				spacesR[i] -= delta;
				//cerr << spacesR[i] << " ";
			}
			//cerr << "INF\n";
		}
		else if(r[q] > r[q - 1])
		{
			ll delta = r[q] - r[q - 1];
			//cerr << l[q] << " " << r[q] << "\n";
			//cerr << "INF" << " ";
			for(int i = 1; i <= N + 1; i++)
			{
				if(spacesL[i] > 0 && spacesL[i] - delta <= 0)
					finalL[i] = a[i] + l[q - 1];
				spacesL[i] -= delta;
				//cerr << spacesL[i] << " ";
			}
			//cerr << "\n";

			for(int i = 0; i <= N; i++)
			{
				if(spacesR[i] > 0 && spacesR[i] - delta <= 0)
					finalR[i] = a[i] + r[q - 1] + spacesR[i];
				spacesR[i] -= delta;
				//cerr << spacesR[i] << " ";
			}
			//cerr << "INF\n";
		}
	}
	
	for(int i = 1; i <= N; i++)
	{
		if(spacesL[i] > 0)
			finalL[i] = a[i] + l[Q];
		if(spacesR[i] > 0)
			finalR[i] = a[i] + r[Q];
		
		//cerr << finalL[i] << " " << finalR[i] << "\n";
			
		cout << finalR[i] - finalL[i] << "\n";
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 27 ms 516 KB Output is correct
5 Correct 28 ms 512 KB Output is correct
6 Correct 28 ms 508 KB Output is correct
7 Correct 24 ms 516 KB Output is correct
8 Correct 24 ms 504 KB Output is correct
9 Correct 13 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 27 ms 524 KB Output is correct
16 Correct 27 ms 504 KB Output is correct
17 Correct 23 ms 624 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 27 ms 516 KB Output is correct
5 Correct 28 ms 512 KB Output is correct
6 Correct 28 ms 508 KB Output is correct
7 Correct 24 ms 516 KB Output is correct
8 Correct 24 ms 504 KB Output is correct
9 Correct 13 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 452 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 27 ms 524 KB Output is correct
16 Correct 27 ms 504 KB Output is correct
17 Correct 23 ms 624 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 38 ms 5512 KB Output is correct
21 Correct 57 ms 5580 KB Output is correct
22 Correct 219 ms 5532 KB Output is correct
23 Correct 2491 ms 5648 KB Output is correct
24 Execution timed out 2589 ms 2280 KB Time limit exceeded
25 Halted 0 ms 0 KB -