4fd800b3a8 2011-02-23 kinaba: #include <iostream> 4fd800b3a8 2011-02-23 kinaba: #include <sstream> 4fd800b3a8 2011-02-23 kinaba: #include <iomanip> 4fd800b3a8 2011-02-23 kinaba: #include <vector> 4fd800b3a8 2011-02-23 kinaba: #include <string> 4fd800b3a8 2011-02-23 kinaba: #include <map> 4fd800b3a8 2011-02-23 kinaba: #include <set> 4fd800b3a8 2011-02-23 kinaba: #include <algorithm> 4fd800b3a8 2011-02-23 kinaba: #include <numeric> 4fd800b3a8 2011-02-23 kinaba: #include <iterator> 4fd800b3a8 2011-02-23 kinaba: #include <complex> 4fd800b3a8 2011-02-23 kinaba: #include <queue> 4fd800b3a8 2011-02-23 kinaba: #include <stack> 4fd800b3a8 2011-02-23 kinaba: #include <cmath> 4fd800b3a8 2011-02-23 kinaba: #include <cassert> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: typedef long long LL; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: class SubrectanglesOfTable 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: public: 4fd800b3a8 2011-02-23 kinaba: vector<long long> getQuantity(vector <string> table) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: for(int i=0,n=table.size(); i<n; ++i) 4fd800b3a8 2011-02-23 kinaba: table.push_back( table[i]+=table[i] ); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: vector<LL> ans(26); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: LL Y = table.size(), X = table[0].size(); 4fd800b3a8 2011-02-23 kinaba: for(LL y=0; y<Y; ++y) 4fd800b3a8 2011-02-23 kinaba: for(LL x=0; x<X; ++x) 4fd800b3a8 2011-02-23 kinaba: ans[table[y][x]-'A'] += (y+1)*(x+1)*(Y-y)*(X-x); 4fd800b3a8 2011-02-23 kinaba: return ans; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: }; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: // BEGIN CUT HERE 4fd800b3a8 2011-02-23 kinaba: #include <ctime> 4fd800b3a8 2011-02-23 kinaba: double start_time;string timer() { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } 4fd800b3a8 2011-02-23 kinaba: int verify_case(const vector<long long> &Expected, const vector<long long> &Received) { if (Expected == Received) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } return 0;} 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: template<int N> struct Case_ { Case_(){start_time=clock();} }; 4fd800b3a8 2011-02-23 kinaba: char Test_(...); 4fd800b3a8 2011-02-23 kinaba: int Test_(Case_<0>) { 4fd800b3a8 2011-02-23 kinaba: string table_[] = {"OK"}; 4fd800b3a8 2011-02-23 kinaba: vector <string> table(table_, table_+sizeof(table_)/sizeof(*table_)); 4fd800b3a8 2011-02-23 kinaba: long RetVal_[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 4fd800b3a8 2011-02-23 kinaba: vector<long long> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 4fd800b3a8 2011-02-23 kinaba: return verify_case(RetVal, SubrectanglesOfTable().getQuantity(table)); } 4fd800b3a8 2011-02-23 kinaba: int Test_(Case_<1>) { 4fd800b3a8 2011-02-23 kinaba: string table_[] = {"GOOD", "LUCK"}; 4fd800b3a8 2011-02-23 kinaba: vector <string> table(table_, table_+sizeof(table_)/sizeof(*table_)); 4fd800b3a8 2011-02-23 kinaba: long RetVal_[] = {0, 0, 320, 280, 0, 0, 280, 0, 0, 0, 280, 280, 0, 0, 640, 0, 0, 0, 0, 0, 320, 0, 0, 0, 0, 0 }; 4fd800b3a8 2011-02-23 kinaba: vector<long long> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 4fd800b3a8 2011-02-23 kinaba: return verify_case(RetVal, SubrectanglesOfTable().getQuantity(table)); } 4fd800b3a8 2011-02-23 kinaba: int Test_(Case_<2>) { 4fd800b3a8 2011-02-23 kinaba: string table_[] = {"TANYA", 4fd800b3a8 2011-02-23 kinaba: "HAPPY", 4fd800b3a8 2011-02-23 kinaba: "BIRTH", 4fd800b3a8 2011-02-23 kinaba: "DAYYY"}; 4fd800b3a8 2011-02-23 kinaba: vector <string> table(table_, table_+sizeof(table_)/sizeof(*table_)); 4fd800b3a8 2011-02-23 kinaba: long RetVal_[] = {5168, 1280, 0, 1120, 0, 0, 0, 2560, 1472, 0, 0, 0, 0, 1344, 0, 3008, 0, 1536, 0, 2592, 0, 0, 0, 0, 6320, 0 }; 4fd800b3a8 2011-02-23 kinaba: vector<long long> RetVal(RetVal_, RetVal_+sizeof(RetVal_)/sizeof(*RetVal_)); 4fd800b3a8 2011-02-23 kinaba: return verify_case(RetVal, SubrectanglesOfTable().getQuantity(table)); } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: template<int N> void Run_() { cerr << "Test Case #" << N << "..." << flush; Test_(Case_<N>()); Run_<sizeof(Test_(Case_<N+1>()))==1 ? -1 : N+1>(); } 4fd800b3a8 2011-02-23 kinaba: template<> void Run_<-1>() {} 4fd800b3a8 2011-02-23 kinaba: int main() { Run_<0>(); } 4fd800b3a8 2011-02-23 kinaba: // END CUT HERE 4fd800b3a8 2011-02-23 kinaba: