Submission #183498


Source Code Expand

#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std; using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using SS = stringstream;
using PII = pair<int,int>;
using VPII = vector< pair<int,int> >;
template < typename T = int > using VT = vector<T>;
template < typename T = int > using VVT = VT< VT<T> >;
template < typename T = int > using LIM = numeric_limits<T>;

template < typename T > inline T fromString( const string &s ){ T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) (c).begin(), (c).end()
#define AALL( a, t ) (t*)a, (t*)a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

// 累積和による区間 Sum クエリ
// 前処理 O( HW )
// クエリ O( 1 )
class ConsecutiveSums2d
{
private:
	const int H, W;
	vector< vector<int> > src, csum;
	bool isSolved;

public:
	ConsecutiveSums2d( const int h, const int w ) : H( h ), W( w ), src( H, vector<int>( W ) ), isSolved( false ) {};
	ConsecutiveSums2d( const vector< vector<int> > &s ) : H( s.size() ), W( s[0].size() ), src( s ), isSolved( false ) {};

	int get( const int y, const int x ) const
	{
		return src[y][x];
	}

	void set( const int y, const int x, const int v )
	{
		src[y][x] = v;
		isSolved = false;
		
		return;
	}

	int sum( const int y1, const int x1, const int y2, const int x2 )
	{
		if ( !isSolved )
		{
			solve();
		}
		return csum[ y2 + 1 ][ x2 + 1 ] - csum[ y2 + 1 ][ x1 ] - csum[ y1 ][ x2 + 1 ] + csum[ y1 ][ x1 ];
	}

private:
	void solve()
	{
		csum.clear();
		csum.resize( H + 1, vector<int>( W + 1 ) );

		for ( int i = 0; i < H; ++i )
		{
			partial_sum( src[i].begin(), src[i].end(), csum[ i + 1 ].begin() + 1 );
		}

		for ( int i = 0; i < H; ++i )
		{
			for ( int j = 0; j <= W; ++j )
			{
				csum[ i + 1 ][j] += csum[i][j];
			}
		}

		isSolved = true;
		return;
	}
};
// Consecutivesums2d( H, W )
// Consecutivesums2d( SRC )
// get( y, x )
// set( y, x, value )
// sum( y1, x1, y2, x2 )

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int h, w;
	cin >> h >> w;

	VVI board( h, VI( w ) );
	FOR( row, board )
	{
		FOR( c, row )
		{
			cin >> c;
		}
	}

	ConsecutiveSums2d csum1( h, w ), csum2( h, w );

	REP( i, 0, h )
	{
		REP( j, 0, w )
		{
			( ( i + j ) % 2 ? csum1 : csum2 ).set( i, j, board[i][j] );
		}
	}

	int res = 0;
	REP( y1, 0, h )
	{
		REP( y2, y1, h )
		{
			REP( x1, 0, w )
			{
				REP( x2, x1, w )
				{
					if ( csum1.sum( y1, x1, y2, x2 ) == csum2.sum( y1, x1, y2, x2 ) )
					{
						res = max( res, ( y2 -y1 + 1 ) * ( x2 - x1 + 1 ) );
					}
				}
			}
		}
	}

	cout << res << endl;

	return 0;
}

Submission Info

Submission Time
Task B - チョコレート
User torus711
Language C++11 (GCC 4.8.1)
Score 100
Code Size 3581 Byte
Status AC
Exec Time 321 ms
Memory 1164 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 5
AC × 25
Set Name Test Cases
Sample subtask0_sample-01.txt, subtask0_sample-02.txt, subtask0_sample-03.txt, subtask0_sample-04.txt, subtask0_sample-05.txt
All subtask0_sample-01.txt, subtask0_sample-02.txt, subtask0_sample-03.txt, subtask0_sample-04.txt, subtask0_sample-05.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt
Case Name Status Exec Time Memory
subtask0_sample-01.txt AC 32 ms 796 KB
subtask0_sample-02.txt AC 22 ms 912 KB
subtask0_sample-03.txt AC 22 ms 916 KB
subtask0_sample-04.txt AC 23 ms 848 KB
subtask0_sample-05.txt AC 26 ms 864 KB
subtask1_01.txt AC 22 ms 916 KB
subtask1_02.txt AC 23 ms 916 KB
subtask1_03.txt AC 24 ms 736 KB
subtask1_04.txt AC 24 ms 796 KB
subtask1_05.txt AC 25 ms 896 KB
subtask1_06.txt AC 25 ms 920 KB
subtask1_07.txt AC 21 ms 836 KB
subtask1_08.txt AC 23 ms 920 KB
subtask1_09.txt AC 299 ms 1076 KB
subtask1_10.txt AC 62 ms 912 KB
subtask1_11.txt AC 283 ms 1164 KB
subtask1_12.txt AC 284 ms 1160 KB
subtask1_13.txt AC 285 ms 984 KB
subtask1_14.txt AC 321 ms 1052 KB
subtask1_15.txt AC 306 ms 1140 KB
subtask1_16.txt AC 274 ms 1080 KB
subtask1_17.txt AC 242 ms 1144 KB
subtask1_18.txt AC 24 ms 920 KB
subtask1_19.txt AC 23 ms 916 KB
subtask1_20.txt AC 305 ms 1116 KB