|
| 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 | +#define FOREACH(it,c) for(typeof((c).begin())it=(c).begin();it!=(c).end();++it) |
| 85 | +#define CLR(x) memset((x),0,sizeof((x))) |
| 86 | +typedef long long LL; |
| 87 | +typedef vector<int> VI; |
| 88 | +typedef vector<string> VS; |
| 89 | + |
| 90 | +// BEGIN CUT HERE |
| 91 | +vector<string> split( const string& s, const string& delim =" " ) { |
| 92 | + vector<string> res; |
| 93 | + string t; |
| 94 | + for ( int i = 0 ; i != s.size() ; i++ ) { |
| 95 | + if ( delim.find( s[i] ) != string::npos ) { |
| 96 | + if ( !t.empty() ) { |
| 97 | + res.push_back( t ); |
| 98 | + t = ""; |
| 99 | + } |
| 100 | + } else { |
| 101 | + t += s[i]; |
| 102 | + } |
| 103 | + } |
| 104 | + if ( !t.empty() ) { |
| 105 | + res.push_back(t); |
| 106 | + } |
| 107 | + return res; |
| 108 | +} |
| 109 | + |
| 110 | +vector<int> splitInt( const string& s, const string& delim =" " ) { |
| 111 | + vector<string> tok = split( s, delim ); |
| 112 | + vector<int> res; |
| 113 | + for ( int i = 0 ; i != tok.size(); i++ ) |
| 114 | + res.push_back( atoi( tok[i].c_str() ) ); |
| 115 | + return res; |
| 116 | +} |
| 117 | +// END CUT HERE |
| 118 | + |
| 119 | +// BEGIN CUT HERE |
| 120 | +int s2i(string s) { |
| 121 | + stringstream ss; |
| 122 | + ss << s; |
| 123 | + int res; |
| 124 | + ss >> res; |
| 125 | + return res; |
| 126 | +} |
| 127 | + |
| 128 | +string i2s(int n) { |
| 129 | + stringstream ss; |
| 130 | + ss << n; |
| 131 | + string res; |
| 132 | + ss >> res; |
| 133 | + return res; |
| 134 | +} |
| 135 | +// END CUT HERE |
| 136 | + |
| 137 | +int hh[105][105], vv[105][105]; |
| 138 | + |
| 139 | +class TheMatrix { |
| 140 | +public: |
| 141 | + int MaxArea(vector <string> board) { |
| 142 | + int n = board.size(), m = board[0].length(); |
| 143 | + REP(i,n) { |
| 144 | + REP(j,m) { |
| 145 | + hh[i][j] = 1; |
| 146 | + FOR(ii,j+1,m-1) { |
| 147 | + if (board[i][ii] != board[i][ii - 1]) ++hh[i][j]; |
| 148 | + else break; |
| 149 | + } |
| 150 | + vv[i][j] = 1; |
| 151 | + FOR(ii,i+1,n-1) { |
| 152 | + if (board[ii][j] != board[ii - 1][j]) ++vv[i][j]; |
| 153 | + else break; |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + int res = 1; |
| 159 | + REP(i,n) { |
| 160 | + REP(j,m) { |
| 161 | + if ((n - i) * (m - j) <= res) continue; |
| 162 | + int t = vv[i][j]; |
| 163 | + REP(ii,hh[i][j]) { |
| 164 | + t = min(t, vv[i][j + ii]); |
| 165 | + res = max(res, t * (ii + 1)); |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + return res; |
| 170 | + } |
| 171 | +}; |
| 172 | +// BEGIN CUT HERE |
| 173 | +int main() { |
| 174 | + { |
| 175 | + string boardARRAY[] = {"1", |
| 176 | + "0"}; |
| 177 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 178 | + TheMatrix theObject; |
| 179 | + eq(0, theObject.MaxArea(board),2); |
| 180 | + } |
| 181 | + { |
| 182 | + string boardARRAY[] = {"0000"}; |
| 183 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 184 | + TheMatrix theObject; |
| 185 | + eq(1, theObject.MaxArea(board),1); |
| 186 | + } |
| 187 | + { |
| 188 | + string boardARRAY[] = {"01"}; |
| 189 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 190 | + TheMatrix theObject; |
| 191 | + eq(2, theObject.MaxArea(board),2); |
| 192 | + } |
| 193 | + { |
| 194 | + string boardARRAY[] = {"001", |
| 195 | + "000", |
| 196 | + "100"}; |
| 197 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 198 | + TheMatrix theObject; |
| 199 | + eq(3, theObject.MaxArea(board),2); |
| 200 | + } |
| 201 | + { |
| 202 | + string boardARRAY[] = {"0"}; |
| 203 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 204 | + TheMatrix theObject; |
| 205 | + eq(4, theObject.MaxArea(board),1); |
| 206 | + } |
| 207 | + { |
| 208 | + string boardARRAY[] = {"101", |
| 209 | + "010"}; |
| 210 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 211 | + TheMatrix theObject; |
| 212 | + eq(5, theObject.MaxArea(board),6); |
| 213 | + } |
| 214 | + { |
| 215 | + string boardARRAY[] = {"101", |
| 216 | + "011", |
| 217 | + "101", |
| 218 | + "010"}; |
| 219 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 220 | + TheMatrix theObject; |
| 221 | + eq(6, theObject.MaxArea(board),8); |
| 222 | + } |
| 223 | + { |
| 224 | + string boardARRAY[] = {"11001110011000110001111001001110110011010110001011", |
| 225 | + "10100100010111111011111001011110101111010011100001", |
| 226 | + "11101111001110100110010101101100011100101000010001", |
| 227 | + "01000010001010101100010011111000100100110111111000", |
| 228 | + "10110100000101100000111000100001011101111101010010", |
| 229 | + "00111010000011100001110110010011010110010011100100", |
| 230 | + "01100001111101001101001101100001111000111001101010", |
| 231 | + "11010000000011011010100010000000111011001001100101", |
| 232 | + "10100000000100010100100011010100110110110001000001", |
| 233 | + "01101010101100001100000110100110100000010100100010", |
| 234 | + "11010000001110111111011010011110001101100011100010", |
| 235 | + "11101111000000011010011100100001100011111111110111", |
| 236 | + "11000001101100100011000110111010011001010100000001", |
| 237 | + "00100001111001010000101101100010000001100100001000", |
| 238 | + "01001110110111101011010000111111101011000110010111", |
| 239 | + "01001010000111111001100000100010101100100101010100", |
| 240 | + "11111101001101110011011011011000111001101100011011", |
| 241 | + "10000100110111000001110110010000000000111100101101", |
| 242 | + "01010011101101101110000011000110011111001111011100", |
| 243 | + "01101010011111010000011001111101011010011100001101", |
| 244 | + "11011000011000110010101111100000101011011111101100", |
| 245 | + "11100001001000110010100011001010101101001010001100", |
| 246 | + "11011011001100111101001100111100000101011101101011", |
| 247 | + "11110111100100101011100101111101000111001111110111", |
| 248 | + "00011001100110111100111100001100101001111100001111", |
| 249 | + "10001111100101110111001111100000000011110000100111", |
| 250 | + "10101010110110100110010001001010000111100110100011", |
| 251 | + "01100110100000001110101001101011001010001101110101", |
| 252 | + "10110101110100110110101001100111110000101111100110", |
| 253 | + "01011000001001101110100001101001110011001001110001", |
| 254 | + "00100101010001100110110101001010010100001011000011", |
| 255 | + "00011101100100001010100000000011000010100110011100", |
| 256 | + "11001001011000000101111111000000110010001101101110", |
| 257 | + "10101010110110010000010011001100110101110100111011", |
| 258 | + "01101001010111010001101000100011101001110101000110", |
| 259 | + "00110101101110110001110101110010100100110000101101", |
| 260 | + "11010101000111010011110011000001101111010011110011", |
| 261 | + "10010000010001110011011101001110110010001100011100", |
| 262 | + "00111101110001001100101001110100110010100110110000", |
| 263 | + "00010011011000101000100001101110111100100000010100", |
| 264 | + "01101110001101000001001000001011101010011101011110", |
| 265 | + "00000100110011001011101011110011011101100001110111", |
| 266 | + "00110011110000011001011100001110101010100110010110", |
| 267 | + "00111001010011011111010100000100100000101101110001", |
| 268 | + "10101101101110111110000011111011001011100011110001", |
| 269 | + "00101110010101111000001010110100001110111011100011", |
| 270 | + "01111110010100111010110001111000111101110100111011"}; |
| 271 | + vector <string> board( boardARRAY, boardARRAY+ARRSIZE(boardARRAY) ); |
| 272 | + TheMatrix theObject; |
| 273 | + eq(7, theObject.MaxArea(board),12); |
| 274 | + } |
| 275 | + return 0; |
| 276 | +} |
| 277 | +// END CUT HERE |
0 commit comments