d477545505 2016-01-13 kinaba: #include <iostream> d477545505 2016-01-13 kinaba: #include <sstream> d477545505 2016-01-13 kinaba: #include <iomanip> d477545505 2016-01-13 kinaba: #include <vector> d477545505 2016-01-13 kinaba: #include <string> d477545505 2016-01-13 kinaba: #include <map> d477545505 2016-01-13 kinaba: #include <set> d477545505 2016-01-13 kinaba: #include <algorithm> d477545505 2016-01-13 kinaba: #include <numeric> d477545505 2016-01-13 kinaba: #include <iterator> d477545505 2016-01-13 kinaba: #include <functional> d477545505 2016-01-13 kinaba: #include <complex> d477545505 2016-01-13 kinaba: #include <queue> d477545505 2016-01-13 kinaba: #include <stack> d477545505 2016-01-13 kinaba: #include <cmath> d477545505 2016-01-13 kinaba: #include <cassert> d477545505 2016-01-13 kinaba: #include <tuple> d477545505 2016-01-13 kinaba: using namespace std; d477545505 2016-01-13 kinaba: typedef long long LL; d477545505 2016-01-13 kinaba: typedef complex<double> CMP; d477545505 2016-01-13 kinaba: d477545505 2016-01-13 kinaba: class ANewHope { public: d477545505 2016-01-13 kinaba: int count(vector <int> firstWeek, vector <int> lastWeek, int D) d477545505 2016-01-13 kinaba: { d477545505 2016-01-13 kinaba: const int N = firstWeek.size(); d477545505 2016-01-13 kinaba: const int s = N-D; d477545505 2016-01-13 kinaba: int worst = 0; d477545505 2016-01-13 kinaba: for(int v=1; v<=N; ++v) { d477545505 2016-01-13 kinaba: int a = find(firstWeek.begin(), firstWeek.end(), v) - firstWeek.begin(); d477545505 2016-01-13 kinaba: int b = find(lastWeek.begin(), lastWeek.end(), v) - lastWeek.begin(); d477545505 2016-01-13 kinaba: worst = max(worst, b==a ? 0 : b>a ? 1 : (a-b+s-1)/s); d477545505 2016-01-13 kinaba: } d477545505 2016-01-13 kinaba: return worst+1; d477545505 2016-01-13 kinaba: } d477545505 2016-01-13 kinaba: }; d477545505 2016-01-13 kinaba: d477545505 2016-01-13 kinaba: // BEGIN CUT HERE d477545505 2016-01-13 kinaba: #include <ctime> d477545505 2016-01-13 kinaba: double start_time; string timer() d477545505 2016-01-13 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } d477545505 2016-01-13 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) d477545505 2016-01-13 kinaba: { os << "{ "; d477545505 2016-01-13 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) d477545505 2016-01-13 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } d477545505 2016-01-13 kinaba: void verify_case(const int& Expected, const int& Received) { d477545505 2016-01-13 kinaba: bool ok = (Expected == Received); d477545505 2016-01-13 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; d477545505 2016-01-13 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } d477545505 2016-01-13 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); d477545505 2016-01-13 kinaba: #define END verify_case(_, ANewHope().count(firstWeek, lastWeek, D));} d477545505 2016-01-13 kinaba: int main(){ d477545505 2016-01-13 kinaba: d477545505 2016-01-13 kinaba: CASE(0) d477545505 2016-01-13 kinaba: int firstWeek_[] = {1,2,3,4}; d477545505 2016-01-13 kinaba: vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_)); d477545505 2016-01-13 kinaba: int lastWeek_[] = {4,3,2,1}; d477545505 2016-01-13 kinaba: vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_)); d477545505 2016-01-13 kinaba: int D = 3; d477545505 2016-01-13 kinaba: int _ = 4; d477545505 2016-01-13 kinaba: END d477545505 2016-01-13 kinaba: CASE(1) d477545505 2016-01-13 kinaba: int firstWeek_[] = {8,5,4,1,7,6,3,2}; d477545505 2016-01-13 kinaba: vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_)); d477545505 2016-01-13 kinaba: int lastWeek_[] = {2,4,6,8,1,3,5,7}; d477545505 2016-01-13 kinaba: vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_)); d477545505 2016-01-13 kinaba: int D = 3; d477545505 2016-01-13 kinaba: int _ = 3; d477545505 2016-01-13 kinaba: END d477545505 2016-01-13 kinaba: CASE(2) d477545505 2016-01-13 kinaba: int firstWeek_[] = {1,2,3,4}; d477545505 2016-01-13 kinaba: vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_)); d477545505 2016-01-13 kinaba: int lastWeek_[] = {1,2,3,4}; d477545505 2016-01-13 kinaba: vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_)); d477545505 2016-01-13 kinaba: int D = 2; d477545505 2016-01-13 kinaba: int _ = 1; d477545505 2016-01-13 kinaba: END d477545505 2016-01-13 kinaba: /* d477545505 2016-01-13 kinaba: CASE(3) d477545505 2016-01-13 kinaba: int firstWeek_[] = ; d477545505 2016-01-13 kinaba: vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_)); d477545505 2016-01-13 kinaba: int lastWeek_[] = ; d477545505 2016-01-13 kinaba: vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_)); d477545505 2016-01-13 kinaba: int D = ; d477545505 2016-01-13 kinaba: int _ = ; d477545505 2016-01-13 kinaba: END d477545505 2016-01-13 kinaba: CASE(4) d477545505 2016-01-13 kinaba: int firstWeek_[] = ; d477545505 2016-01-13 kinaba: vector <int> firstWeek(firstWeek_, firstWeek_+sizeof(firstWeek_)/sizeof(*firstWeek_)); d477545505 2016-01-13 kinaba: int lastWeek_[] = ; d477545505 2016-01-13 kinaba: vector <int> lastWeek(lastWeek_, lastWeek_+sizeof(lastWeek_)/sizeof(*lastWeek_)); d477545505 2016-01-13 kinaba: int D = ; d477545505 2016-01-13 kinaba: int _ = ; d477545505 2016-01-13 kinaba: END d477545505 2016-01-13 kinaba: */ d477545505 2016-01-13 kinaba: } d477545505 2016-01-13 kinaba: // END CUT HERE