ddb24a372f 2012-10-19 kinaba: #include <iostream> ddb24a372f 2012-10-19 kinaba: #include <sstream> ddb24a372f 2012-10-19 kinaba: #include <iomanip> ddb24a372f 2012-10-19 kinaba: #include <vector> ddb24a372f 2012-10-19 kinaba: #include <string> ddb24a372f 2012-10-19 kinaba: #include <map> ddb24a372f 2012-10-19 kinaba: #include <set> ddb24a372f 2012-10-19 kinaba: #include <algorithm> ddb24a372f 2012-10-19 kinaba: #include <numeric> ddb24a372f 2012-10-19 kinaba: #include <iterator> ddb24a372f 2012-10-19 kinaba: #include <functional> ddb24a372f 2012-10-19 kinaba: #include <complex> ddb24a372f 2012-10-19 kinaba: #include <queue> ddb24a372f 2012-10-19 kinaba: #include <stack> ddb24a372f 2012-10-19 kinaba: #include <cmath> ddb24a372f 2012-10-19 kinaba: #include <cassert> ddb24a372f 2012-10-19 kinaba: using namespace std; ddb24a372f 2012-10-19 kinaba: typedef long long LL; ddb24a372f 2012-10-19 kinaba: typedef long double LD; ddb24a372f 2012-10-19 kinaba: typedef complex<LD> CMP; ddb24a372f 2012-10-19 kinaba: ddb24a372f 2012-10-19 kinaba: class Ear { public: ddb24a372f 2012-10-19 kinaba: long long getCount(vector <string> redX, vector <string> blueX, vector <string> blueY) ddb24a372f 2012-10-19 kinaba: { ddb24a372f 2012-10-19 kinaba: vector<int> rx, bx, by; ddb24a372f 2012-10-19 kinaba: { ddb24a372f 2012-10-19 kinaba: stringstream sin(accumulate(redX.begin(), redX.end(), string(""))); ddb24a372f 2012-10-19 kinaba: for(int x; sin>>x; ) rx.push_back(x); ddb24a372f 2012-10-19 kinaba: } ddb24a372f 2012-10-19 kinaba: { ddb24a372f 2012-10-19 kinaba: stringstream sin(accumulate(blueX.begin(), blueX.end(), string(""))); ddb24a372f 2012-10-19 kinaba: for(int x; sin>>x; ) bx.push_back(x); ddb24a372f 2012-10-19 kinaba: } ddb24a372f 2012-10-19 kinaba: { ddb24a372f 2012-10-19 kinaba: stringstream sin(accumulate(blueY.begin(), blueY.end(), string(""))); ddb24a372f 2012-10-19 kinaba: for(int y; sin>>y; ) by.push_back(y); ddb24a372f 2012-10-19 kinaba: } ddb24a372f 2012-10-19 kinaba: int B = bx.size(); ddb24a372f 2012-10-19 kinaba: ddb24a372f 2012-10-19 kinaba: LL total = 0; ddb24a372f 2012-10-19 kinaba: for(int p=0; p<B; ++p) ddb24a372f 2012-10-19 kinaba: for(int q=0; q<B; ++q) ddb24a372f 2012-10-19 kinaba: if(by[p] > by[q]) ddb24a372f 2012-10-19 kinaba: { ddb24a372f 2012-10-19 kinaba: int px=bx[p], py=by[p], qx=bx[q], qy=by[q]; ddb24a372f 2012-10-19 kinaba: LL a=0, b=0, c=0, d=0; ddb24a372f 2012-10-19 kinaba: for(int i=0; i<rx.size(); ++i) ddb24a372f 2012-10-19 kinaba: { ddb24a372f 2012-10-19 kinaba: int x = rx[i]; ddb24a372f 2012-10-19 kinaba: double z = px + (qx-px)*py/double(py-qy); ddb24a372f 2012-10-19 kinaba: if(x<min<double>(z,px)) ddb24a372f 2012-10-19 kinaba: ++a; ddb24a372f 2012-10-19 kinaba: if(min<double>(z,px)<=x && x<qx) ddb24a372f 2012-10-19 kinaba: ++b; ddb24a372f 2012-10-19 kinaba: if(qx<x && x<=max<double>(z,px)) ddb24a372f 2012-10-19 kinaba: ++c; ddb24a372f 2012-10-19 kinaba: if(max<double>(z,px)<x) ddb24a372f 2012-10-19 kinaba: ++d; ddb24a372f 2012-10-19 kinaba: } ddb24a372f 2012-10-19 kinaba: total += (a*(a-1)/2+a*b) * (d*(d-1)/2+d*c); ddb24a372f 2012-10-19 kinaba: } ddb24a372f 2012-10-19 kinaba: return total; ddb24a372f 2012-10-19 kinaba: } ddb24a372f 2012-10-19 kinaba: }; ddb24a372f 2012-10-19 kinaba: ddb24a372f 2012-10-19 kinaba: // BEGIN CUT HERE ddb24a372f 2012-10-19 kinaba: #include <ctime> ddb24a372f 2012-10-19 kinaba: double start_time; string timer() ddb24a372f 2012-10-19 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } ddb24a372f 2012-10-19 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) ddb24a372f 2012-10-19 kinaba: { os << "{ "; ddb24a372f 2012-10-19 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) ddb24a372f 2012-10-19 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } ddb24a372f 2012-10-19 kinaba: void verify_case(const long long& Expected, const long long& Received) { ddb24a372f 2012-10-19 kinaba: bool ok = (Expected == Received); ddb24a372f 2012-10-19 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; ddb24a372f 2012-10-19 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } ddb24a372f 2012-10-19 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); ddb24a372f 2012-10-19 kinaba: #define END verify_case(_, Ear().getCount(redX, blueX, blueY));} ddb24a372f 2012-10-19 kinaba: int main(){ ddb24a372f 2012-10-19 kinaba: ddb24a372f 2012-10-19 kinaba: CASE(0) ddb24a372f 2012-10-19 kinaba: string redX_[] = {"3 2 8 7"}; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = {"5 4"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = {"2 4"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = 1LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: CASE(1) ddb24a372f 2012-10-19 kinaba: string redX_[] = {"3 2 8 7"}; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = {"2 8"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = {"3 4"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = 0LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: CASE(2) ddb24a372f 2012-10-19 kinaba: string redX_[] = {"1 2 6 9"}; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = {"3 6 8 5"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = {"1 5 4 3"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = 4LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: CASE(3) ddb24a372f 2012-10-19 kinaba: string redX_[] = {"10000"}; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = {"10000 9999"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = {"10000 9999"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = 0LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: CASE(4) ddb24a372f 2012-10-19 kinaba: string redX_[] = {"100 2", "00", " 39", "9", " 800 900 9", "99"}; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = {"15", "0 250 ", "349"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = {"2 3 1"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = 12LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: CASE(5) ddb24a372f 2012-10-19 kinaba: string redX_[] = {"1", " ", "2", " ", "3", " ", "4 5 6", " 7 8 9"}; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = {"4", " ", "5", " ", "6", " 7 ", "8"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = {"1", " 2 ", "3 4", " 5"}; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = 204LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: /* ddb24a372f 2012-10-19 kinaba: CASE(6) ddb24a372f 2012-10-19 kinaba: string redX_[] = ; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = ; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = ; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: CASE(7) ddb24a372f 2012-10-19 kinaba: string redX_[] = ; ddb24a372f 2012-10-19 kinaba: vector <string> redX(redX_, redX_+sizeof(redX_)/sizeof(*redX_)); ddb24a372f 2012-10-19 kinaba: string blueX_[] = ; ddb24a372f 2012-10-19 kinaba: vector <string> blueX(blueX_, blueX_+sizeof(blueX_)/sizeof(*blueX_)); ddb24a372f 2012-10-19 kinaba: string blueY_[] = ; ddb24a372f 2012-10-19 kinaba: vector <string> blueY(blueY_, blueY_+sizeof(blueY_)/sizeof(*blueY_)); ddb24a372f 2012-10-19 kinaba: long long _ = LL; ddb24a372f 2012-10-19 kinaba: END ddb24a372f 2012-10-19 kinaba: */ ddb24a372f 2012-10-19 kinaba: } ddb24a372f 2012-10-19 kinaba: // END CUT HERE