File Annotation
Not logged in
83fd197aaa 2015-07-18        kinaba: #include <iostream>
83fd197aaa 2015-07-18        kinaba: #include <sstream>
83fd197aaa 2015-07-18        kinaba: #include <iomanip>
83fd197aaa 2015-07-18        kinaba: #include <vector>
83fd197aaa 2015-07-18        kinaba: #include <string>
83fd197aaa 2015-07-18        kinaba: #include <map>
83fd197aaa 2015-07-18        kinaba: #include <set>
83fd197aaa 2015-07-18        kinaba: #include <algorithm>
83fd197aaa 2015-07-18        kinaba: #include <numeric>
83fd197aaa 2015-07-18        kinaba: #include <iterator>
83fd197aaa 2015-07-18        kinaba: #include <functional>
83fd197aaa 2015-07-18        kinaba: #include <complex>
83fd197aaa 2015-07-18        kinaba: #include <queue>
83fd197aaa 2015-07-18        kinaba: #include <stack>
83fd197aaa 2015-07-18        kinaba: #include <cmath>
83fd197aaa 2015-07-18        kinaba: #include <cassert>
83fd197aaa 2015-07-18        kinaba: #include <tuple>
83fd197aaa 2015-07-18        kinaba: using namespace std;
83fd197aaa 2015-07-18        kinaba: typedef long long LL;
83fd197aaa 2015-07-18        kinaba: typedef complex<double> CMP;
83fd197aaa 2015-07-18        kinaba: 
83fd197aaa 2015-07-18        kinaba: template<typename T>
83fd197aaa 2015-07-18        kinaba: struct DP2
83fd197aaa 2015-07-18        kinaba: {
83fd197aaa 2015-07-18        kinaba: 	const int N1, N2;
83fd197aaa 2015-07-18        kinaba: 	vector<T> data;
83fd197aaa 2015-07-18        kinaba: 	DP2(int N1, int N2, const T& t = T())
83fd197aaa 2015-07-18        kinaba: 		: N1(N1), N2(N2), data(N1*N2, t) { assert(data.size()*sizeof(T)<(1<<28)); }
83fd197aaa 2015-07-18        kinaba: 	T& operator()(int i1, int i2)
83fd197aaa 2015-07-18        kinaba: 		{ return data[ (i1*N2)+i2 ]; }
83fd197aaa 2015-07-18        kinaba: 	void swap(DP2& rhs)
83fd197aaa 2015-07-18        kinaba: 		{ data.swap(rhs.data); }
83fd197aaa 2015-07-18        kinaba: };
83fd197aaa 2015-07-18        kinaba: 
83fd197aaa 2015-07-18        kinaba: class FoxesOfTheRoundTable { public:
83fd197aaa 2015-07-18        kinaba: 	vector <int> minimalDifference(vector <int> h)
83fd197aaa 2015-07-18        kinaba: 	{
83fd197aaa 2015-07-18        kinaba: 		const int N = h.size();
83fd197aaa 2015-07-18        kinaba: 		vector<int> idx(N);
83fd197aaa 2015-07-18        kinaba: 		for(int i=0; i<idx.size(); ++i) idx[i] = i;
83fd197aaa 2015-07-18        kinaba: 
83fd197aaa 2015-07-18        kinaba: 		sort(idx.begin(), idx.end(), [&](int a, int b) {
83fd197aaa 2015-07-18        kinaba: 			return h[a] < h[b];
83fd197aaa 2015-07-18        kinaba: 		});
83fd197aaa 2015-07-18        kinaba: 
83fd197aaa 2015-07-18        kinaba: 		vector<int> aa(1, 0), bb(1, 0);
83fd197aaa 2015-07-18        kinaba: 		for(int k=1; k<N-1; ++k)
83fd197aaa 2015-07-18        kinaba: 			(aa.back()<bb.back() ? aa : bb).push_back(k);
83fd197aaa 2015-07-18        kinaba: 		vector<int> ans;
83fd197aaa 2015-07-18        kinaba: 		for(auto a: aa)
83fd197aaa 2015-07-18        kinaba: 			ans.push_back(idx[a]);
83fd197aaa 2015-07-18        kinaba: 		bb.push_back(N-1);
83fd197aaa 2015-07-18        kinaba: 		reverse(bb.begin(), bb.end());
83fd197aaa 2015-07-18        kinaba: 		bb.pop_back();
83fd197aaa 2015-07-18        kinaba: 		for(auto b: bb)
83fd197aaa 2015-07-18        kinaba: 			ans.push_back(idx[b]);
83fd197aaa 2015-07-18        kinaba: 
83fd197aaa 2015-07-18        kinaba: 		return ans;
83fd197aaa 2015-07-18        kinaba: 	}
83fd197aaa 2015-07-18        kinaba: };
83fd197aaa 2015-07-18        kinaba: 
83fd197aaa 2015-07-18        kinaba: // BEGIN CUT HERE
83fd197aaa 2015-07-18        kinaba: #include <ctime>
83fd197aaa 2015-07-18        kinaba: double start_time; string timer()
83fd197aaa 2015-07-18        kinaba:  { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
83fd197aaa 2015-07-18        kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
83fd197aaa 2015-07-18        kinaba:  { os << "{ ";
83fd197aaa 2015-07-18        kinaba:    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
83fd197aaa 2015-07-18        kinaba:    os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
83fd197aaa 2015-07-18        kinaba: void verify_case(const vector <int>& Expected, const vector <int>& Received) {
83fd197aaa 2015-07-18        kinaba:  bool ok = (Expected == Received);
83fd197aaa 2015-07-18        kinaba:  if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
83fd197aaa 2015-07-18        kinaba:  cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
83fd197aaa 2015-07-18        kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
83fd197aaa 2015-07-18        kinaba: #define END	 verify_case(_, FoxesOfTheRoundTable().minimalDifference(h));}
83fd197aaa 2015-07-18        kinaba: int main(){
83fd197aaa 2015-07-18        kinaba: 
83fd197aaa 2015-07-18        kinaba: CASE(0)
83fd197aaa 2015-07-18        kinaba: 	int h_[] = {1,99,50,50};
83fd197aaa 2015-07-18        kinaba: 	  vector <int> h(h_, h_+sizeof(h_)/sizeof(*h_));
83fd197aaa 2015-07-18        kinaba: 	int __[] = {0, 3, 1, 2 };
83fd197aaa 2015-07-18        kinaba: 	  vector <int> _(__, __+sizeof(__)/sizeof(*__));
83fd197aaa 2015-07-18        kinaba: END
83fd197aaa 2015-07-18        kinaba: CASE(1)
83fd197aaa 2015-07-18        kinaba: 	int h_[] = {123,456,789};
83fd197aaa 2015-07-18        kinaba: 	  vector <int> h(h_, h_+sizeof(h_)/sizeof(*h_));
83fd197aaa 2015-07-18        kinaba: 	int __[] = {0, 1, 2 };
83fd197aaa 2015-07-18        kinaba: 	  vector <int> _(__, __+sizeof(__)/sizeof(*__));
83fd197aaa 2015-07-18        kinaba: END
83fd197aaa 2015-07-18        kinaba: CASE(2)
83fd197aaa 2015-07-18        kinaba: 	int h_[] = {10,30,40,50,60};
83fd197aaa 2015-07-18        kinaba: 	  vector <int> h(h_, h_+sizeof(h_)/sizeof(*h_));
83fd197aaa 2015-07-18        kinaba: 	int __[] = {0, 1, 4, 3, 2 };
83fd197aaa 2015-07-18        kinaba: 	  vector <int> _(__, __+sizeof(__)/sizeof(*__));
83fd197aaa 2015-07-18        kinaba: END
83fd197aaa 2015-07-18        kinaba: CASE(3)
83fd197aaa 2015-07-18        kinaba: 	int h_[] = {1,2,3,4,8,12,13,14 };
83fd197aaa 2015-07-18        kinaba: 	  vector <int> h(h_, h_+sizeof(h_)/sizeof(*h_));
83fd197aaa 2015-07-18        kinaba: 	int __[] = {0, 1, 2, 3, 5, 6, 7, 4 };
83fd197aaa 2015-07-18        kinaba: 	  vector <int> _(__, __+sizeof(__)/sizeof(*__));
83fd197aaa 2015-07-18        kinaba: END
83fd197aaa 2015-07-18        kinaba: CASE(4)
83fd197aaa 2015-07-18        kinaba: 	int h_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };
83fd197aaa 2015-07-18        kinaba: 	  vector <int> h(h_, h_+sizeof(h_)/sizeof(*h_));
83fd197aaa 2015-07-18        kinaba: 	int __[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
83fd197aaa 2015-07-18        kinaba: 	  vector <int> _(__, __+sizeof(__)/sizeof(*__));
83fd197aaa 2015-07-18        kinaba: END
83fd197aaa 2015-07-18        kinaba: /*
83fd197aaa 2015-07-18        kinaba: CASE(5)
83fd197aaa 2015-07-18        kinaba: 	int h_[] = ;
83fd197aaa 2015-07-18        kinaba: 	  vector <int> h(h_, h_+sizeof(h_)/sizeof(*h_));
83fd197aaa 2015-07-18        kinaba: 	int __[] = ;
83fd197aaa 2015-07-18        kinaba: 	  vector <int> _(__, __+sizeof(__)/sizeof(*__));
83fd197aaa 2015-07-18        kinaba: END
83fd197aaa 2015-07-18        kinaba: CASE(6)
83fd197aaa 2015-07-18        kinaba: 	int h_[] = ;
83fd197aaa 2015-07-18        kinaba: 	  vector <int> h(h_, h_+sizeof(h_)/sizeof(*h_));
83fd197aaa 2015-07-18        kinaba: 	int __[] = ;
83fd197aaa 2015-07-18        kinaba: 	  vector <int> _(__, __+sizeof(__)/sizeof(*__));
83fd197aaa 2015-07-18        kinaba: END
83fd197aaa 2015-07-18        kinaba: */
83fd197aaa 2015-07-18        kinaba: }
83fd197aaa 2015-07-18        kinaba: // END CUT HERE