Submission #4422959


Source Code Expand

Copy
//#define NDEBUG

#pragma GCC optimize ("O3") // 最適化レベルの変更 O0〜O3 などを指定
#pragma GCC optimize("-O3,inline,omit-frame-pointer,unroll-loops")
#pragma warning(1:4456) // 多重forループ内での変数の2重定義を警告にする

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <array>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <math.h>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>

#include <memory>
#include <cassert>

#include <functional>
#include <chrono>

using namespace std;
using namespace chrono;

const int DX[] = {	0,	-1,	 0,	 1};
const int DY[] = { -1,	 0,	 1,	 0};

const int DX8[] = {	 0,	-1, -1, -1, 0, 1, 1,  1};
const int DY8[] = { -1, -1,  0,	 1, 1, 1, 0, -1};

namespace ValLib {

	typedef unsigned long long ull;

	template<typename Key, typename Value>
	using umap = std::unordered_map<Key, Value>;
	template<typename T>
	using uset = std::unordered_set<T>;
	template <typename T>
	using sptr = typename std::shared_ptr<T>;

	class NullStream {
	public:
		template<typename T> NullStream& operator<<(T const&) { return *this; }
	};

#ifdef NDEBUG
#define vcerr if(false) NullStream()
#define vendl nullptr
#else
#define vcerr std::cerr
#define vendl std::endl
#endif

	template<typename T>void fill(vector<T>&vec,const T&value){std::fill(vec.begin(),vec.end(),value);}
	template<typename T>void fill(vector<vector<T>>&vec,const T&value){for(vector<T>&t:vec)std::fill(t.begin(),t.end(),value);}
	template<typename T>void resize(vector<T>&vec,int size1){vec.resize(size1);}
	template<typename T>void resize(vector<T>&vec,int size1,const T& value){vec.resize(size1,value);}
	template<typename T>void resize(vector<vector<T>>&vec,int size1,int size2){vec.resize(size1);for(vector<T>&t:vec)t.resize(size2);}
	template<typename T>void resize(vector<vector<T>>&vec,int size1,int size2,const T& value){vec.resize(size1);for(vector<T>&t:vec)t.resize(size2,value);}
	template<typename T>void assign(vector<T>&vec,int size1,const T& value){vec.assign(size1,value);}
	template<typename T>void assign(vector<vector<T>>&vec,int size1,int size2,const T& value){vec.resize(size1);for(vector<T>&t:vec)t.assign(size2,value);}
	template<typename T>const typename vector<T>::const_iterator max_element(const vector<T>&vec){assert(!vec.empty());return std::max_element(vec.begin(),vec.end());}
	template<typename T,typename _Pr>const typename vector<T>::const_iterator max_element(const vector<T>&vec,_Pr lessThan){assert(!vec.empty());return std::max_element(vec.begin(),vec.end(),lessThan);}
	template<typename T>typename vector<T>::iterator min_element(vector<T>&vec){assert(!vec.empty());return std::min_element(vec.begin(),vec.end());}
	template<typename T>const typename vector<T>::const_iterator min_element(const vector<T>&vec){assert(!vec.empty());return std::min_element(vec.begin(),vec.end());}
	template<typename T,typename _Pr>const typename vector<T>::const_iterator min_element(const vector<T>&vec,_Pr lessThan){assert(!vec.empty());return std::min_element(vec.begin(),vec.end(),lessThan);}
	int accumulate(const vector<int>&vec){return std::accumulate(vec.begin(),vec.end(),0);}
	template<typename _Pr>int accumulate(const vector<int>&vec,_Pr func){return std::accumulate(vec.begin(),vec.end(),0,func);}
	double accumulate(const vector<double>&vec){return std::accumulate(vec.begin(),vec.end(),0.0);}
	template<typename _Pr>double accumulate(const vector<double>&vec,_Pr func){return std::accumulate(vec.begin(),vec.end(),0.0,func);}
	float accumulate(const vector<float>&vec){return std::accumulate(vec.begin(),vec.end(),0.f);}
	template<typename _Pr>float accumulate(const vector<float>&vec,_Pr func){return std::accumulate(vec.begin(),vec.end(),0.f,func);}
	template<typename T,typename _Pr>bool all_of(const vector<T>&vec,_Pr pred){return std::all_of(vec.begin(),vec.end(),pred);	}
	template<typename T,typename _Pr>bool any_of(const vector<T>&vec,_Pr pred){return std::any_of(vec.begin(),vec.end(),pred);}
	template<typename T,typename _Pr>bool none_of(const vector<T>&vec,_Pr pred){return std::none_of(vec.begin(),vec.end(),pred);}
	template<typename T>const typename vector<T>::const_iterator find(const vector<T>&vec,const T& val){return std::find(vec.begin(),vec.end(),val);}
	template<typename T,typename _Pr>const typename vector<T>::const_iterator find_if(const vector<T>&vec,_Pr pred){return std::find_if(vec.begin(),vec.end(),pred);}
	template<typename T>bool contains(const vector<T>&vec,const T& val){return std::find(vec.begin(),vec.end(),val) != vec.end();}
	template<typename T,typename _Pr>bool contains_if(const vector<T>&vec,_Pr pred){return std::find_if(vec.begin(),vec.end(),pred)!=vec.end();}
	template<typename T,typename _Pr>typename iterator_traits<const typename vector<T>::const_iterator>::difference_type count_if(const vector<T>&vec,_Pr pred){return std::count_if(vec.begin(),vec.end(),pred);}
	template<typename T>void sort(vector<T>&vec){std::sort(vec.begin(),vec.end());}
	template<typename T,typename _Pr>void sort(vector<T>&vec,_Pr pred){std::sort(vec.begin(),vec.end(),pred);}

	template<typename T,size_t N>void fill(array<T,N>&ary,const T& value){std::fill(ary.begin(),ary.end(),value);}
	template<typename T,size_t N,size_t M>void fill(array<array<T,M>,N>&ary,const T& value){ for(array<T,M>& t : ary) std::fill(t.begin(),t.end(),value);}
	template<typename T,size_t N,typename _Pr>const typename array<T,N>::const_iterator max_element(const array<T,N>&ary){assert(!ary.empty());return std::max_element(ary.begin(),ary.end());}
	template<typename T,size_t N,typename _Pr>const typename vector<T>::const_iterator max_element(const array<T,N>&ary){assert(!ary.empty());return std::max_element(ary.begin(),ary.end());}
	template<typename T,size_t N,typename _Pr>const typename array<T,N>::const_iterator max_element(const array<T,N>&ary,_Pr lessThan){assert(!ary.empty());return std::max_element(ary.begin(),ary.end(),lessThan);}
	template<typename T,size_t N,typename _Pr>const typename array<T,N>::const_iterator min_element(const array<T,N>&ary){assert(!ary.empty());return std::min_element(ary.begin(),ary.end());}
	template<typename T,size_t N,typename _Pr>const typename array<T,N>::const_iterator min_element(const array<T,N>&ary,_Pr lessThan){assert(!ary.empty());return std::min_element(ary.begin(),ary.end(),lessThan);}
	template<size_t N>int accumulate(const array<int,N>&ary){return std::accumulate(ary.begin(),ary.end(),0);}
	template<size_t N,typename _Pr>int accumulate(const array<int,N>&ary,_Pr func){return std::accumulate(ary.begin(),ary.end(),0,func);}
	template<size_t N>double accumulate(const array<double,N>&ary){return std::accumulate(ary.begin(),ary.end(),0.0);}
	template<size_t N,typename _Pr>double accumulate(const array<double,N>&ary,_Pr func){return std::accumulate(ary.begin(),ary.end(),0.0,func);}
	template<size_t N> float accumulate(const array<float,N>&ary){return std::accumulate(ary.begin(),ary.end(),0.f);}
	template<size_t N,typename _Pr>float accumulate(const array<float,N>&ary,_Pr func){return std::accumulate(ary.begin(),ary.end(),0.f,func);}
	template<typename T,size_t N,typename _Pr>bool all_of(const array<T,N>&ary,_Pr pred){return std::all_of(ary.begin(),ary.end(),pred);}
	template<typename T,size_t N,typename _Pr>bool any_of(const array<T,N>&ary,_Pr pred){return std::any_of(ary.begin(),ary.end(),pred);}
	template<typename T,size_t N,typename _Pr>bool none_of(const array<T,N>&ary,_Pr pred){return std::none_of(ary.begin(),ary.end(),pred);}
	template<typename T,size_t N>const typename array<T,N>::const_iterator find(const array<T,N>&ary,const T& val){return std::find(ary.begin(),ary.end(),val);}
	template<typename T,size_t N,typename _Pr>const typename array<T,N>::const_iterator find_if(const array<T,N>&ary,_Pr pred){return std::find_if(ary.begin(),ary.end(),pred);}
	template<typename T,size_t N>bool contains(const array<T,N>&ary,const T& val){return std::find(ary.begin(),ary.end(),val)!=ary.end();}
	template<typename T,size_t N,typename _Pr>bool contains_if(const array<T,N>&ary,_Pr pred){return std::find_if(ary.begin(),ary.end(),pred) != ary.end();}
	template<typename T,size_t N,typename _Pr>typename iterator_traits<const typename array<T,N>::const_iterator>::difference_type count_if(const array<T,N>&ary,_Pr pred){return std::count_if(ary.begin(),ary.end(),pred);}
	template<typename T,size_t N>void sort(array<T,N>&ary){std::sort(ary.begin(),ary.end());}
	template<typename T,size_t N,typename _Pr>void sort(array<T,N>&ary,_Pr pred){std::sort(ary.begin(),ary.end(),pred);}

	template<typename T>
	const typename uset<T>::const_iterator find(const uset<T>& s, const T& key) {
		return s.find(key);
	}

	inline bool same(double a, double b) {
		return abs(a - b) < 0.00000000001;
	}

	unsigned long long xor128() {
		static unsigned long long rx = 123456789, ry = 362436069, rz = 521288629, rw = 88675123;
		unsigned long long rt = (rx ^ (rx << 11));
		rx = ry;
		ry = rz;
		rz = rw;
		return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
	}
}

using namespace ValLib;

class Tank {
public:
	int cap;
	int amount;
	int index;
	
	Tank() : cap(0), amount(0), index(0) {}
};

class TankCombi {
public:
	int cap;
	int amount;
	vector<int> indexes;

	TankCombi() : cap(0), amount(0) {}
};

constexpr int MAX_TURN = 1000;
constexpr int N = 8;
int D, T;
array<Tank, N> gTanks;
vector<TankCombi> gTankCombis;

void input(int turn) {
	cin >> D >> T;
	for (int i = 0; i < N; ++i) {
		gTanks[i].index = i;
	}
	for (int i = 0; i < N; ++i) {
		cin >> gTanks[i].cap;
	}
	for (int i = 0; i < N; ++i) {
		cin >> gTanks[i].amount;
	}
	//sort(gTanks, [](const Tank& a, const Tank& b) { return a.cap < b.cap; });
}

void makePatterns(int x, TankCombi& combi) {
	if (x == 0) {
		gTankCombis.clear();
	}
	gTankCombis.push_back(combi);
	for (int i = x; i < N; ++i) {
		combi.amount += gTanks[i].amount;
		combi.cap += gTanks[i].cap;
		combi.indexes.push_back(gTanks[i].index);
		makePatterns(i + 1, combi);
		combi.amount -= gTanks[i].amount;
		combi.cap -= gTanks[i].cap;
		combi.indexes.pop_back();
	}
}

void fill(int index) {
	cout << "fill " << (index + 1) << endl;
}
void sell(const vector<int>& indexes) {
	cout << "sell ";
	cout << indexes.size();
	for (int i = 0; i < indexes.size(); ++i) {
		cout << " " << (indexes[i] + 1);
	}
	cout << endl;
}
void sell(int index) {
	vector<int> x(1, index);
	sell(x);
}
void pass() {
	cout << "pass" << endl;
}

void solve() {
	TankCombi tCombi;
	makePatterns(0, tCombi);
	for (int i = 0; i < N; ++i) {
		if (D == gTanks[i].amount) {
			sell(gTanks[i].index);
			return;
		}
	}
	for (int i = 0; i < N; ++i) {
		if (D == gTanks[i].cap) {
			fill(gTanks[i].index);
			return;
		}
	}
	for (int i = 0; i < gTankCombis.size(); ++i) {
		const TankCombi& combi = gTankCombis[i];
		if (combi.cap == D) {
			for (int j = 0; j < combi.indexes.size(); ++j) {
				const Tank& tank = gTanks[combi.indexes[j]];
				if (tank.cap != tank.amount) {
					fill(gTanks[combi.indexes[j]].index);
					return;
				}
			}
			vector<int> tankIndexes;
			for (int j = 0; j < combi.indexes.size(); ++j) {
				tankIndexes.push_back(combi.indexes[j]);
			}
			sell(tankIndexes);
			return;
		}
	}
	pass();
}

int main()
{
	std::ios::sync_with_stdio(false);

	for (int turn = 0; turn < MAX_TURN; ++turn) {
		input(turn);
		solve();
	}

}

Submission Info

Submission Time
Task A - 石油王Xの憂鬱
User ValGrowth
Language C++14 (GCC 5.4.1)
Score 5490018
Code Size 11770 Byte
Status
Exec Time 68 ms
Memory 724 KB

Judge Result

Set Name Score / Max Score Test Cases
test_01 109639 / 417500 subtask_01_01.txt
test_02 112856 / 417500 subtask_01_02.txt
test_03 103367 / 417500 subtask_01_03.txt
test_04 108230 / 417500 subtask_01_04.txt
test_05 109822 / 417500 subtask_01_05.txt
test_06 114680 / 417500 subtask_01_06.txt
test_07 113544 / 417500 subtask_01_07.txt
test_08 110088 / 417500 subtask_01_08.txt
test_09 117944 / 417500 subtask_01_09.txt
test_10 111213 / 417500 subtask_01_10.txt
test_11 120775 / 417500 subtask_01_11.txt
test_12 107984 / 417500 subtask_01_12.txt
test_13 119086 / 417500 subtask_01_13.txt
test_14 108511 / 417500 subtask_01_14.txt
test_15 108574 / 417500 subtask_01_15.txt
test_16 116607 / 417500 subtask_01_16.txt
test_17 109324 / 417500 subtask_01_17.txt
test_18 114775 / 417500 subtask_01_18.txt
test_19 110352 / 417500 subtask_01_19.txt
test_20 100347 / 417500 subtask_01_20.txt
test_21 110996 / 417500 subtask_01_21.txt
test_22 114466 / 417500 subtask_01_22.txt
test_23 99267 / 417500 subtask_01_23.txt
test_24 104484 / 417500 subtask_01_24.txt
test_25 112168 / 417500 subtask_01_25.txt
test_26 103781 / 417500 subtask_01_26.txt
test_27 109057 / 417500 subtask_01_27.txt
test_28 112334 / 417500 subtask_01_28.txt
test_29 109952 / 417500 subtask_01_29.txt
test_30 108876 / 417500 subtask_01_30.txt
test_31 117153 / 417500 subtask_01_31.txt
test_32 112563 / 417500 subtask_01_32.txt
test_33 113701 / 417500 subtask_01_33.txt
test_34 109139 / 417500 subtask_01_34.txt
test_35 120746 / 417500 subtask_01_35.txt
test_36 113543 / 417500 subtask_01_36.txt
test_37 111436 / 417500 subtask_01_37.txt
test_38 102979 / 417500 subtask_01_38.txt
test_39 106453 / 417500 subtask_01_39.txt
test_40 107017 / 417500 subtask_01_40.txt
test_41 102347 / 417500 subtask_01_41.txt
test_42 108848 / 417500 subtask_01_42.txt
test_43 114365 / 417500 subtask_01_43.txt
test_44 107685 / 417500 subtask_01_44.txt
test_45 99265 / 417500 subtask_01_45.txt
test_46 99903 / 417500 subtask_01_46.txt
test_47 109336 / 417500 subtask_01_47.txt
test_48 102643 / 417500 subtask_01_48.txt
test_49 109672 / 417500 subtask_01_49.txt
test_50 108125 / 417500 subtask_01_50.txt
Case Name Status Exec Time Memory
subtask_01_01.txt 62 ms 720 KB
subtask_01_02.txt 65 ms 616 KB
subtask_01_03.txt 66 ms 716 KB
subtask_01_04.txt 68 ms 668 KB
subtask_01_05.txt 67 ms 716 KB
subtask_01_06.txt 67 ms 724 KB
subtask_01_07.txt 66 ms 724 KB
subtask_01_08.txt 67 ms 668 KB
subtask_01_09.txt 62 ms 716 KB
subtask_01_10.txt 67 ms 720 KB
subtask_01_11.txt 66 ms 636 KB
subtask_01_12.txt 67 ms 724 KB
subtask_01_13.txt 67 ms 724 KB
subtask_01_14.txt 63 ms 668 KB
subtask_01_15.txt 66 ms 724 KB
subtask_01_16.txt 65 ms 724 KB
subtask_01_17.txt 64 ms 724 KB
subtask_01_18.txt 65 ms 724 KB
subtask_01_19.txt 68 ms 712 KB
subtask_01_20.txt 67 ms 720 KB
subtask_01_21.txt 67 ms 720 KB
subtask_01_22.txt 67 ms 716 KB
subtask_01_23.txt 68 ms 724 KB
subtask_01_24.txt 63 ms 720 KB
subtask_01_25.txt 67 ms 720 KB
subtask_01_26.txt 68 ms 716 KB
subtask_01_27.txt 67 ms 724 KB
subtask_01_28.txt 64 ms 724 KB
subtask_01_29.txt 68 ms 724 KB
subtask_01_30.txt 67 ms 616 KB
subtask_01_31.txt 64 ms 592 KB
subtask_01_32.txt 64 ms 624 KB
subtask_01_33.txt 65 ms 716 KB
subtask_01_34.txt 67 ms 720 KB
subtask_01_35.txt 68 ms 664 KB
subtask_01_36.txt 67 ms 592 KB
subtask_01_37.txt 67 ms 720 KB
subtask_01_38.txt 68 ms 720 KB
subtask_01_39.txt 68 ms 716 KB
subtask_01_40.txt 65 ms 664 KB
subtask_01_41.txt 64 ms 720 KB
subtask_01_42.txt 66 ms 724 KB
subtask_01_43.txt 68 ms 624 KB
subtask_01_44.txt 67 ms 724 KB
subtask_01_45.txt 67 ms 596 KB
subtask_01_46.txt 68 ms 720 KB
subtask_01_47.txt 63 ms 720 KB
subtask_01_48.txt 67 ms 588 KB
subtask_01_49.txt 68 ms 724 KB
subtask_01_50.txt 66 ms 724 KB