9befbbd1cf 2016-09-06 kinaba: #include <iostream> 9befbbd1cf 2016-09-06 kinaba: #include <sstream> 9befbbd1cf 2016-09-06 kinaba: #include <iomanip> 9befbbd1cf 2016-09-06 kinaba: #include <vector> 9befbbd1cf 2016-09-06 kinaba: #include <string> 9befbbd1cf 2016-09-06 kinaba: #include <map> 9befbbd1cf 2016-09-06 kinaba: #include <set> 9befbbd1cf 2016-09-06 kinaba: #include <algorithm> 9befbbd1cf 2016-09-06 kinaba: #include <numeric> 9befbbd1cf 2016-09-06 kinaba: #include <iterator> 9befbbd1cf 2016-09-06 kinaba: #include <functional> 9befbbd1cf 2016-09-06 kinaba: #include <complex> 9befbbd1cf 2016-09-06 kinaba: #include <queue> 9befbbd1cf 2016-09-06 kinaba: #include <stack> 9befbbd1cf 2016-09-06 kinaba: #include <cmath> 9befbbd1cf 2016-09-06 kinaba: #include <cassert> 9befbbd1cf 2016-09-06 kinaba: #include <tuple> 9befbbd1cf 2016-09-06 kinaba: using namespace std; 9befbbd1cf 2016-09-06 kinaba: typedef long long LL; 9befbbd1cf 2016-09-06 kinaba: typedef complex<double> CMP; 9befbbd1cf 2016-09-06 kinaba: 9befbbd1cf 2016-09-06 kinaba: class DivisibleSetDiv1 { public: 9befbbd1cf 2016-09-06 kinaba: string isPossible(vector <int> b) 9befbbd1cf 2016-09-06 kinaba: { 9befbbd1cf 2016-09-06 kinaba: return solve(b) ? "Possible" : "Impossible"; 9befbbd1cf 2016-09-06 kinaba: } 9befbbd1cf 2016-09-06 kinaba: 9befbbd1cf 2016-09-06 kinaba: bool solve(vector<int> b) 9befbbd1cf 2016-09-06 kinaba: { 9befbbd1cf 2016-09-06 kinaba: sort(b.begin(), b.end()); 9befbbd1cf 2016-09-06 kinaba: int n = b.size(); 9befbbd1cf 2016-09-06 kinaba: 9befbbd1cf 2016-09-06 kinaba: int sum = 0; 9befbbd1cf 2016-09-06 kinaba: for(int i=0; i<b.size(); ++i) 9befbbd1cf 2016-09-06 kinaba: sum += (n-i); 9befbbd1cf 2016-09-06 kinaba: for(int i=0; i<b.size(); ++i) 9befbbd1cf 2016-09-06 kinaba: if(sum > (b[i]+1)*(n-i)) 9befbbd1cf 2016-09-06 kinaba: return false; 9befbbd1cf 2016-09-06 kinaba: return true; 9befbbd1cf 2016-09-06 kinaba: } 9befbbd1cf 2016-09-06 kinaba: }; 9befbbd1cf 2016-09-06 kinaba: 9befbbd1cf 2016-09-06 kinaba: // BEGIN CUT HERE 9befbbd1cf 2016-09-06 kinaba: #include <ctime> 9befbbd1cf 2016-09-06 kinaba: double start_time; string timer() 9befbbd1cf 2016-09-06 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 9befbbd1cf 2016-09-06 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 9befbbd1cf 2016-09-06 kinaba: { os << "{ "; 9befbbd1cf 2016-09-06 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 9befbbd1cf 2016-09-06 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 9befbbd1cf 2016-09-06 kinaba: void verify_case(const string& Expected, const string& Received) { 9befbbd1cf 2016-09-06 kinaba: bool ok = (Expected == Received); 9befbbd1cf 2016-09-06 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 9befbbd1cf 2016-09-06 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 9befbbd1cf 2016-09-06 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 9befbbd1cf 2016-09-06 kinaba: #define END verify_case(_, DivisibleSetDiv1().isPossible(b));} 9befbbd1cf 2016-09-06 kinaba: int main(){ 9befbbd1cf 2016-09-06 kinaba: 9befbbd1cf 2016-09-06 kinaba: CASE(0) 9befbbd1cf 2016-09-06 kinaba: int b_[] = {2,1}; 9befbbd1cf 2016-09-06 kinaba: vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 9befbbd1cf 2016-09-06 kinaba: string _ = "Possible"; 9befbbd1cf 2016-09-06 kinaba: END 9befbbd1cf 2016-09-06 kinaba: CASE(1) 9befbbd1cf 2016-09-06 kinaba: int b_[] = {1,1}; 9befbbd1cf 2016-09-06 kinaba: vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 9befbbd1cf 2016-09-06 kinaba: string _ = "Impossible"; 9befbbd1cf 2016-09-06 kinaba: END 9befbbd1cf 2016-09-06 kinaba: CASE(2) 9befbbd1cf 2016-09-06 kinaba: int b_[] = {7, 7, 7}; 9befbbd1cf 2016-09-06 kinaba: vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 9befbbd1cf 2016-09-06 kinaba: string _ = "Possible"; 9befbbd1cf 2016-09-06 kinaba: END 9befbbd1cf 2016-09-06 kinaba: CASE(3) 9befbbd1cf 2016-09-06 kinaba: int b_[] = {5,3,5,4,6,1,3,7,9,6,2,5,4,1,1,9,6,10,10,6,10,7,7,8}; 9befbbd1cf 2016-09-06 kinaba: vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 9befbbd1cf 2016-09-06 kinaba: string _ = "Impossible"; 9befbbd1cf 2016-09-06 kinaba: END 9befbbd1cf 2016-09-06 kinaba: CASE(4) 9befbbd1cf 2016-09-06 kinaba: int b_[] = {2,3,4}; 9befbbd1cf 2016-09-06 kinaba: vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 9befbbd1cf 2016-09-06 kinaba: string _ = "Possible"; 9befbbd1cf 2016-09-06 kinaba: END 9befbbd1cf 2016-09-06 kinaba: /* 9befbbd1cf 2016-09-06 kinaba: CASE(5) 9befbbd1cf 2016-09-06 kinaba: int b_[] = ; 9befbbd1cf 2016-09-06 kinaba: vector <int> b(b_, b_+sizeof(b_)/sizeof(*b_)); 9befbbd1cf 2016-09-06 kinaba: string _ = ; 9befbbd1cf 2016-09-06 kinaba: END 9befbbd1cf 2016-09-06 kinaba: */ 9befbbd1cf 2016-09-06 kinaba: } 9befbbd1cf 2016-09-06 kinaba: // END CUT HERE