結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー | kriii |
提出日時 | 2018-12-09 01:29:26 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 904 bytes |
コンパイル時間 | 384 ms |
コンパイル使用メモリ | 47,508 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-13 09:53:16 |
合計ジャッジ時間 | 1,958 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 16 ms
4,352 KB |
testcase_02 | AC | 65 ms
4,348 KB |
testcase_03 | AC | 63 ms
4,348 KB |
testcase_04 | AC | 59 ms
4,348 KB |
testcase_05 | AC | 53 ms
4,348 KB |
testcase_06 | AC | 48 ms
4,348 KB |
testcase_07 | AC | 47 ms
4,348 KB |
testcase_08 | AC | 46 ms
4,348 KB |
testcase_09 | AC | 49 ms
4,352 KB |
testcase_10 | AC | 46 ms
4,348 KB |
testcase_11 | AC | 1 ms
4,352 KB |
evil_1 | AC | 65 ms
4,352 KB |
ソースコード
#include <stdio.h> #include <algorithm> using namespace std; int N,M; long long A[133][133],U[133][133]; int main() { scanf ("%d %d",&N,&M); for (int i=1;i<=M;i++){ for (int j=1;j<=M;j++){ scanf ("%lld",&A[i][j]); A[i][j] += A[i-1][j] + A[i][j-1] - A[i-1][j-1]; } } for (int i1=1;i1<=M;i1++) for (int i2=i1;i2<=M;i2++){ pair<long long, int> X[133]; X[0] = {0,1}; for (int j=1;j<=M;j++) X[j] = {A[i2][j] - A[i1-1][j], j+1}; sort(X,X+M+1); for (int j=0;j<=M;){ int k = j; while (k <= M && X[j].first == X[k].first) k++; for (int l=j;l<k;l++){ int d = (k - l - 1) - (l - j); int r = X[l].second; U[i1][r] += d; U[i2+1][r] -= d; } j = k; } } for (int i=1;i<=M;i++){ for (int j=1;j<=M;j++){ U[i][j] += U[i-1][j] + U[i][j-1] - U[i-1][j-1]; } } while (N--){ int x,y; scanf ("%d %d",&x,&y); printf ("%lld\n",U[x][y]); } return 0; }