|
| 1 | +// BEGIN CUT HERE |
| 2 | + |
| 3 | +// END CUT HERE |
| 4 | +#include <algorithm> |
| 5 | +#include <iostream> |
| 6 | +#include <sstream> |
| 7 | +#include <string> |
| 8 | +#include <vector> |
| 9 | +#include <queue> |
| 10 | +#include <set> |
| 11 | +#include <map> |
| 12 | +#include <cstdio> |
| 13 | +#include <cstdlib> |
| 14 | +#include <cctype> |
| 15 | +#include <cmath> |
| 16 | +#include <string> |
| 17 | +#include <cstring> |
| 18 | +using namespace std; |
| 19 | + |
| 20 | +// BEGIN CUT HERE |
| 21 | +#define ARRSIZE(x) (sizeof(x)/sizeof(x[0])) |
| 22 | + |
| 23 | +template<typename T> void print( T a ) { |
| 24 | + cerr << a; |
| 25 | +} |
| 26 | +static void print( long long a ) { |
| 27 | + cerr << a << "L"; |
| 28 | +} |
| 29 | +static void print( string a ) { |
| 30 | + cerr << '"' << a << '"'; |
| 31 | +} |
| 32 | +template<typename T> void print( vector<T> a ) { |
| 33 | + cerr << "{"; |
| 34 | + for ( int i = 0 ; i != a.size() ; i++ ) { |
| 35 | + if ( i != 0 ) cerr << ", "; |
| 36 | + print( a[i] ); |
| 37 | + } |
| 38 | + cerr << "}" << endl; |
| 39 | +} |
| 40 | +template<typename T> void eq( int n, T have, T need ) { |
| 41 | + if ( have == need ) { |
| 42 | + cerr << "Case " << n << " passed." << endl; |
| 43 | + } else { |
| 44 | + cerr << "Case " << n << " failed: expected "; |
| 45 | + print( need ); |
| 46 | + cerr << " received "; |
| 47 | + print( have ); |
| 48 | + cerr << "." << endl; |
| 49 | + } |
| 50 | +} |
| 51 | +template<typename T> void eq( int n, vector<T> have, vector<T> need ) { |
| 52 | + if( have.size() != need.size() ) { |
| 53 | + cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements."; |
| 54 | + print( have ); |
| 55 | + print( need ); |
| 56 | + return; |
| 57 | + } |
| 58 | + for( int i= 0; i < have.size(); i++ ) { |
| 59 | + if( have[i] != need[i] ) { |
| 60 | + cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << "."; |
| 61 | + print( have ); |
| 62 | + print( need ); |
| 63 | + return; |
| 64 | + } |
| 65 | + } |
| 66 | + cerr << "Case " << n << " passed." << endl; |
| 67 | +} |
| 68 | +static void eq( int n, string have, string need ) { |
| 69 | + if ( have == need ) { |
| 70 | + cerr << "Case " << n << " passed." << endl; |
| 71 | + } else { |
| 72 | + cerr << "Case " << n << " failed: expected "; |
| 73 | + print( need ); |
| 74 | + cerr << " received "; |
| 75 | + print( have ); |
| 76 | + cerr << "." << endl; |
| 77 | + } |
| 78 | +} |
| 79 | +// END CUT HERE |
| 80 | + |
| 81 | +#define REP(i,n) for(int i=0;i<(n);++i) |
| 82 | +#define FOR(i,a,b) for(int i=(a);i<=(b);++i) |
| 83 | +#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) |
| 84 | + |
| 85 | +// BEGIN CUT HERE |
| 86 | +vector<string> split( const string& s, const string& delim =" " ) { |
| 87 | + vector<string> res; |
| 88 | + string t; |
| 89 | + for ( int i = 0 ; i != s.size() ; i++ ) { |
| 90 | + if ( delim.find( s[i] ) != string::npos ) { |
| 91 | + if ( !t.empty() ) { |
| 92 | + res.push_back( t ); |
| 93 | + t = ""; |
| 94 | + } |
| 95 | + } else { |
| 96 | + t += s[i]; |
| 97 | + } |
| 98 | + } |
| 99 | + if ( !t.empty() ) { |
| 100 | + res.push_back(t); |
| 101 | + } |
| 102 | + return res; |
| 103 | +} |
| 104 | + |
| 105 | +vector<int> splitInt( const string& s, const string& delim =" " ) { |
| 106 | + vector<string> tok = split( s, delim ); |
| 107 | + vector<int> res; |
| 108 | + for ( int i = 0 ; i != tok.size(); i++ ) |
| 109 | + res.push_back( atoi( tok[i].c_str() ) ); |
| 110 | + return res; |
| 111 | +} |
| 112 | +// END CUT HERE |
| 113 | + |
| 114 | +// BEGIN CUT HERE |
| 115 | +int s2i(string s) { |
| 116 | + stringstream ss; |
| 117 | + ss << s; |
| 118 | + int res; |
| 119 | + ss >> res; |
| 120 | + return res; |
| 121 | +} |
| 122 | + |
| 123 | +string i2s(int n) { |
| 124 | + stringstream ss; |
| 125 | + ss << n; |
| 126 | + string res; |
| 127 | + ss >> res; |
| 128 | + return res; |
| 129 | +} |
| 130 | +// END CUT HERE |
| 131 | + |
| 132 | +class SixteenBricks { |
| 133 | +public: |
| 134 | + int maximumSurface(vector <int> height) { |
| 135 | + sort(height.begin(), height.end()); |
| 136 | + int res = 16; |
| 137 | + REP(i,16) res += height[i] * 4; |
| 138 | + FOR(i,0,1) res -= height[i] * 4 * 2; |
| 139 | + FOR(i,2,5) res -= height[i] * 3 * 2; |
| 140 | + FOR(i,6,7) res -= height[i] * 2 * 2; |
| 141 | + return res; |
| 142 | + } |
| 143 | +}; |
| 144 | +// BEGIN CUT HERE |
| 145 | +int main() { |
| 146 | + { |
| 147 | + int heightARRAY[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; |
| 148 | + vector <int> height( heightARRAY, heightARRAY+ARRSIZE(heightARRAY) ); |
| 149 | + SixteenBricks theObject; |
| 150 | + eq(0, theObject.maximumSurface(height),32); |
| 151 | + } |
| 152 | + { |
| 153 | + int heightARRAY[] = {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2}; |
| 154 | + vector <int> height( heightARRAY, heightARRAY+ARRSIZE(heightARRAY) ); |
| 155 | + SixteenBricks theObject; |
| 156 | + eq(1, theObject.maximumSurface(height),64); |
| 157 | + } |
| 158 | + { |
| 159 | + int heightARRAY[] = {77, 78, 58, 34, 30, 20, 8, 71, 37, 74, 21, 45, 39, 16, 4, 59} |
| 160 | + ; |
| 161 | + vector <int> height( heightARRAY, heightARRAY+ARRSIZE(heightARRAY) ); |
| 162 | + SixteenBricks theObject; |
| 163 | + eq(2, theObject.maximumSurface(height),1798); |
| 164 | + } |
| 165 | + return 0; |
| 166 | +} |
| 167 | +// END CUT HERE |
0 commit comments