6cfba8c225 2015-12-10 kinaba: #include <iostream> 6cfba8c225 2015-12-10 kinaba: #include <sstream> 6cfba8c225 2015-12-10 kinaba: #include <iomanip> 6cfba8c225 2015-12-10 kinaba: #include <vector> 6cfba8c225 2015-12-10 kinaba: #include <string> 6cfba8c225 2015-12-10 kinaba: #include <map> 6cfba8c225 2015-12-10 kinaba: #include <set> 6cfba8c225 2015-12-10 kinaba: #include <algorithm> 6cfba8c225 2015-12-10 kinaba: #include <numeric> 6cfba8c225 2015-12-10 kinaba: #include <iterator> 6cfba8c225 2015-12-10 kinaba: #include <functional> 6cfba8c225 2015-12-10 kinaba: #include <complex> 6cfba8c225 2015-12-10 kinaba: #include <queue> 6cfba8c225 2015-12-10 kinaba: #include <stack> 6cfba8c225 2015-12-10 kinaba: #include <cmath> 6cfba8c225 2015-12-10 kinaba: #include <cassert> 6cfba8c225 2015-12-10 kinaba: #include <tuple> 6cfba8c225 2015-12-10 kinaba: using namespace std; 6cfba8c225 2015-12-10 kinaba: typedef long long LL; 6cfba8c225 2015-12-10 kinaba: typedef complex<double> CMP; 6cfba8c225 2015-12-10 kinaba: 6cfba8c225 2015-12-10 kinaba: class VampireTree { public: 6cfba8c225 2015-12-10 kinaba: int maxDistance(vector <int> num) 6cfba8c225 2015-12-10 kinaba: { 6cfba8c225 2015-12-10 kinaba: int d1 = 0, d_else = 0, d_kill = 0; 6cfba8c225 2015-12-10 kinaba: for(int d: num) 6cfba8c225 2015-12-10 kinaba: if(d == 1) 6cfba8c225 2015-12-10 kinaba: d1++; 6cfba8c225 2015-12-10 kinaba: else 6cfba8c225 2015-12-10 kinaba: d_else++, d_kill+=d-2; 6cfba8c225 2015-12-10 kinaba: if(d1-d_kill == 2) 6cfba8c225 2015-12-10 kinaba: return d_else + 1; 6cfba8c225 2015-12-10 kinaba: else 6cfba8c225 2015-12-10 kinaba: return -1; 6cfba8c225 2015-12-10 kinaba: } 6cfba8c225 2015-12-10 kinaba: }; 6cfba8c225 2015-12-10 kinaba: 6cfba8c225 2015-12-10 kinaba: // BEGIN CUT HERE 6cfba8c225 2015-12-10 kinaba: #include <ctime> 6cfba8c225 2015-12-10 kinaba: double start_time; string timer() 6cfba8c225 2015-12-10 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 6cfba8c225 2015-12-10 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 6cfba8c225 2015-12-10 kinaba: { os << "{ "; 6cfba8c225 2015-12-10 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 6cfba8c225 2015-12-10 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 6cfba8c225 2015-12-10 kinaba: void verify_case(const int& Expected, const int& Received) { 6cfba8c225 2015-12-10 kinaba: bool ok = (Expected == Received); 6cfba8c225 2015-12-10 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 6cfba8c225 2015-12-10 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 6cfba8c225 2015-12-10 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 6cfba8c225 2015-12-10 kinaba: #define END verify_case(_, VampireTree().maxDistance(num));} 6cfba8c225 2015-12-10 kinaba: int main(){ 6cfba8c225 2015-12-10 kinaba: 6cfba8c225 2015-12-10 kinaba: CASE(0) 6cfba8c225 2015-12-10 kinaba: int num_[] = {1, 2, 1}; 6cfba8c225 2015-12-10 kinaba: vector <int> num(num_, num_+sizeof(num_)/sizeof(*num_)); 6cfba8c225 2015-12-10 kinaba: int _ = 2; 6cfba8c225 2015-12-10 kinaba: END 6cfba8c225 2015-12-10 kinaba: CASE(1) 6cfba8c225 2015-12-10 kinaba: int num_[] = {2, 2, 2}; 6cfba8c225 2015-12-10 kinaba: vector <int> num(num_, num_+sizeof(num_)/sizeof(*num_)); 6cfba8c225 2015-12-10 kinaba: int _ = -1; 6cfba8c225 2015-12-10 kinaba: END 6cfba8c225 2015-12-10 kinaba: CASE(2) 6cfba8c225 2015-12-10 kinaba: int num_[] = {1, 1, 1, 1, 4}; 6cfba8c225 2015-12-10 kinaba: vector <int> num(num_, num_+sizeof(num_)/sizeof(*num_)); 6cfba8c225 2015-12-10 kinaba: int _ = 2; 6cfba8c225 2015-12-10 kinaba: END 6cfba8c225 2015-12-10 kinaba: CASE(3) 6cfba8c225 2015-12-10 kinaba: int num_[] = {1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; 6cfba8c225 2015-12-10 kinaba: vector <int> num(num_, num_+sizeof(num_)/sizeof(*num_)); 6cfba8c225 2015-12-10 kinaba: int _ = -1; 6cfba8c225 2015-12-10 kinaba: END 6cfba8c225 2015-12-10 kinaba: /* 6cfba8c225 2015-12-10 kinaba: CASE(4) 6cfba8c225 2015-12-10 kinaba: int num_[] = ; 6cfba8c225 2015-12-10 kinaba: vector <int> num(num_, num_+sizeof(num_)/sizeof(*num_)); 6cfba8c225 2015-12-10 kinaba: int _ = ; 6cfba8c225 2015-12-10 kinaba: END 6cfba8c225 2015-12-10 kinaba: CASE(5) 6cfba8c225 2015-12-10 kinaba: int num_[] = ; 6cfba8c225 2015-12-10 kinaba: vector <int> num(num_, num_+sizeof(num_)/sizeof(*num_)); 6cfba8c225 2015-12-10 kinaba: int _ = ; 6cfba8c225 2015-12-10 kinaba: END 6cfba8c225 2015-12-10 kinaba: */ 6cfba8c225 2015-12-10 kinaba: 6cfba8c225 2015-12-10 kinaba: } 6cfba8c225 2015-12-10 kinaba: // END CUT HERE