1f14a4420e 2015-12-01 kinaba: #include <iostream> 1f14a4420e 2015-12-01 kinaba: #include <sstream> 1f14a4420e 2015-12-01 kinaba: #include <iomanip> 1f14a4420e 2015-12-01 kinaba: #include <vector> 1f14a4420e 2015-12-01 kinaba: #include <string> 1f14a4420e 2015-12-01 kinaba: #include <map> 1f14a4420e 2015-12-01 kinaba: #include <set> 1f14a4420e 2015-12-01 kinaba: #include <algorithm> 1f14a4420e 2015-12-01 kinaba: #include <numeric> 1f14a4420e 2015-12-01 kinaba: #include <iterator> 1f14a4420e 2015-12-01 kinaba: #include <functional> 1f14a4420e 2015-12-01 kinaba: #include <complex> 1f14a4420e 2015-12-01 kinaba: #include <queue> 1f14a4420e 2015-12-01 kinaba: #include <stack> 1f14a4420e 2015-12-01 kinaba: #include <cmath> 1f14a4420e 2015-12-01 kinaba: #include <cassert> 1f14a4420e 2015-12-01 kinaba: #include <tuple> 1f14a4420e 2015-12-01 kinaba: using namespace std; 1f14a4420e 2015-12-01 kinaba: typedef long long LL; 1f14a4420e 2015-12-01 kinaba: typedef complex<double> CMP; 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: static const unsigned MODVAL = 1000000007; 1f14a4420e 2015-12-01 kinaba: struct mint 1f14a4420e 2015-12-01 kinaba: { 1f14a4420e 2015-12-01 kinaba: unsigned val; 1f14a4420e 2015-12-01 kinaba: mint():val(0){} 1f14a4420e 2015-12-01 kinaba: mint(int x):val(x%MODVAL) {} 1f14a4420e 2015-12-01 kinaba: mint(unsigned x):val(x%MODVAL) {} 1f14a4420e 2015-12-01 kinaba: mint(LL x):val(x%MODVAL) {} 1f14a4420e 2015-12-01 kinaba: }; 1f14a4420e 2015-12-01 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 1f14a4420e 2015-12-01 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 1f14a4420e 2015-12-01 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 1f14a4420e 2015-12-01 kinaba: mint operator+(mint x, mint y) { return x+=y; } 1f14a4420e 2015-12-01 kinaba: mint operator-(mint x, mint y) { return x-=y; } 1f14a4420e 2015-12-01 kinaba: mint operator*(mint x, mint y) { return x*=y; } 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: class BearCavalry { public: 1f14a4420e 2015-12-01 kinaba: int countAssignments(vector <int> warriors, vector <int> horses) 1f14a4420e 2015-12-01 kinaba: { 1f14a4420e 2015-12-01 kinaba: mint total = 0; 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: const int W = warriors[0]; 1f14a4420e 2015-12-01 kinaba: warriors.erase(warriors.begin()); 1f14a4420e 2015-12-01 kinaba: sort(warriors.begin(), warriors.end()); 1f14a4420e 2015-12-01 kinaba: sort(horses.begin(), horses.end()); 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: for(int x=0; x<horses.size(); ++x) { 1f14a4420e 2015-12-01 kinaba: const int H = horses[x]; 1f14a4420e 2015-12-01 kinaba: vector<int> hs(horses.begin(), horses.begin()+x); 1f14a4420e 2015-12-01 kinaba: hs.insert(hs.end(), horses.begin()+x+1, horses.end()); 1f14a4420e 2015-12-01 kinaba: total += cnt(W*H, warriors, hs); 1f14a4420e 2015-12-01 kinaba: } 1f14a4420e 2015-12-01 kinaba: return total.val; 1f14a4420e 2015-12-01 kinaba: } 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: mint cnt(int TOP, vector<int> w, vector<int> h) 1f14a4420e 2015-12-01 kinaba: { 1f14a4420e 2015-12-01 kinaba: mint total = 1; 1f14a4420e 2015-12-01 kinaba: for(int i=0; i<w.size(); ++i) { 1f14a4420e 2015-12-01 kinaba: int W = w[w.size()-1-i]; 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: int c=0; 1f14a4420e 2015-12-01 kinaba: for(int hk: h) 1f14a4420e 2015-12-01 kinaba: c += (hk*W < TOP); 1f14a4420e 2015-12-01 kinaba: c -= i; 1f14a4420e 2015-12-01 kinaba: if(c <= 0) 1f14a4420e 2015-12-01 kinaba: return 0; 1f14a4420e 2015-12-01 kinaba: total *= c; 1f14a4420e 2015-12-01 kinaba: } 1f14a4420e 2015-12-01 kinaba: return total; 1f14a4420e 2015-12-01 kinaba: } 1f14a4420e 2015-12-01 kinaba: }; 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: // BEGIN CUT HERE 1f14a4420e 2015-12-01 kinaba: #include <ctime> 1f14a4420e 2015-12-01 kinaba: double start_time; string timer() 1f14a4420e 2015-12-01 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 1f14a4420e 2015-12-01 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 1f14a4420e 2015-12-01 kinaba: { os << "{ "; 1f14a4420e 2015-12-01 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 1f14a4420e 2015-12-01 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 1f14a4420e 2015-12-01 kinaba: void verify_case(const int& Expected, const int& Received) { 1f14a4420e 2015-12-01 kinaba: bool ok = (Expected == Received); 1f14a4420e 2015-12-01 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 1f14a4420e 2015-12-01 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 1f14a4420e 2015-12-01 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 1f14a4420e 2015-12-01 kinaba: #define END verify_case(_, BearCavalry().countAssignments(warriors, horses));} 1f14a4420e 2015-12-01 kinaba: int main(){ 1f14a4420e 2015-12-01 kinaba: 1f14a4420e 2015-12-01 kinaba: CASE(0) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = {5,8,4,8}; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = {19,40,25,20}; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = 2; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: CASE(1) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = {1,1}; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = {1,1}; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = 0; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: CASE(2) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = {10,2,10}; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = {100,150,200}; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = 3; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: CASE(3) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = {10,20}; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = {1,3}; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = 1; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: CASE(4) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = {20,20,25,23,24,24,21}; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = {20,25,25,20,25,23,20}; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = 0; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: CASE(5) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = {970,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800, 1f14a4420e 2015-12-01 kinaba: 800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800,800}; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1f14a4420e 2015-12-01 kinaba: 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, 1f14a4420e 2015-12-01 kinaba: 1000,1000,1000,1000,1000,1000,1000,1000,1000,1000}; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = 318608048; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: /* 1f14a4420e 2015-12-01 kinaba: CASE(6) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = ; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = ; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = ; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: CASE(7) 1f14a4420e 2015-12-01 kinaba: int warriors_[] = ; 1f14a4420e 2015-12-01 kinaba: vector <int> warriors(warriors_, warriors_+sizeof(warriors_)/sizeof(*warriors_)); 1f14a4420e 2015-12-01 kinaba: int horses_[] = ; 1f14a4420e 2015-12-01 kinaba: vector <int> horses(horses_, horses_+sizeof(horses_)/sizeof(*horses_)); 1f14a4420e 2015-12-01 kinaba: int _ = ; 1f14a4420e 2015-12-01 kinaba: END 1f14a4420e 2015-12-01 kinaba: */ 1f14a4420e 2015-12-01 kinaba: } 1f14a4420e 2015-12-01 kinaba: // END CUT HERE