cf074c940a 2022-05-21 kinaba: #include <iostream> cf074c940a 2022-05-21 kinaba: #include <sstream> cf074c940a 2022-05-21 kinaba: #include <iomanip> cf074c940a 2022-05-21 kinaba: #include <vector> cf074c940a 2022-05-21 kinaba: #include <string> cf074c940a 2022-05-21 kinaba: #include <map> cf074c940a 2022-05-21 kinaba: #include <set> cf074c940a 2022-05-21 kinaba: #include <algorithm> cf074c940a 2022-05-21 kinaba: #include <numeric> cf074c940a 2022-05-21 kinaba: #include <iterator> cf074c940a 2022-05-21 kinaba: #include <functional> cf074c940a 2022-05-21 kinaba: #include <complex> cf074c940a 2022-05-21 kinaba: #include <queue> cf074c940a 2022-05-21 kinaba: #include <stack> cf074c940a 2022-05-21 kinaba: #include <cmath> cf074c940a 2022-05-21 kinaba: #include <cassert> cf074c940a 2022-05-21 kinaba: #include <tuple> cf074c940a 2022-05-21 kinaba: using namespace std; cf074c940a 2022-05-21 kinaba: typedef long long LL; cf074c940a 2022-05-21 kinaba: typedef complex<double> CMP; cf074c940a 2022-05-21 kinaba: cf074c940a 2022-05-21 kinaba: class PlugStuffIn { public: cf074c940a 2022-05-21 kinaba: vector <int> plug(vector <int> gadgets) cf074c940a 2022-05-21 kinaba: { cf074c940a 2022-05-21 kinaba: vector<int> idx; cf074c940a 2022-05-21 kinaba: for (int i = 0; i < gadgets.size(); ++i) cf074c940a 2022-05-21 kinaba: idx.push_back(i); cf074c940a 2022-05-21 kinaba: sort(idx.begin(), idx.end(), [&](int a, int b) { cf074c940a 2022-05-21 kinaba: return gadgets[a] > gadgets[b]; cf074c940a 2022-05-21 kinaba: }); cf074c940a 2022-05-21 kinaba: cf074c940a 2022-05-21 kinaba: vector<int> ans(gadgets.size(), -1); cf074c940a 2022-05-21 kinaba: cf074c940a 2022-05-21 kinaba: deque<int> s; cf074c940a 2022-05-21 kinaba: s.push_back(gadgets.size()); cf074c940a 2022-05-21 kinaba: for (int i : idx) cf074c940a 2022-05-21 kinaba: if (s.empty()) { cf074c940a 2022-05-21 kinaba: if (gadgets[i] == 0) cf074c940a 2022-05-21 kinaba: return vector<int>(); cf074c940a 2022-05-21 kinaba: ans[i] = -1; cf074c940a 2022-05-21 kinaba: } cf074c940a 2022-05-21 kinaba: else { cf074c940a 2022-05-21 kinaba: ans[i] = s.front(); cf074c940a 2022-05-21 kinaba: s.pop_front(); cf074c940a 2022-05-21 kinaba: for (int k = 0; k < gadgets[i]; ++k) cf074c940a 2022-05-21 kinaba: s.push_back(i); cf074c940a 2022-05-21 kinaba: } cf074c940a 2022-05-21 kinaba: cf074c940a 2022-05-21 kinaba: return ans; cf074c940a 2022-05-21 kinaba: } cf074c940a 2022-05-21 kinaba: }; cf074c940a 2022-05-21 kinaba: cf074c940a 2022-05-21 kinaba: // BEGIN CUT HERE cf074c940a 2022-05-21 kinaba: #include <ctime> cf074c940a 2022-05-21 kinaba: double start_time; string timer() cf074c940a 2022-05-21 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } cf074c940a 2022-05-21 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) cf074c940a 2022-05-21 kinaba: { os << "{ "; cf074c940a 2022-05-21 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) cf074c940a 2022-05-21 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } cf074c940a 2022-05-21 kinaba: void verify_case(const vector <int>& Expected, const vector <int>& Received) { cf074c940a 2022-05-21 kinaba: bool ok = (Expected == Received); cf074c940a 2022-05-21 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cf074c940a 2022-05-21 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } cf074c940a 2022-05-21 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); cf074c940a 2022-05-21 kinaba: #define END verify_case(_, PlugStuffIn().plug(gadgets));} cf074c940a 2022-05-21 kinaba: int main(){ cf074c940a 2022-05-21 kinaba: cf074c940a 2022-05-21 kinaba: CASE(0) cf074c940a 2022-05-21 kinaba: int gadgets_[] = {0}; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: int __[] = {1 }; cf074c940a 2022-05-21 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: CASE(1) cf074c940a 2022-05-21 kinaba: int gadgets_[] = {1, 1, 0, 1, 1, 1}; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: int __[] = {-1, -1, 4, -1, 6, -1 }; cf074c940a 2022-05-21 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: CASE(2) cf074c940a 2022-05-21 kinaba: int gadgets_[] = {1, 1, 0, 1, 1, 1, 0}; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: vector <int> _; cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: CASE(3) cf074c940a 2022-05-21 kinaba: int gadgets_[] = {0, 0, 2, 0, 2}; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: int __[] = {2, 4, 5, 4, 2 }; cf074c940a 2022-05-21 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: CASE(4) cf074c940a 2022-05-21 kinaba: int gadgets_[] = {0, 3, 3}; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: int __[] = {3, 2, 1 }; cf074c940a 2022-05-21 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: CASE(5) cf074c940a 2022-05-21 kinaba: int gadgets_[] = {10, 20, 30, 40}; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: int __[] = {-1, 1, -1, -1 }; cf074c940a 2022-05-21 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: /* cf074c940a 2022-05-21 kinaba: CASE(6) cf074c940a 2022-05-21 kinaba: int gadgets_[] = ; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: int __[] = ; cf074c940a 2022-05-21 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: CASE(7) cf074c940a 2022-05-21 kinaba: int gadgets_[] = ; cf074c940a 2022-05-21 kinaba: vector <int> gadgets(gadgets_, gadgets_+sizeof(gadgets_)/sizeof(*gadgets_)); cf074c940a 2022-05-21 kinaba: int __[] = ; cf074c940a 2022-05-21 kinaba: vector <int> _(__, __+sizeof(__)/sizeof(*__)); cf074c940a 2022-05-21 kinaba: END cf074c940a 2022-05-21 kinaba: */ cf074c940a 2022-05-21 kinaba: } cf074c940a 2022-05-21 kinaba: // END CUT HERE