0ea7f42c5c 2012-09-02 kinaba: #include <iostream> 0ea7f42c5c 2012-09-02 kinaba: #include <sstream> 0ea7f42c5c 2012-09-02 kinaba: #include <iomanip> 0ea7f42c5c 2012-09-02 kinaba: #include <vector> 0ea7f42c5c 2012-09-02 kinaba: #include <string> 0ea7f42c5c 2012-09-02 kinaba: #include <map> 0ea7f42c5c 2012-09-02 kinaba: #include <set> 0ea7f42c5c 2012-09-02 kinaba: #include <algorithm> 0ea7f42c5c 2012-09-02 kinaba: #include <numeric> 0ea7f42c5c 2012-09-02 kinaba: #include <iterator> 0ea7f42c5c 2012-09-02 kinaba: #include <functional> 0ea7f42c5c 2012-09-02 kinaba: #include <complex> 0ea7f42c5c 2012-09-02 kinaba: #include <queue> 0ea7f42c5c 2012-09-02 kinaba: #include <stack> 0ea7f42c5c 2012-09-02 kinaba: #include <cmath> 0ea7f42c5c 2012-09-02 kinaba: #include <cassert> 0ea7f42c5c 2012-09-02 kinaba: using namespace std; 0ea7f42c5c 2012-09-02 kinaba: typedef long long LL; 0ea7f42c5c 2012-09-02 kinaba: typedef long double LD; 0ea7f42c5c 2012-09-02 kinaba: typedef complex<LD> CMP; 0ea7f42c5c 2012-09-02 kinaba: 0ea7f42c5c 2012-09-02 kinaba: class TheBrickTowerEasyDivOne { public: 0ea7f42c5c 2012-09-02 kinaba: int find(int redCount, int redHeight, int blueCount, int blueHeight) 0ea7f42c5c 2012-09-02 kinaba: { 0ea7f42c5c 2012-09-02 kinaba: if(redHeight != blueHeight) 0ea7f42c5c 2012-09-02 kinaba: { 0ea7f42c5c 2012-09-02 kinaba: int ans = 0; 0ea7f42c5c 2012-09-02 kinaba: ans += min(redCount, blueCount); 0ea7f42c5c 2012-09-02 kinaba: ans += min(redCount-1, blueCount) + 1; 0ea7f42c5c 2012-09-02 kinaba: ans += min(redCount, blueCount-1) + 1; 0ea7f42c5c 2012-09-02 kinaba: return ans; 0ea7f42c5c 2012-09-02 kinaba: } 0ea7f42c5c 2012-09-02 kinaba: return min(redCount,blueCount)*2 + (redCount != blueCount); 0ea7f42c5c 2012-09-02 kinaba: } 0ea7f42c5c 2012-09-02 kinaba: }; 0ea7f42c5c 2012-09-02 kinaba: 0ea7f42c5c 2012-09-02 kinaba: // BEGIN CUT HERE 0ea7f42c5c 2012-09-02 kinaba: #include <ctime> 0ea7f42c5c 2012-09-02 kinaba: double start_time; string timer() 0ea7f42c5c 2012-09-02 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 0ea7f42c5c 2012-09-02 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 0ea7f42c5c 2012-09-02 kinaba: { os << "{ "; 0ea7f42c5c 2012-09-02 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 0ea7f42c5c 2012-09-02 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 0ea7f42c5c 2012-09-02 kinaba: void verify_case(const int& Expected, const int& Received) { 0ea7f42c5c 2012-09-02 kinaba: bool ok = (Expected == Received); 0ea7f42c5c 2012-09-02 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 0ea7f42c5c 2012-09-02 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 0ea7f42c5c 2012-09-02 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 0ea7f42c5c 2012-09-02 kinaba: #define END verify_case(_, TheBrickTowerEasyDivOne().find(redCount, redHeight, blueCount, blueHeight));} 0ea7f42c5c 2012-09-02 kinaba: int main(){ 0ea7f42c5c 2012-09-02 kinaba: 0ea7f42c5c 2012-09-02 kinaba: CASE(0) 0ea7f42c5c 2012-09-02 kinaba: int redCount = 1; 0ea7f42c5c 2012-09-02 kinaba: int redHeight = 2; 0ea7f42c5c 2012-09-02 kinaba: int blueCount = 3; 0ea7f42c5c 2012-09-02 kinaba: int blueHeight = 4; 0ea7f42c5c 2012-09-02 kinaba: int _ = 4; 0ea7f42c5c 2012-09-02 kinaba: END 0ea7f42c5c 2012-09-02 kinaba: CASE(1) 0ea7f42c5c 2012-09-02 kinaba: int redCount = 4; 0ea7f42c5c 2012-09-02 kinaba: int redHeight = 4; 0ea7f42c5c 2012-09-02 kinaba: int blueCount = 4; 0ea7f42c5c 2012-09-02 kinaba: int blueHeight = 7; 0ea7f42c5c 2012-09-02 kinaba: int _ = 12; 0ea7f42c5c 2012-09-02 kinaba: END 0ea7f42c5c 2012-09-02 kinaba: CASE(2) 0ea7f42c5c 2012-09-02 kinaba: int redCount = 7; 0ea7f42c5c 2012-09-02 kinaba: int redHeight = 7; 0ea7f42c5c 2012-09-02 kinaba: int blueCount = 4; 0ea7f42c5c 2012-09-02 kinaba: int blueHeight = 4; 0ea7f42c5c 2012-09-02 kinaba: int _ = 13; 0ea7f42c5c 2012-09-02 kinaba: END 0ea7f42c5c 2012-09-02 kinaba: CASE(3) 0ea7f42c5c 2012-09-02 kinaba: int redCount = 47; 0ea7f42c5c 2012-09-02 kinaba: int redHeight = 47; 0ea7f42c5c 2012-09-02 kinaba: int blueCount = 47; 0ea7f42c5c 2012-09-02 kinaba: int blueHeight = 47; 0ea7f42c5c 2012-09-02 kinaba: int _ = 94; 0ea7f42c5c 2012-09-02 kinaba: END 0ea7f42c5c 2012-09-02 kinaba: /* 0ea7f42c5c 2012-09-02 kinaba: CASE(4) 0ea7f42c5c 2012-09-02 kinaba: int redCount = ; 0ea7f42c5c 2012-09-02 kinaba: int redHeight = ; 0ea7f42c5c 2012-09-02 kinaba: int blueCount = ; 0ea7f42c5c 2012-09-02 kinaba: int blueHeight = ; 0ea7f42c5c 2012-09-02 kinaba: int _ = ; 0ea7f42c5c 2012-09-02 kinaba: END 0ea7f42c5c 2012-09-02 kinaba: CASE(5) 0ea7f42c5c 2012-09-02 kinaba: int redCount = ; 0ea7f42c5c 2012-09-02 kinaba: int redHeight = ; 0ea7f42c5c 2012-09-02 kinaba: int blueCount = ; 0ea7f42c5c 2012-09-02 kinaba: int blueHeight = ; 0ea7f42c5c 2012-09-02 kinaba: int _ = ; 0ea7f42c5c 2012-09-02 kinaba: END 0ea7f42c5c 2012-09-02 kinaba: */ 0ea7f42c5c 2012-09-02 kinaba: } 0ea7f42c5c 2012-09-02 kinaba: // END CUT HERE