Submission #1610326


Source Code Expand

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}

int nextInt() { int x; scanf("%d", &x); return x;}

int D[55][55];
int acc[55][55];
int ans[3000];

// [ r1, r2 ) - [ c1, c2 )
int get(int r1, int c1, int r2, int c2) {
  return acc[r2][c2] - acc[r2][c1] - acc[r1][c2] + acc[r1][c1];
}

int main2() {
  int N = nextInt();
  REP(i, N) REP(j, N) D[i][j] = nextInt();
  memset(acc, 0, sizeof(acc));
  memset(ans, 0, sizeof(ans));

  REP(i, N) REP(j, N) {
    acc[i+1][j+1] = -acc[i][j] + acc[i+1][j] + acc[i][j+1] + D[i][j];
  }

  for (int r1 = 0; r1 < N; r1++) {
    for (int r2 = r1 + 1; r2 <= N; r2++) {
      for (int c1 = 0; c1 < N; c1++) {
        for (int c2 = c1 + 1; c2 <= N; c2++) {
          int p = (r2 - r1) * (c2 - c1);
          int cur = get(r1, c1, r2, c2);
          chmax(ans[p], cur);
        }
      }
    }
  }
  for (int i = 0; i < N*N; i++) {
    chmax(ans[i+1], ans[i]);
  }
  int Q = nextInt();
  while (Q-->0) {
    int P = nextInt();
    cout << ans[P] << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Submission Info

Submission Time
Task D - おいしいたこ焼きの焼き方
User hs484
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1579 Byte
Status AC
Exec Time 9 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int nextInt()’:
./Main.cpp:12:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 int nextInt() { int x; scanf("%d", &x); return x;}
                                       ^

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 4 ms 256 KB
rand1.txt AC 4 ms 256 KB
rand2.txt AC 6 ms 256 KB
rand3.txt AC 2 ms 256 KB
rand4.txt AC 1 ms 256 KB
rand_max0.txt AC 9 ms 256 KB
rand_max1.txt AC 9 ms 256 KB
rand_max2.txt AC 9 ms 256 KB
rand_max3.txt AC 9 ms 256 KB
rand_max4.txt AC 9 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
sub0.txt AC 1 ms 256 KB
sub1.txt AC 1 ms 256 KB
sub2.txt AC 1 ms 256 KB
sub_rand_max0.txt AC 1 ms 256 KB
sub_rand_max1.txt AC 1 ms 256 KB
sub_rand_max2.txt AC 1 ms 256 KB
sub_rand_max3.txt AC 1 ms 256 KB
sub_rand_min0.txt AC 1 ms 256 KB