結果
問題 | No.761 平均値ゲーム |
ユーザー |
![]() |
提出日時 | 2018-12-09 03:26:16 |
言語 | D (dmd 2.109.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,004 bytes |
コンパイル時間 | 1,009 ms |
コンパイル使用メモリ | 128,008 KB |
実行使用メモリ | 6,952 KB |
最終ジャッジ日時 | 2024-06-13 02:06:38 |
合計ジャッジ時間 | 4,958 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 RE * 66 |
ソースコード
import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } int n; int[] as; int[] sums; // sums[i] は as[i -1] までの和 void main(){ n = read.to!int; as = readln.chomp.split.map!(to!int).array; sums = [0]; foreach(a; as) sums ~= sums[$ - 1] + a; solve(0, n - 1).writeln; } string solve(int l, int r){ // [l, r] int c = uplimit(l, r, (int i) => as[i] * (r + 1 - l) < sums[r + 1] - sums[l]); if(c < l) return "First"; else if(solve(l, c) == "Second") return "First"; else if(solve(c + 1, r) == "Second") return "First"; else return "Second"; } // fをみたす最大 int uplimit(int a, int c, bool delegate(int) f){ if(f(c)) return c; if(! f(a)) return a - 1; while(a + 1 < c){ int b = (a + c) / 2; if(f(b)) a = b; else c = b; } return a; }