結果

問題 No.755 Zero-Sum Rectangle
ユーザー heno239heno239
提出日時 2018-12-09 00:35:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,751 bytes
コンパイル時間 1,111 ms
コンパイル使用メモリ 110,796 KB
実行使用メモリ 7,968 KB
最終ジャッジ日時 2023-10-12 20:42:54
合計ジャッジ時間 6,589 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,968 KB
testcase_01 AC 109 ms
4,368 KB
testcase_02 AC 84 ms
4,368 KB
testcase_03 AC 121 ms
4,372 KB
testcase_04 AC 137 ms
4,368 KB
testcase_05 AC 149 ms
4,372 KB
testcase_06 AC 97 ms
4,368 KB
testcase_07 AC 89 ms
4,368 KB
testcase_08 AC 119 ms
4,368 KB
testcase_09 AC 137 ms
4,372 KB
testcase_10 AC 158 ms
4,372 KB
testcase_11 AC 2 ms
4,368 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
ll s[131][131];
ll a[130][130];
ll calc(int xmi,int ymi,int xma,int yma) {
	ll res = s[xma][yma];
	if (xmi > 0) {
		res -= s[xmi - 1][yma];
	}
	if (ymi > 0) {
		res -= s[xma][ymi - 1];
	}
	if (xmi > 0 && ymi > 0) {
		res += s[xmi - 1][ymi - 1];
	}
	return res;
}
int main() {
	int n, m; cin >> n >> m;
	rep(i, m) {
		rep(j, m) {
			cin >> a[i][j];
		}
	}
	rep(i, m) {
		rep(j,m) {
			s[i][j] = a[i][j];
			if (i > 0) {
				s[i][j] += s[i - 1][j];
			}
			if (j > 0) {
				s[i][j] += s[i][j - 1];
			}
			if (i > 0 && j > 0) {
				s[i][j] -= s[i - 1][j - 1];
			}
		}
	}
	rep(i, n) {
		int x, y; cin >> x >> y; x--; y--;
		int cnt = 0;
		Rep1(xmi, 0, x) {
			Rep1(ymi, 0, y) {
				Rep(xma, x, m) {
					Rep(yma, y, m) {
						if (!calc(xmi, ymi, xma, yma))cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}
0