Submission #147648


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  int D[55][55];
  for(int i = 0 ; i < N ; i++)
    for(int j = 0 ; j < N ; j++) cin >> D[i][j];
 
  int sum[55][55];
  memset(sum, 0, sizeof(sum));
  
  for(int i = 0 ; i < N ; i++) sum[i][0] = D[i][0];
  
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N-1 ; j++){
      sum[i][j+1] = sum[i][j] + D[i][j+1];
    }
  }
  
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      sum[j+1][i] += sum[j][i];      
    }
  }

  /*
  cout << endl;
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      cout << sum[i][j] << ' ';
    }
    cout << endl;
  }
  */
  int dp[55*55];
  memset(dp, 0, sizeof(dp));
  
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < N ; j++){
      for(int k = i ; k < N ; k++){
	for(int l = j ; l < N ; l++){
	  int S = (k-i+1)*(l-j+1);	  
	  
	  int res = sum[k][l];
	  if(i != 0) res -= sum[i-1][l];
	  if(j != 0) res -= sum[k][j-1];
	  if(i != 0 && j != 0) res += sum[i-1][j-1];
	  
	  dp[S] = max(dp[S], res);
	}
      }
    }
  }
  
  //for(int i = 1 ; i <= N*N ; i++) cout << dp[i] << endl;
  
  int Q;
  cin >> Q;
  
  int x;
  while(Q--){
    cin >> x;
    int ans = 0;
    for(int i = 0 ; i <= x ; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
  }
  
  
  return 0;
}

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User nox
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1407 Byte
Status AC
Exec Time 71 ms
Memory 932 KB

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 50 / 50 50 / 50
Status
AC × 18
AC × 20
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 26 ms 932 KB
rand1.txt AC 28 ms 928 KB
rand2.txt AC 71 ms 760 KB
rand3.txt AC 23 ms 924 KB
rand4.txt AC 21 ms 792 KB
rand_max0.txt AC 44 ms 932 KB
rand_max1.txt AC 44 ms 792 KB
rand_max2.txt AC 43 ms 800 KB
rand_max3.txt AC 44 ms 800 KB
rand_max4.txt AC 44 ms 808 KB
s1.txt AC 20 ms 928 KB
s2.txt AC 20 ms 804 KB
sub0.txt AC 21 ms 740 KB
sub1.txt AC 21 ms 800 KB
sub2.txt AC 21 ms 932 KB
sub_rand_max0.txt AC 22 ms 928 KB
sub_rand_max1.txt AC 21 ms 928 KB
sub_rand_max2.txt AC 21 ms 804 KB
sub_rand_max3.txt AC 21 ms 804 KB
sub_rand_min0.txt AC 20 ms 920 KB