結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー |
![]() |
提出日時 | 2018-12-20 03:31:17 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 586 ms / 2,000 ms |
コード長 | 1,207 bytes |
コンパイル時間 | 2,133 ms |
コンパイル使用メモリ | 167,120 KB |
実行使用メモリ | 115,760 KB |
最終ジャッジ日時 | 2024-09-25 08:19:43 |
合計ジャッジ時間 | 9,500 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 TLE * 1 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(int)(n);i++)#define rep1(i,n) for(int i=1;i<=(int)(n);i++)#define all(c) c.begin(),c.end()#define pb push_back#define fs first#define sc second#define show(x) cout << #x << " = " << (x) << endl#define chmin(x,y) x=min(x,y)#define chmax(x,y) x=max(x,y)using namespace std;template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"{";for(const T& v:vc) o<<v<<",";o<<"}";return o;}using ll = long long;template<class T> using V = vector<T>;template<class T> using VV = vector<vector<T>>;int Q,N;ll a[131][131];ll s[131][131];map<ll,int> cnt[131][131][131];int main(){cin>>Q>>N;rep(i,N) rep(j,N) cin>>a[i][j];rep(i,N) rep(j,N) s[i+1][j+1] = a[i][j];rep(i,N+1) rep(j,N) s[i][j+1] += s[i][j];rep(i,N) rep(j,N+1) s[i+1][j] += s[i][j];rep(_,Q){int x,y;cin>>x>>y;x--,y--;int res = 0;rep(i,x+1) for(int ri=x+1;ri<=N;ri++){map<ll,int> cnt;rep(j,N+1){ll v = s[ri][j] - s[i][j];if(j<=y) cnt[v]++;else res += cnt[v];}}cout<<res<<endl;}}