結果
| 問題 |
No.68 よくある棒を切る問題 (2)
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2014-11-18 00:04:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,969 bytes |
| コンパイル時間 | 949 ms |
| コンパイル使用メモリ | 79,136 KB |
| 実行使用メモリ | 20,048 KB |
| 最終ジャッジ日時 | 2025-01-02 17:00:51 |
| 合計ジャッジ時間 | 68,152 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 10 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <memory.h>
using namespace std;
typedef signed long long ll;
int pred(pair<int, ll> first, pair<int, ll> second)
{
return first.second < second.second;
}
int main()
{
ll n;
cin >> n;
vector<ll> values(n);
for(int i = 0; i < n;i++)
{
cin >> values[i];
}
int q;
cin >> q;
vector<pair<int, ll>> length(q);
vector<double> results(q);
for(int i = 0; i < q;i++)
{
ll value;
cin >> value;
length[i] = make_pair(i, value);
}
sort(length.begin(), length.end(), pred);
double totalMin = 0;
double totalMax = 1e9;
int left = 0;
int right = q-1;
while(true)
{
{
double minValue = totalMin;
double maxValue = totalMax;
double threshold = length[left].second;
while(maxValue - minValue > 1e-10)
{
double mid = (minValue + maxValue)/2.0;
ll sum = 0;
for (int i = 0; i < n; i++)
{
sum += (ll)(values[i]/mid);
}
if (sum >= threshold)
{
minValue = mid;
}
else
{
maxValue = mid;
}
}
results[length[left].first] = minValue;
totalMax = min(totalMax, minValue);
if(left >= right)
{
break;
}
left++;
}
{
double minValue = totalMin;
double maxValue = totalMax;
double threshold = length[right].second;
while(maxValue - minValue > 1e-10)
{
double mid = (minValue + maxValue)/2.0;
ll sum = 0;
for (int i = 0; i < n; i++)
{
sum += (ll)(values[i]/mid);
}
if (sum >= threshold)
{
minValue = mid;
}
else
{
maxValue = mid;
}
}
results[length[right].first] = minValue;
totalMin = max(totalMin, minValue);
if(left >= right)
{
break;
}
right--;
}
}
for(int m = 0;m < q;m++)
{
printf("%.15f\n", results[m]);
}
}
nanophoto12