結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー codershifthcodershifth
提出日時 2015-07-29 14:03:38
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,627 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 146,452 KB
実行使用メモリ 10,820 KB
最終ジャッジ日時 2023-09-24 21:41:55
合計ジャッジ時間 10,487 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
10,820 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class CuttingStick1 {
public:
    void solve(void) {
            int N;
            cin>>N;
            vector<double> L(N);
            REP(i,N)
                cin>>L[i];
            ll K;
            cin>>K;
            // ある長さ D の棒を K 本つくれるならそれ以下の長さの棒も作れる
            // よって二分探索すればよい

            double high = 1E+9;
            double low  = 0;

            REP(i, 100)
            {
                if (abs(high-low) < 1e-9)
                    break;
                double mid = (high+low)*0.5;
                auto tmp = L;

                ll     k = 0;
                size_t j = 0;
                while (j < tmp.size())
                {
                    if (k == K)
                        break;
                    if (tmp[j] < mid)
                        ++j;
                    else if (tmp[j] >= mid)
                    {
                        tmp[j] -= mid;
                        ++k;
                    }
                }
                if (k == K)
                    low = mid;
                else
                    high = mid;
            }
            cout<<setprecision(20)<<low<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new CuttingStick1();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0