2de557d8c0 2011-03-20 kinaba: #include <iostream> 2de557d8c0 2011-03-20 kinaba: #include <sstream> 2de557d8c0 2011-03-20 kinaba: #include <iomanip> 2de557d8c0 2011-03-20 kinaba: #include <vector> 2de557d8c0 2011-03-20 kinaba: #include <string> 2de557d8c0 2011-03-20 kinaba: #include <map> 2de557d8c0 2011-03-20 kinaba: #include <set> 2de557d8c0 2011-03-20 kinaba: #include <algorithm> 2de557d8c0 2011-03-20 kinaba: #include <numeric> 2de557d8c0 2011-03-20 kinaba: #include <iterator> 2de557d8c0 2011-03-20 kinaba: #include <functional> 2de557d8c0 2011-03-20 kinaba: #include <complex> 2de557d8c0 2011-03-20 kinaba: #include <queue> 2de557d8c0 2011-03-20 kinaba: #include <stack> 2de557d8c0 2011-03-20 kinaba: #include <cmath> 2de557d8c0 2011-03-20 kinaba: #include <cassert> 2de557d8c0 2011-03-20 kinaba: #include <cstring> 2de557d8c0 2011-03-20 kinaba: using namespace std; 2de557d8c0 2011-03-20 kinaba: typedef long long LL; 2de557d8c0 2011-03-20 kinaba: typedef complex<double> CMP; 2de557d8c0 2011-03-20 kinaba: 2de557d8c0 2011-03-20 kinaba: class ColorfulRabbits { public: 2de557d8c0 2011-03-20 kinaba: int getMinimum(vector <int> replies) 2de557d8c0 2011-03-20 kinaba: { 2de557d8c0 2011-03-20 kinaba: map<int,int> m; 2de557d8c0 2011-03-20 kinaba: for(int i=0; i<replies.size(); ++i) 2de557d8c0 2011-03-20 kinaba: m[replies[i]]++; 2de557d8c0 2011-03-20 kinaba: int total = 0; 2de557d8c0 2011-03-20 kinaba: for(map<int,int>::iterator it=m.begin(); it!=m.end(); ++it) 2de557d8c0 2011-03-20 kinaba: { 2de557d8c0 2011-03-20 kinaba: int s = it->first + 1; 2de557d8c0 2011-03-20 kinaba: int n = it->second; 2de557d8c0 2011-03-20 kinaba: total += (n+s-1) / s * s; 2de557d8c0 2011-03-20 kinaba: } 2de557d8c0 2011-03-20 kinaba: return total; 2de557d8c0 2011-03-20 kinaba: } 2de557d8c0 2011-03-20 kinaba: }; 2de557d8c0 2011-03-20 kinaba: 2de557d8c0 2011-03-20 kinaba: // BEGIN CUT HERE 2de557d8c0 2011-03-20 kinaba: #include <ctime> 2de557d8c0 2011-03-20 kinaba: double start_time; string timer() 2de557d8c0 2011-03-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 2de557d8c0 2011-03-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 2de557d8c0 2011-03-20 kinaba: { os << "{ "; 2de557d8c0 2011-03-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 2de557d8c0 2011-03-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 2de557d8c0 2011-03-20 kinaba: void verify_case(const int& Expected, const int& Received) { 2de557d8c0 2011-03-20 kinaba: bool ok = (Expected == Received); 2de557d8c0 2011-03-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 2de557d8c0 2011-03-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 2de557d8c0 2011-03-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 2de557d8c0 2011-03-20 kinaba: #define END verify_case(_, ColorfulRabbits().getMinimum(replies));} 2de557d8c0 2011-03-20 kinaba: int main(){ 2de557d8c0 2011-03-20 kinaba: 2de557d8c0 2011-03-20 kinaba: CASE(0) 2de557d8c0 2011-03-20 kinaba: int replies_[] = { 1, 1, 2, 2 } 2de557d8c0 2011-03-20 kinaba: ; 2de557d8c0 2011-03-20 kinaba: vector <int> replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); 2de557d8c0 2011-03-20 kinaba: int _ = 5; 2de557d8c0 2011-03-20 kinaba: END 2de557d8c0 2011-03-20 kinaba: CASE(1) 2de557d8c0 2011-03-20 kinaba: int replies_[] = { 0 } 2de557d8c0 2011-03-20 kinaba: ; 2de557d8c0 2011-03-20 kinaba: vector <int> replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); 2de557d8c0 2011-03-20 kinaba: int _ = 1; 2de557d8c0 2011-03-20 kinaba: END 2de557d8c0 2011-03-20 kinaba: CASE(2) 2de557d8c0 2011-03-20 kinaba: int replies_[] = { 2, 2, 44, 2, 2, 2, 444, 2, 2 } 2de557d8c0 2011-03-20 kinaba: ; 2de557d8c0 2011-03-20 kinaba: vector <int> replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); 2de557d8c0 2011-03-20 kinaba: int _ = 499; 2de557d8c0 2011-03-20 kinaba: END 2de557d8c0 2011-03-20 kinaba: CASE(3) 2de557d8c0 2011-03-20 kinaba: int replies_[] = {1}; 2de557d8c0 2011-03-20 kinaba: vector <int> replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); 2de557d8c0 2011-03-20 kinaba: int _ = 2; 2de557d8c0 2011-03-20 kinaba: END 2de557d8c0 2011-03-20 kinaba: CASE(4) 2de557d8c0 2011-03-20 kinaba: int replies_[] = {2}; 2de557d8c0 2011-03-20 kinaba: vector <int> replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); 2de557d8c0 2011-03-20 kinaba: int _ = 3; 2de557d8c0 2011-03-20 kinaba: END 2de557d8c0 2011-03-20 kinaba: CASE(5) 2de557d8c0 2011-03-20 kinaba: int replies_[] = {1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}; 2de557d8c0 2011-03-20 kinaba: vector <int> replies(replies_, replies_+sizeof(replies_)/sizeof(*replies_)); 2de557d8c0 2011-03-20 kinaba: int _ = -1; 2de557d8c0 2011-03-20 kinaba: END 2de557d8c0 2011-03-20 kinaba: 2de557d8c0 2011-03-20 kinaba: } 2de557d8c0 2011-03-20 kinaba: // END CUT HERE