結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー bal4ubal4u
提出日時 2019-09-07 14:06:39
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 32,512 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 00:45:56
合計ジャッジ時間 3,797 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 32 ms
6,944 KB
testcase_03 AC 61 ms
6,940 KB
testcase_04 AC 83 ms
6,940 KB
testcase_05 AC 83 ms
6,944 KB
testcase_06 AC 82 ms
6,940 KB
testcase_07 AC 83 ms
6,944 KB
testcase_08 AC 84 ms
6,944 KB
testcase_09 AC 81 ms
6,940 KB
testcase_10 AC 74 ms
6,940 KB
testcase_11 AC 78 ms
6,944 KB
testcase_12 AC 69 ms
6,940 KB
testcase_13 AC 76 ms
6,944 KB
testcase_14 AC 78 ms
6,944 KB
testcase_15 AC 71 ms
6,940 KB
testcase_16 AC 84 ms
6,944 KB
testcase_17 AC 82 ms
6,940 KB
testcase_18 AC 84 ms
6,944 KB
testcase_19 AC 85 ms
6,944 KB
testcase_20 AC 83 ms
6,944 KB
testcase_21 AC 83 ms
6,940 KB
testcase_22 AC 75 ms
6,944 KB
testcase_23 AC 79 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 14 ms
6,940 KB
testcase_29 AC 8 ms
6,940 KB
testcase_30 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:11:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
   11 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:24: note: in expansion of macro 'gc'
   17 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.67 よくある棒を切る問題 (1)
// bal4u 2019.9.7

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

ll inLL() {
	ll n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define EPS 1e-12
int N; ll K;
int L[200005];

inline static void chmax(ll *r, ll a) { if (*r < a) *r = a; }

ll cut(ll x) {
	int i; ll s = 0;
	for (i = 0; i < N; i++) s += L[i] / x;
	return s;
}

double fine(double l, double r) {
	int i, loop = 30; ll s; double m;
    while (loop--) {
      m = (l + r) / 2.0;
	  s = 0; for (i = 0; i < N; i++) s += (ll)((L[i]+EPS)/m + EPS);
	  if (s < K) r = m; else l = m;
    }
	return m;
}
	
int main()
{
	int i; ll l, r, m, ma;

	N = in(); 
	ma = 0; for (i = 0; i < N; i++) {
		L[i] = in(), chmax(&ma, L[i]);
	}
	K = inLL();
	l = 1; r = ma+1;
    while (l+1 < r) {
      m = (l + r) >> 1;
      if (cut(m) < K) r = m; else l = m;
    }
	if (cut(l) < K) r = l;
	printf("%.12lf\n", fine((double)r-1, (double)r));
	return 0;
}
0