結果
| 問題 | No.68 よくある棒を切る問題 (2) | 
| コンテスト | |
| ユーザー |  myanta | 
| 提出日時 | 2017-05-11 22:23:22 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,203 bytes | 
| コンパイル時間 | 534 ms | 
| コンパイル使用メモリ | 58,240 KB | 
| 実行使用メモリ | 9,856 KB | 
| 最終ジャッジ日時 | 2024-09-15 08:07:43 | 
| 合計ジャッジ時間 | 13,406 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | TLE * 1 -- * 9 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:76:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   76 |                         scanf("%d", <);
      |                         ~~~~~^~~~~~~~~~~
main.cpp:82:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |                 scanf("%d", &q);
      |                 ~~~~~^~~~~~~~~~
main.cpp:85:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   85 |                         scanf("%d", &k);
      |                         ~~~~~^~~~~~~~~~
            
            ソースコード
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<utility>
using namespace std;
using ld=long double;
map<int,ld,greater<int> > m;
vector<ld> l;
ld l_max;
ld solve(int k)
{
	int ksum;
	ld s, e, c, ans;
	int n=l.size(), i, j;
	s=l_max/k;
	e=l_max;
	auto it=m.upper_bound(k);
	if(it!=m.end())
	{
		e=it->second;
		--it;
		if(it!=m.begin()) s=max(it->second, s);
	}
//printf("k=%d  s=%Lf e=%Lf\n", k, s, e);
	ans=s;
	for(i=0;i<100;i++)
	{
		if(e-s<1e-20) break;
		c=(s+e)*0.5;
		ksum=0;
		for(j=0;j<n;j++)
		{
			ksum+=l[j]/c;
		}
//		if(m.find(ksum)==m.end()) m[ksum]=c;
//		else m[ksum]=max(m[ksum], c);
		m[ksum]=max(m[ksum], c);
		if(ksum>=k)
		{
			ans=c;
			s=c;
		}
		else
		{
			e=c;
		}
	}
	return ans;
}
int main(void)
{
	int n, q, k, i;
	ld ans;
	while(scanf("%d", &n)==1)
	{
		m.clear();
		l.resize(n);
		l_max=0.0;
		for(i=0;i<n;i++)
		{
			int lt;
			scanf("%d", <);
			l[i]=lt;
			if(l_max<lt) l_max=lt;
		}
		m[0]=l_max;
		m[500000]=l_max/500000;
		scanf("%d", &q);
		for(i=0;i<q;i++)
		{
			scanf("%d", &k);
			ans=solve(k);
			printf("%.12Lf\n", ans);
		}
/*
for(auto me: m)
{
	printf("k=%d  c=%Lf\n", me.first, me.second);
}
*/
	}
	return 0;
}
            
            
            
        