結果

問題 No.91 赤、緑、青の石
ユーザー tnakao0123
提出日時 2016-03-12 18:35:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 988 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 86,084 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 06:56:07
合計ジャッジ時間 1,749 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 91.cc: No.91 赤、緑、青の石 - 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 */

/* typedef */

/* global variables */

/* subroutines */

bool ok(int m, int c1, int c2) { // c1 <= c2
  if (c1 >= m)
    return ((c1 - m) / 2 + (c2 - m) / 2 >= m);
  return (c2 - m) / 2 >= 2 * m - c1;
}

/* main */

int main() {
  int cs[3];
  for (int i = 0; i < 3; i++) cin >> cs[i];
  sort(cs, cs + 3);

  int c1 = cs[1] - cs[0], c2 = cs[2] - cs[0];
  //printf("%d %d\n", c1, c2);

  int m0 = 0, m1 = c2;
  while (m0 + 1 < m1) {
    int m = (m0 + m1) / 2;
    if (ok(m, c1, c2)) m0 = m;
    else m1 = m;
  }

  printf("%d\n", m0 + cs[0]);
  return 0;
}
0