Submission #147271
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 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 )
#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, csums;
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> > &src ) : H( src.size() ), W( src[0].size() ), src( src ), 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 y2, const int x1, const int x2 )
{
if ( !isSolved )
{
solve();
}
return csums[ y2 + 1 ][ x2 + 1 ] - csums[ y2 + 1 ][ x1 ] - csums[ y1 ][ x2 + 1 ] + csums[ y1 ][ x1 ];
}
private:
void solve()
{
csums.clear();
csums.resize( H + 1, vector<int>( W + 1 ) );
for ( int i = 0; i < H; ++i )
{
partial_sum( src[i].begin(), src[i].end(), csums[ i + 1 ].begin() + 1 );
}
for ( int i = 0; i < H; ++i )
{
for ( int j = 0; j <= W; ++j )
{
csums[ i + 1 ][j] += csums[i][j];
}
}
isSolved = true;
return;
}
};
// consecutivesums2d( H, W )
// consecutivesums2d( SRC )
// get( y, x )
// set( y, x, value )
// sum( y1, y2, x1, x2 )
int main()
{
cin.tie( 0 );
ios::sync_with_stdio( false );
int n;
cin >> n;
VVI board( n, VI( n ) );
FOR( line, board )
{
FOR( d, line )
{
cin >> d;
}
}
ConsecutiveSums2d csums( board );
VI maxes( n * n + 1 );
REP( y1, 0, n )
{
REP( y2, y1, n )
{
REP( x1, 0, n )
{
REP( x2, 0, n )
{
const int s = ( y2 - y1 + 1 ) * ( x2 - x1 + 1 );
maxes[s] = max( maxes[s], csums.sum( y1, y2, x1, x2 ) );
}
}
}
}
int q;
cin >> q;
REP( i, 0, q )
{
int p;
cin >> p;
cout << *max_element( maxes.begin(), maxes.begin() + p + 1 ) << endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - おいしいたこ焼きの焼き方 |
User |
torus711 |
Language |
C++11 (GCC 4.8.1) |
Score |
100 |
Code Size |
3517 Byte |
Status |
AC |
Exec Time |
58 ms |
Memory |
932 KB |
Judge Result
Set Name |
Subtask1 |
Subtask2 |
Score / Max Score |
50 / 50 |
50 / 50 |
Status |
|
|
Set Name |
Test Cases |
Subtask1 |
sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt |
Subtask2 |
rand0.txt, rand1.txt, rand2.txt, rand3.txt, rand4.txt, rand_max0.txt, rand_max1.txt, rand_max2.txt, rand_max3.txt, rand_max4.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt |
Case Name |
Status |
Exec Time |
Memory |
rand0.txt |
AC |
35 ms |
796 KB |
rand1.txt |
AC |
32 ms |
804 KB |
rand2.txt |
AC |
41 ms |
932 KB |
rand3.txt |
AC |
24 ms |
928 KB |
rand4.txt |
AC |
21 ms |
928 KB |
rand_max0.txt |
AC |
58 ms |
928 KB |
rand_max1.txt |
AC |
58 ms |
928 KB |
rand_max2.txt |
AC |
58 ms |
812 KB |
rand_max3.txt |
AC |
57 ms |
884 KB |
rand_max4.txt |
AC |
58 ms |
804 KB |
s1.txt |
AC |
21 ms |
924 KB |
s2.txt |
AC |
23 ms |
924 KB |
sub0.txt |
AC |
21 ms |
932 KB |
sub1.txt |
AC |
21 ms |
932 KB |
sub2.txt |
AC |
21 ms |
796 KB |
sub_rand_max0.txt |
AC |
21 ms |
792 KB |
sub_rand_max1.txt |
AC |
21 ms |
804 KB |
sub_rand_max2.txt |
AC |
21 ms |
924 KB |
sub_rand_max3.txt |
AC |
21 ms |
928 KB |
sub_rand_min0.txt |
AC |
20 ms |
800 KB |