2e5fb9b56a 2013-02-13 kinaba: #include <iostream> 2e5fb9b56a 2013-02-13 kinaba: #include <sstream> 2e5fb9b56a 2013-02-13 kinaba: #include <iomanip> 2e5fb9b56a 2013-02-13 kinaba: #include <vector> 2e5fb9b56a 2013-02-13 kinaba: #include <string> 2e5fb9b56a 2013-02-13 kinaba: #include <map> 2e5fb9b56a 2013-02-13 kinaba: #include <set> 2e5fb9b56a 2013-02-13 kinaba: #include <algorithm> 2e5fb9b56a 2013-02-13 kinaba: #include <numeric> 2e5fb9b56a 2013-02-13 kinaba: #include <iterator> 2e5fb9b56a 2013-02-13 kinaba: #include <functional> 2e5fb9b56a 2013-02-13 kinaba: #include <complex> 2e5fb9b56a 2013-02-13 kinaba: #include <queue> 2e5fb9b56a 2013-02-13 kinaba: #include <stack> 2e5fb9b56a 2013-02-13 kinaba: #include <cmath> 2e5fb9b56a 2013-02-13 kinaba: #include <cassert> 2e5fb9b56a 2013-02-13 kinaba: using namespace std; 2e5fb9b56a 2013-02-13 kinaba: typedef long long LL; 2e5fb9b56a 2013-02-13 kinaba: typedef long double LD; 2e5fb9b56a 2013-02-13 kinaba: typedef complex<LD> CMP; 2e5fb9b56a 2013-02-13 kinaba: 2e5fb9b56a 2013-02-13 kinaba: class TheDevice { public: 2e5fb9b56a 2013-02-13 kinaba: int minimumAdditional(vector <string> plates) 2e5fb9b56a 2013-02-13 kinaba: { 2e5fb9b56a 2013-02-13 kinaba: int NB = plates[0].size(); 2e5fb9b56a 2013-02-13 kinaba: int lackMax = 0; 2e5fb9b56a 2013-02-13 kinaba: for(int i=0; i<NB; ++i) 2e5fb9b56a 2013-02-13 kinaba: { 2e5fb9b56a 2013-02-13 kinaba: int zero=0, one=0; 2e5fb9b56a 2013-02-13 kinaba: for(int k=0; k<plates.size(); ++k) 2e5fb9b56a 2013-02-13 kinaba: (plates[k][i]=='0' ? zero : one)++; 2e5fb9b56a 2013-02-13 kinaba: int lack = max(0,1-zero)+max(0,2-one); 2e5fb9b56a 2013-02-13 kinaba: lackMax = max(lackMax, lack); 2e5fb9b56a 2013-02-13 kinaba: } 2e5fb9b56a 2013-02-13 kinaba: return lackMax; 2e5fb9b56a 2013-02-13 kinaba: } 2e5fb9b56a 2013-02-13 kinaba: }; 2e5fb9b56a 2013-02-13 kinaba: 2e5fb9b56a 2013-02-13 kinaba: // BEGIN CUT HERE 2e5fb9b56a 2013-02-13 kinaba: #include <ctime> 2e5fb9b56a 2013-02-13 kinaba: double start_time; string timer() 2e5fb9b56a 2013-02-13 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 2e5fb9b56a 2013-02-13 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 2e5fb9b56a 2013-02-13 kinaba: { os << "{ "; 2e5fb9b56a 2013-02-13 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 2e5fb9b56a 2013-02-13 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 2e5fb9b56a 2013-02-13 kinaba: void verify_case(const int& Expected, const int& Received) { 2e5fb9b56a 2013-02-13 kinaba: bool ok = (Expected == Received); 2e5fb9b56a 2013-02-13 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 2e5fb9b56a 2013-02-13 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 2e5fb9b56a 2013-02-13 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 2e5fb9b56a 2013-02-13 kinaba: #define END verify_case(_, TheDevice().minimumAdditional(plates));} 2e5fb9b56a 2013-02-13 kinaba: int main(){ 2e5fb9b56a 2013-02-13 kinaba: 2e5fb9b56a 2013-02-13 kinaba: CASE(0) 2e5fb9b56a 2013-02-13 kinaba: string plates_[] = {"010", 2e5fb9b56a 2013-02-13 kinaba: "011", 2e5fb9b56a 2013-02-13 kinaba: "101"}; 2e5fb9b56a 2013-02-13 kinaba: vector <string> plates(plates_, plates_+sizeof(plates_)/sizeof(*plates_)); 2e5fb9b56a 2013-02-13 kinaba: int _ = 1; 2e5fb9b56a 2013-02-13 kinaba: END 2e5fb9b56a 2013-02-13 kinaba: CASE(1) 2e5fb9b56a 2013-02-13 kinaba: string plates_[] = {"0", 2e5fb9b56a 2013-02-13 kinaba: "1", 2e5fb9b56a 2013-02-13 kinaba: "0", 2e5fb9b56a 2013-02-13 kinaba: "1"}; 2e5fb9b56a 2013-02-13 kinaba: vector <string> plates(plates_, plates_+sizeof(plates_)/sizeof(*plates_)); 2e5fb9b56a 2013-02-13 kinaba: int _ = 0; 2e5fb9b56a 2013-02-13 kinaba: END 2e5fb9b56a 2013-02-13 kinaba: CASE(2) 2e5fb9b56a 2013-02-13 kinaba: string plates_[] = {"01010101", 2e5fb9b56a 2013-02-13 kinaba: "10101010"}; 2e5fb9b56a 2013-02-13 kinaba: vector <string> plates(plates_, plates_+sizeof(plates_)/sizeof(*plates_)); 2e5fb9b56a 2013-02-13 kinaba: int _ = 1; 2e5fb9b56a 2013-02-13 kinaba: END 2e5fb9b56a 2013-02-13 kinaba: CASE(3) 2e5fb9b56a 2013-02-13 kinaba: string plates_[] = {"10010101011", 2e5fb9b56a 2013-02-13 kinaba: "00010101001", 2e5fb9b56a 2013-02-13 kinaba: "00100010111", 2e5fb9b56a 2013-02-13 kinaba: "00101010101", 2e5fb9b56a 2013-02-13 kinaba: "01010111101"}; 2e5fb9b56a 2013-02-13 kinaba: vector <string> plates(plates_, plates_+sizeof(plates_)/sizeof(*plates_)); 2e5fb9b56a 2013-02-13 kinaba: int _ = 1; 2e5fb9b56a 2013-02-13 kinaba: END 2e5fb9b56a 2013-02-13 kinaba: CASE(4) 2e5fb9b56a 2013-02-13 kinaba: string plates_[] = {"1101001011010", 2e5fb9b56a 2013-02-13 kinaba: "0010000010101", 2e5fb9b56a 2013-02-13 kinaba: "1010101011110", 2e5fb9b56a 2013-02-13 kinaba: "1101010100111", 2e5fb9b56a 2013-02-13 kinaba: "1011111110111"}; 2e5fb9b56a 2013-02-13 kinaba: vector <string> plates(plates_, plates_+sizeof(plates_)/sizeof(*plates_)); 2e5fb9b56a 2013-02-13 kinaba: int _ = 0; 2e5fb9b56a 2013-02-13 kinaba: END 2e5fb9b56a 2013-02-13 kinaba: /* 2e5fb9b56a 2013-02-13 kinaba: CASE(5) 2e5fb9b56a 2013-02-13 kinaba: string plates_[] = ; 2e5fb9b56a 2013-02-13 kinaba: vector <string> plates(plates_, plates_+sizeof(plates_)/sizeof(*plates_)); 2e5fb9b56a 2013-02-13 kinaba: int _ = ; 2e5fb9b56a 2013-02-13 kinaba: END 2e5fb9b56a 2013-02-13 kinaba: CASE(6) 2e5fb9b56a 2013-02-13 kinaba: string plates_[] = ; 2e5fb9b56a 2013-02-13 kinaba: vector <string> plates(plates_, plates_+sizeof(plates_)/sizeof(*plates_)); 2e5fb9b56a 2013-02-13 kinaba: int _ = ; 2e5fb9b56a 2013-02-13 kinaba: END 2e5fb9b56a 2013-02-13 kinaba: */ 2e5fb9b56a 2013-02-13 kinaba: } 2e5fb9b56a 2013-02-13 kinaba: // END CUT HERE