結果

問題 No.755 Zero-Sum Rectangle
ユーザー nanae
提出日時 2018-12-03 00:18:34
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 1,043 ms / 2,000 ms
コード長 1,904 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 110,720 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-06-13 01:57:21
合計ジャッジ時間 13,141 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
void main() {
int n, m;
scan(n, m);
auto a = iota(m).map!(i => readln.split.to!(int[])).array;
auto q = iota(n).map!(i => readln.split.to!(int[])).array;
auto ac = new long[][](m + 1, m + 1);
foreach (i ; 1 .. m + 1) {
foreach (j ; 1 .. m + 1) {
ac[i][j] = ac[i-1][j] + ac[i][j-1] - ac[i-1][j-1] + a[i-1][j-1];
}
}
debug {
writefln("%(%s\n%)", ac);
}
long solve(int x, int y) {
long ans;
foreach (i ; 0 .. x + 1) {
foreach (j ; x + 1 .. m + 1) {
foreach (k ; 0 .. y + 1) {
foreach (l ; y + 1 .. m + 1) {
long wa;
wa += ac[j][l];
wa -= ac[i][l];
wa -= ac[j][k];
wa += ac[i][k];
if (wa == 0) {
ans++;
}
}
}
}
}
return ans;
}
foreach (i ; 0 .. n) {
int x = q[i][0];
int y = q[i][1];
x--, y--;
long ans = solve(x, y);
writeln(ans);
}
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1