結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー horizon4096horizon4096
提出日時 2017-12-28 09:42:56
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 636 ms / 5,000 ms
コード長 994 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 71,268 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 12:35:12
合計ジャッジ時間 17,053 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%lld", &N);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:45:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |                 scanf("%lf", &L[i]);
      |                 ~~~~~^~~~~~~~~~~~~~
main.cpp:47:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |         scanf("%lld", &K);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

ll N, K;
double L[200000];

bool C(double x)
{
	ll i = 0;
	for (int j = 0; j < N; j++) {
		i += (int)(L[j] / x);
	}
	return i >= K;
}

int main(int argc, char* argv[])
{
	scanf("%lld", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lf", &L[i]);
	}
	scanf("%lld", &K);

	double l = 0, u = (double)linf;
	for (int i = 0; i < 2000; i++) {
		double mid = (l + u) / 2;
		if (C(mid)) l = mid;
		else u = mid;
	}
	printf("%.14f\n", l);

	return 0;
}
0