結果

問題 No.755 Zero-Sum Rectangle
ユーザー te-shte-sh
提出日時 2018-12-04 17:11:22
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 1,352 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 96,984 KB
実行使用メモリ 15,032 KB
最終ジャッジ日時 2023-09-03 21:22:26
合計ジャッジ時間 7,261 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,060 KB
testcase_01 AC 153 ms
4,376 KB
testcase_02 AC 220 ms
4,380 KB
testcase_03 AC 314 ms
4,380 KB
testcase_04 AC 344 ms
4,380 KB
testcase_05 AC 347 ms
5,928 KB
testcase_06 AC 288 ms
6,716 KB
testcase_07 AC 262 ms
6,188 KB
testcase_08 AC 279 ms
6,376 KB
testcase_09 AC 374 ms
15,032 KB
testcase_10 AC 337 ms
14,940 KB
testcase_11 AC 1 ms
4,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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