Submission #2006369


Source Code Expand

#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

template < class T > class IMOS_2D {

private:
    
    int N;
    vector < vector < T > > acc;

public:

    IMOS_2D (int h, int w) : acc(h + 1, vector < T > (w + 1, 0)) {}
    
    void add(int x, int y, T val) {
        acc[x][y] += val; 
    }
    
    void update(int x, int y, T val) {
        acc[x][y] = val;
    }

    void build() {
        for (int x = 0; x < acc.size() - 1; x++) {
            for (int y = 0; y < acc[x].size() - 1; y++) {
                acc[x][y + 1] = acc[x][y] + acc[x][y + 1];
            }
        }
        for (int x = 0; x < acc.size() - 1; x++) {
            for (int y = 0; y < acc[x].size() - 1; y++) {
                acc[x + 1][y] = acc[x][y] + acc[x + 1][y];
            }
        }
    }

    T sum(int x1, int y1, int x2, int y2) {
        x2--; y2--;
        int ret = acc[x2][y2];
        if (y1 > 0) ret -= acc[x2][y1 - 1];
        if (x1 > 0) ret -= acc[x1 - 1][y2];
        if (x1 > 0 && y1 > 0) ret += acc[x1 - 1][y1 - 1];
        return ret;
    }

    vector < T > & operator [] (int n) {
        return acc[n];
    }

};

 
int main(){
  
    int H,W; cin>>H>>W;
    IMOS_2D <int> black(H,W);
    IMOS_2D <int> white(H,W);

    REP(i,H)REP(j,W){
        if((i+j)%2==0)cin>>black[i][j];
        else cin>>white[i][j];
    }
    
    black.build();
    white.build();

    int ans=0;    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int x=i + 1; x<=H;x++){
                for(int y=j + 1;y<=W;y++){
                    int sumw=white.sum(i,j,x,y);
                    int sumb=black.sum(i,j,x,y);
                    if(sumw==sumb)ans=max(ans,(x-i)*(y-j));
                }
            }
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Submission Info

Submission Time
Task B - チョコレート
User kosakkun
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2448 Byte
Status AC
Exec Time 94 ms
Memory 512 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 1 ms 256 KB
subtask0_sample-02.txt AC 1 ms 256 KB
subtask0_sample-03.txt AC 1 ms 256 KB
subtask0_sample-04.txt AC 1 ms 256 KB
subtask0_sample-05.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 2 ms 256 KB
subtask1_07.txt AC 1 ms 256 KB
subtask1_08.txt AC 1 ms 256 KB
subtask1_09.txt AC 92 ms 384 KB
subtask1_10.txt AC 15 ms 256 KB
subtask1_11.txt AC 79 ms 384 KB
subtask1_12.txt AC 79 ms 384 KB
subtask1_13.txt AC 79 ms 384 KB
subtask1_14.txt AC 93 ms 384 KB
subtask1_15.txt AC 94 ms 384 KB
subtask1_16.txt AC 76 ms 384 KB
subtask1_17.txt AC 74 ms 384 KB
subtask1_18.txt AC 1 ms 256 KB
subtask1_19.txt AC 1 ms 256 KB
subtask1_20.txt AC 93 ms 512 KB