답안 #129243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129243 2019-07-11T21:53:55 Z arthurconmy 쌀 창고 (IOI11_ricehub) C++14
49 / 100
22 ms 2440 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
using namespace std;

#ifndef ARTHUR_LOCAL
	#include "ricehub.h"
#endif

#ifdef ARTHUR_LOCAL
	#define ARTHUR_MAIN main
#endif

using ll = long long;

#define REP(i,a,b) \
for(ll i=int(a); i<=ll(b); i++)

#define len(x) ll(x.size())

int besthub(int R, int L, int X[], long long B)
{
	ll cur_budget = B + ll(L)*0;
	ll maxx=0;
	
	deque<ll> ahead;

	REP(i,0,R-1) ahead.push_back(ll(X[i]));

	deque<ll> cur_behind;
	deque<ll> cur_ahead;

	cur_behind.push_back(ll(X[0]));
	ahead.pop_front();

	while(cur_budget>0 && !ahead.empty()) // add as many rices as we can
	{
		if(cur_budget >= ahead.front()-ll(X[0]))
		{
			cur_budget -= ahead.front()-ll(X[0]);

			// cout << X[0] << " " << ahead.front() << endl;

			cur_ahead.push_back(ahead.front());
			ahead.pop_front();
		}

		else break;
	}

	maxx=len(cur_behind)+len(cur_ahead);

	// cout << cur_behind.size() << " " << cur_ahead.size() << endl;

	REP(i,1,R-1)
	{
		cur_budget -= (len(cur_behind)-len(cur_ahead))*ll(X[i]-X[i-1]);

		// cout << "THE CURRENT BUDGET IS " << cur_budget << " " << cur_behind.size() << endl;
		
		// move X[i] from cur_ahead to cur_behind

		if(!cur_ahead.empty()) cur_ahead.pop_front();
		else ahead.pop_front();
		cur_behind.push_back(ll(X[i])); 

		while(cur_budget < 0) 
		{
			cur_budget += ll(X[i])-cur_behind.front();
			cur_behind.pop_front();

			// cout << "HERE" << endl;
		}

		// cout << cur_budget << endl;

		while(cur_budget>0 && !ahead.empty() && ahead.front()-ll(X[i]) <= cur_budget)
		{
			cur_budget -= ahead.front()-ll(X[i]);
			cur_ahead.push_back(ahead.front());
			ahead.pop_front();
		}

		// cout << cur_budget << endl;
		// cout << X[i] << " " << len(cur_behind) << " " << len(cur_ahead) << endl;
		// cout << ahead.size() << endl;

		while(!ahead.empty() && !cur_behind.empty() && ahead.front() - ll(X[i]) <= ll(X[i]) - cur_behind.front())
		{
			cur_budget += ll(X[i]) + ll(X[i]) - cur_behind.front() - ahead.front();
			cur_behind.pop_front();
			cur_ahead.push_back(ahead.front());
			ahead.pop_front();

			while(cur_budget>0 && !ahead.empty() && ahead.front()-ll(X[i]) <= cur_budget)
			{
				cur_budget -= ahead.front()-ll(X[i]);
				cur_ahead.push_back(ahead.front());
				ahead.pop_front();
			} // yikes a lot of while loops
		}

		// cout << cur_budget << endl;

		maxx=max(maxx,len(cur_behind)+len(cur_ahead));

		// cout << X[i] << " " << len(cur_behind) << " " << len(cur_ahead) << endl;
		// cout << cur_budget << endl;

		// cur_behind.push_front()
	}

	return maxx;
}

// int X[5];

// int ARTHUR_MAIN()
// {
// 	X[0]=1;
// 	X[1]=2;
// 	X[2]=10;
// 	X[3]=12;
// 	X[4]=14;

// 	cout << besthub(5,20,X,6) << endl;

// 	return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 360 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 372 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 276 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Incorrect 2 ms 380 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 676 KB Output is correct
3 Correct 20 ms 2372 KB Output is correct
4 Correct 21 ms 2440 KB Output is correct
5 Correct 10 ms 1272 KB Output is correct
6 Correct 10 ms 1296 KB Output is correct
7 Correct 18 ms 2416 KB Output is correct
8 Correct 18 ms 2424 KB Output is correct
9 Correct 9 ms 1272 KB Output is correct
10 Correct 9 ms 1144 KB Output is correct
11 Correct 22 ms 2428 KB Output is correct
12 Correct 22 ms 2428 KB Output is correct
13 Correct 12 ms 1272 KB Output is correct
14 Correct 11 ms 1300 KB Output is correct
15 Correct 17 ms 1784 KB Output is correct
16 Correct 17 ms 1784 KB Output is correct
17 Correct 20 ms 2040 KB Output is correct
18 Correct 20 ms 2048 KB Output is correct
19 Correct 21 ms 2040 KB Output is correct
20 Correct 22 ms 2168 KB Output is correct