結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー |
|
提出日時 | 2018-12-04 17:11:22 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 376 ms / 2,000 ms |
コード長 | 1,352 bytes |
コンパイル時間 | 721 ms |
コンパイル使用メモリ | 108,048 KB |
実行使用メモリ | 14,632 KB |
最終ジャッジ日時 | 2024-06-13 02:00:57 |
合計ジャッジ時間 | 7,400 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 TLE * 1 |
ソースコード
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;auto rdsp(){return readln.splitter;}void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}void readM(T)(size_t r,size_t c,ref T[][]t){t=new T[][](r);foreach(ref v;t)readA(c,v);}void main(){int n, m; readV(n, m);long[][] a; readM(m, m, a);auto ac = a.map!(ai => ai.cumulativeSum).array;foreach (_; 0..n) {int x, y; readV(x, y); --x; --y;auto ans = 0;foreach (l; 0..y+1)foreach (r; y..m) {auto b = ac.map!(aci => aci[l..r+1]).array;auto s = [0L: 1], sd = 0L;foreach (d; x+1..m) {sd += b[d];++s[-sd];}auto su = 0L;foreach_reverse (u; 0..x+1) {su += b[u];if (su in s) ans += s[su];}}writeln(ans);}}class CumulativeSum(T){size_t n;T[] s;this(T[] a){n = a.length;s = new T[](n+1);s[0] = T(0);foreach (i; 0..n) s[i+1] = s[i] + a[i];}T opSlice(size_t l, size_t r) { return s[r]-s[l]; }size_t opDollar() { return n; }}auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }