Artifact Content
Not logged in

Artifact a4eff36568a9a1cec4257f72f8c1e4995fa24b81


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class PlugStuffIn { public:
	vector <int> plug(vector <int> gadgets)
	{
		vector<int> idx;
		for (int i = 0; i < gadgets.size(); ++i)
			idx.push_back(i);
		sort(idx.begin(), idx.end(), [&](int a, int b) {
			return gadgets[a] > gadgets[b];
		});

		vector<int> ans(gadgets.size(), -1);

		deque<int> s;
		s.push_back(gadgets.size());
		for (int i : idx)
			if (s.empty()) {
				if (gadgets[i] == 0)
					return vector<int>();
				ans[i] = -1;
			}
			else {
				ans[i] = s.front();
				s.pop_front();
				for (int k = 0; k < gadgets[i]; ++k)
					s.push_back(i);
			}

		return ans;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <int>& Expected, const vector <int>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, PlugStuffIn().plug(gadgets));}
int main(){

CASE(0)
	int gadgets_[] = {0};
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	int __[] = {1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int gadgets_[] = {1, 1, 0, 1, 1, 1};
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	int __[] = {-1, -1, 4, -1, 6, -1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int gadgets_[] = {1, 1, 0, 1, 1, 1, 0};
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	vector <int> _; 
END
CASE(3)
	int gadgets_[] = {0, 0, 2, 0, 2};
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	int __[] = {2, 4, 5, 4, 2 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int gadgets_[] = {0, 3, 3};
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	int __[] = {3, 2, 1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	int gadgets_[] = {10, 20, 30, 40};
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	int __[] = {-1, 1, -1, -1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(6)
	int gadgets_[] = ;
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(7)
	int gadgets_[] = ;
	  vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE