7448b5f610 2012-11-20 kinaba: #include <iostream> 7448b5f610 2012-11-20 kinaba: #include <sstream> 7448b5f610 2012-11-20 kinaba: #include <iomanip> 7448b5f610 2012-11-20 kinaba: #include <vector> 7448b5f610 2012-11-20 kinaba: #include <string> 7448b5f610 2012-11-20 kinaba: #include <map> 7448b5f610 2012-11-20 kinaba: #include <set> 7448b5f610 2012-11-20 kinaba: #include <algorithm> 7448b5f610 2012-11-20 kinaba: #include <numeric> 7448b5f610 2012-11-20 kinaba: #include <iterator> 7448b5f610 2012-11-20 kinaba: #include <functional> 7448b5f610 2012-11-20 kinaba: #include <complex> 7448b5f610 2012-11-20 kinaba: #include <queue> 7448b5f610 2012-11-20 kinaba: #include <stack> 7448b5f610 2012-11-20 kinaba: #include <cmath> 7448b5f610 2012-11-20 kinaba: #include <cassert> 7448b5f610 2012-11-20 kinaba: using namespace std; 7448b5f610 2012-11-20 kinaba: typedef long long LL; 7448b5f610 2012-11-20 kinaba: typedef long double LD; 7448b5f610 2012-11-20 kinaba: typedef complex<LD> CMP; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: class TomekPhone { public: 7448b5f610 2012-11-20 kinaba: int minKeystrokes(vector <int> fr, vector <int> keySizes) 7448b5f610 2012-11-20 kinaba: { 7448b5f610 2012-11-20 kinaba: vector<int> cand; 7448b5f610 2012-11-20 kinaba: for(int i=0; i<keySizes.size(); ++i) 7448b5f610 2012-11-20 kinaba: for(int k=1; k<=keySizes[i]; ++k) 7448b5f610 2012-11-20 kinaba: cand.push_back(k); 7448b5f610 2012-11-20 kinaba: sort(cand.begin(), cand.end()); 7448b5f610 2012-11-20 kinaba: if(cand.size() < fr.size()) 7448b5f610 2012-11-20 kinaba: return -1; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: int total = 0; 7448b5f610 2012-11-20 kinaba: sort(fr.rbegin(), fr.rend()); 7448b5f610 2012-11-20 kinaba: for(int i=0; i<fr.size(); ++i) 7448b5f610 2012-11-20 kinaba: total += fr[i]*cand[i]; 7448b5f610 2012-11-20 kinaba: return total; 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: }; 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: // BEGIN CUT HERE 7448b5f610 2012-11-20 kinaba: #include <ctime> 7448b5f610 2012-11-20 kinaba: double start_time; string timer() 7448b5f610 2012-11-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 7448b5f610 2012-11-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 7448b5f610 2012-11-20 kinaba: { os << "{ "; 7448b5f610 2012-11-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 7448b5f610 2012-11-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 7448b5f610 2012-11-20 kinaba: void verify_case(const int& Expected, const int& Received) { 7448b5f610 2012-11-20 kinaba: bool ok = (Expected == Received); 7448b5f610 2012-11-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 7448b5f610 2012-11-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 7448b5f610 2012-11-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 7448b5f610 2012-11-20 kinaba: #define END verify_case(_, TomekPhone().minKeystrokes(frequencies, keySizes));} 7448b5f610 2012-11-20 kinaba: int main(){ 7448b5f610 2012-11-20 kinaba: 7448b5f610 2012-11-20 kinaba: CASE(0) 7448b5f610 2012-11-20 kinaba: int frequencies_[] = {7,3,4,1}; 7448b5f610 2012-11-20 kinaba: vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies_)/sizeof(*frequencies_)); 7448b5f610 2012-11-20 kinaba: int keySizes_[] = {2,2}; 7448b5f610 2012-11-20 kinaba: vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*keySizes_)); 7448b5f610 2012-11-20 kinaba: int _ = 19; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(1) 7448b5f610 2012-11-20 kinaba: int frequencies_[] = {13,7,4,20}; 7448b5f610 2012-11-20 kinaba: vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies_)/sizeof(*frequencies_)); 7448b5f610 2012-11-20 kinaba: int keySizes_[] = {2,1}; 7448b5f610 2012-11-20 kinaba: vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*keySizes_)); 7448b5f610 2012-11-20 kinaba: int _ = -1; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(2) 7448b5f610 2012-11-20 kinaba: int frequencies_[] = {11,23,4,50,1000,7,18}; 7448b5f610 2012-11-20 kinaba: vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies_)/sizeof(*frequencies_)); 7448b5f610 2012-11-20 kinaba: int keySizes_[] = {3,1,4}; 7448b5f610 2012-11-20 kinaba: vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*keySizes_)); 7448b5f610 2012-11-20 kinaba: int _ = 1164; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(3) 7448b5f610 2012-11-20 kinaba: int frequencies_[] = {100,1000,1,10}; 7448b5f610 2012-11-20 kinaba: vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies_)/sizeof(*frequencies_)); 7448b5f610 2012-11-20 kinaba: int keySizes_[] = {50}; 7448b5f610 2012-11-20 kinaba: vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*keySizes_)); 7448b5f610 2012-11-20 kinaba: int _ = 1234; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(4) 7448b5f610 2012-11-20 kinaba: int frequencies_[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50}; 7448b5f610 2012-11-20 kinaba: vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies_)/sizeof(*frequencies_)); 7448b5f610 2012-11-20 kinaba: int keySizes_[] = {10,10,10,10,10,10,10,10}; 7448b5f610 2012-11-20 kinaba: vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*keySizes_)); 7448b5f610 2012-11-20 kinaba: int _ = 3353; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: /* 7448b5f610 2012-11-20 kinaba: CASE(5) 7448b5f610 2012-11-20 kinaba: int frequencies_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies_)/sizeof(*frequencies_)); 7448b5f610 2012-11-20 kinaba: int keySizes_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*keySizes_)); 7448b5f610 2012-11-20 kinaba: int _ = ; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: CASE(6) 7448b5f610 2012-11-20 kinaba: int frequencies_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> frequencies(frequencies_, frequencies_+sizeof(frequencies_)/sizeof(*frequencies_)); 7448b5f610 2012-11-20 kinaba: int keySizes_[] = ; 7448b5f610 2012-11-20 kinaba: vector <int> keySizes(keySizes_, keySizes_+sizeof(keySizes_)/sizeof(*keySizes_)); 7448b5f610 2012-11-20 kinaba: int _ = ; 7448b5f610 2012-11-20 kinaba: END 7448b5f610 2012-11-20 kinaba: */ 7448b5f610 2012-11-20 kinaba: } 7448b5f610 2012-11-20 kinaba: // END CUT HERE