結果

問題 No.755 Zero-Sum Rectangle
ユーザー sigma425sigma425
提出日時 2018-12-20 03:31:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 167,928 KB
実行使用メモリ 113,216 KB
最終ジャッジ日時 2023-10-26 00:19:50
合計ジャッジ時間 9,188 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
113,216 KB
testcase_01 AC 57 ms
109,116 KB
testcase_02 AC 262 ms
109,124 KB
testcase_03 AC 362 ms
109,124 KB
testcase_04 AC 471 ms
109,124 KB
testcase_05 AC 487 ms
109,124 KB
testcase_06 AC 468 ms
109,124 KB
testcase_07 AC 379 ms
109,124 KB
testcase_08 AC 543 ms
109,124 KB
testcase_09 AC 475 ms
109,124 KB
testcase_10 AC 547 ms
109,124 KB
testcase_11 AC 39 ms
108,876 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	}
}
0