結果

問題 No.755 Zero-Sum Rectangle
ユーザー nanaenanae
提出日時 2018-12-03 00:30:35
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 2,041 bytes
コンパイル時間 1,233 ms
コンパイル使用メモリ 99,848 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 21:18:06
合計ジャッジ時間 3,229 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 398 ms
4,380 KB
testcase_02 AC 151 ms
4,384 KB
testcase_03 AC 138 ms
4,380 KB
testcase_04 AC 130 ms
4,380 KB
testcase_05 AC 122 ms
4,384 KB
testcase_06 AC 121 ms
4,384 KB
testcase_07 AC 119 ms
4,380 KB
testcase_08 AC 120 ms
4,384 KB
testcase_09 AC 119 ms
4,384 KB
testcase_10 AC 120 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
evil_1 AC 153 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    }

    auto cnt = new long[][](m + 1, m + 1);

    foreach (i ; 0 .. m) {
        foreach (j ; i + 1 .. m + 1) {
            foreach (k ; 0 .. m) {
                foreach (l ; k + 1 .. m + 1) {
                    long wa = ac[j][l] - ac[i][l] - ac[j][k] + ac[i][k];
                    if (wa == 0) {
                        cnt[i][k]++;
                        cnt[j][k]--;
                        cnt[i][l]--;
                        cnt[j][l]++;
                    }
                }
            }
        }
    }

    foreach (i ; 0 .. m + 1) {
        foreach (j ; 0 .. m + 1) {
            cnt[i][j] += (i > 0 ? cnt[i-1][j] : 0)
                         + (j > 0 ? cnt[i][j-1] : 0)
                         - (i > 0 && j > 0 ? cnt[i-1][j-1] : 0);
        }
    }

    foreach (i ; 0 .. n) {
        int x = q[i][0];
        int y = q[i][1];
        x--, y--;

        writeln(cnt[x][y]);
    }
}























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