結果

問題 No.625 ソンタクロース
ユーザー ikdikd
提出日時 2018-01-05 02:13:06
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 67 ms / 4,000 ms
コード長 769 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 151,048 KB
実行使用メモリ 7,404 KB
最終ジャッジ日時 2023-09-03 17:52:37
合計ジャッジ時間 3,484 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 30 ms
6,376 KB
testcase_18 AC 67 ms
7,404 KB
testcase_19 AC 12 ms
4,548 KB
testcase_20 AC 13 ms
4,512 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 55 ms
7,396 KB
testcase_23 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

  int n, m; rd(n, m);

  auto as=[m];
  alias T=Tuple!(size_t, "i", int, "y");
  foreach(_; 0..(n-1)){
    T[] bs;
    foreach(i, a; as)  bs~=T(i, a+1);
    sort!((l, r)=>(l.y==r.y ? l.i>r.i : l.y<r.y))(bs);
    auto k=(bs.length+1)/2;
    auto nex=new int[](as.length);
    foreach(b; bs[0..k]) nex[b.i]=b.y;
    auto s=sum(nex);
    if(s<=m) as=(m-s)~nex;
    else as=(-1)~as;
  }

  writefln("%(%s %)", as);
}

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) write(e, " ");
  writeln();
}
0