結果

問題 No.761 平均値ゲーム
ユーザー tnakao0123
提出日時 2018-12-16 19:32:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 84,988 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 06:36:00
合計ジャッジ時間 4,248 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:58:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   58 |     scanf("%lld", as + i);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 761.cc:  No.761 平均値ゲーム - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

ll as[MAX_N], sums[MAX_N + 1];

/* subroutines */

bool rec(int r0, int r1) {
  if (r0 >= r1) return false;
  int m = r1 - r0;
  ll ave = ceil((double)(sums[r1] - sums[r0]) / m);
  int k = lower_bound(as + r0, as + r1, ave) - (as + r0);
  if (k == 0 || k == m) return true;
  return (! rec(r0, r0 + k) || ! rec(r0 + k, r1));
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  sums[0] = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld", as + i);
    sums[i + 1] = sums[i] + as[i];
  }

  if (rec(0, n)) puts("First");
  else puts("Second");
  return 0;
}
0