結果
| 問題 |
No.755 Zero-Sum Rectangle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-31 22:37:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 610 ms / 2,000 ms |
| コード長 | 607 bytes |
| コンパイル時間 | 2,472 ms |
| コンパイル使用メモリ | 198,904 KB |
| 最終ジャッジ日時 | 2025-01-10 20:11:42 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 TLE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | int q,n; scanf("%d%d",&q,&n);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:11:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | rep(i,n) rep(j,n) scanf("%d",&a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:17:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | int y0,x0; scanf("%d%d",&y0,&x0); y0--; x0--;
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
int q,n; scanf("%d%d",&q,&n);
int a[130][130];
rep(i,n) rep(j,n) scanf("%d",&a[i][j]);
lint sum[131][131]={};
rep(i,n) rep(j,n) sum[i+1][j+1]=sum[i+1][j]+sum[i][j+1]-sum[i][j]+a[i][j];
rep(_,q){
int y0,x0; scanf("%d%d",&y0,&x0); y0--; x0--;
lint ans=0;
map<lint,int> f;
rep(i,y0+1) for(int j=y0+1;j<=n;j++) {
f.clear();
rep(k,n+1){
lint b=sum[j][k]-sum[i][k];
if(k<=x0) ++f[b];
else ans+=f[b];
}
}
printf("%lld\n",ans);
}
return 0;
}