結果

問題 No.607 開通777年記念
ユーザー ikdikd
提出日時 2017-12-07 01:42:47
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 87,964 KB
実行使用メモリ 24,924 KB
最終ジャッジ日時 2023-09-03 17:17:14
合計ジャッジ時間 1,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 21 ms
11,668 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 100 ms
24,904 KB
testcase_12 AC 96 ms
24,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.random;

  int n, m; rd(n, m);
  auto d=new int[][](m, n);
  foreach(i; 0..m) d[i]=readln.split.to!(int[]);

  writeln(solve(n, m, d)?"YES":"NO");
}

bool solve(int n, int m, int[][] d){
  auto a=new int[](n);
  int tg=777;
  foreach(i; 0..m){
    foreach(j; 0..n) a[j]+=d[i][j];
    auto sum=0, l=0, r=0;
    while(r<n){
      sum+=a[r++];
      while(l<r && sum>tg) sum-=a[l++];
      if(sum==tg) return true;
    }
  }
  return false;
}

bool greedy(int n, int m, int[][] d){
  import std.algorithm.iteration:sum;
  auto a=new int[](n);
  foreach(i; 0..m){
    foreach(j; 0..n) a[j]+=d[i][j];
    foreach(l; 0..n)foreach(r; l..n){
      auto s=sum(a[l..(r+1)]);
      if(s==777) return true;
    }
  }
  return false;
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) stderr.write(e, " ");
  stderr.writeln;
}
0