結果

問題 No.761 平均値ゲーム
ユーザー te-sh
提出日時 2018-12-10 11:53:27
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 105,368 KB
実行使用メモリ 7,156 KB
最終ジャッジ日時 2024-06-13 02:09:34
合計ジャッジ時間 4,982 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

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 main()
{
  int n; readV(n);
  long[] a; readA(n, a);

  auto as = a.assumeSorted, ac = a.cumulativeSum;

  bool calc(int l, int r)
  {
    if (a[l] == a[r-1]) return true;

    auto b = (ac[l..r]+(r-l)-1)/(r-l);
    auto i = as.lowerBound(b).length.to!int;

    auto c1 = calc(l, i), c2 = calc(i, r);
    return !c1 || !c2;
  }

  writeln(calc(0, n) ? "First" : "Second");
}

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