結果

問題 No.1008 Bench Craftsman
ユーザー jelljell
提出日時 2020-03-15 23:12:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 1,998 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 153,820 KB
実行使用メモリ 5,032 KB
最終ジャッジ日時 2023-08-17 10:55:29
合計ジャッジ時間 6,535 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 175 ms
4,836 KB
testcase_06 AC 49 ms
4,392 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 133 ms
4,376 KB
testcase_10 AC 171 ms
4,896 KB
testcase_11 AC 170 ms
5,032 KB
testcase_12 AC 170 ms
4,840 KB
testcase_13 AC 162 ms
4,832 KB
testcase_14 AC 171 ms
4,984 KB
testcase_15 AC 171 ms
4,844 KB
testcase_16 AC 173 ms
4,852 KB
testcase_17 AC 171 ms
4,876 KB
testcase_18 AC 171 ms
4,904 KB
testcase_19 AC 177 ms
4,896 KB
testcase_20 AC 55 ms
4,376 KB
testcase_21 AC 62 ms
4,376 KB
testcase_22 AC 109 ms
4,380 KB
testcase_23 AC 129 ms
4,408 KB
testcase_24 AC 137 ms
4,380 KB
testcase_25 AC 52 ms
4,376 KB
testcase_26 AC 42 ms
4,380 KB
testcase_27 AC 92 ms
4,380 KB
testcase_28 AC 90 ms
4,380 KB
testcase_29 AC 141 ms
4,632 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:21:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   21 | main()
      | ^~~~

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <tuple>
#include <cassert>
#include <string>
using namespace std;

template <class T> void chmax(T &x, T y) {if(x<y) x=y;}
template <class T> void chmin(T &x, T y) {if(x>y) x=y;}



main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);

    int n,m; cin>>n>>m;
    vector<int> a(n);
    for(int &e:a) cin>>e;
    vector<pair<int,int>> h(m);
    for(auto &e:h)
    {
        int x,w; cin>>x>>w; --x;
        e={x,w};
    }

    // binary search
    long long ok=1e5+1;
    long long ng=0;
    while(ok-ng>1)
    {
        long long c=(ok+ng)/2;
        vector<long long> b(n+1);
        for(auto &e:h)
        {
            int x,w; tie(x,w)=e;
            const int l=max(0LL,x-w/c);
            const int r=x+w/c+1;
            b[l+1]+=c;
            b[x+1]-=c*2;
            if(r<=n) b[r]+=c;
        }
        for(int i=0;i<n;++i)
        {
            b[i+1]+=b[i];
        }
        for(auto &e:h)
        {
            int x,w; tie(x,w)=e;
            const int l=max(0LL,x-w/c);
            const int r=x+w/c+1;
            b[l]+=w-c*(x-l);
            if(r<=n) b[r]-=w%c;
        }
        for(int i=0;i<n;++i)
        {
            b[i+1]+=b[i];
        }
        bool fail=0;
        for(int i=0;i<n;++i)
        {
            if(b[i]>=a[i])
            {
                fail=1;
            }
        }
        if(fail)
        {
            ng=c;
        }
        else
        {
            ok=c;
        }
    }
    if(ng)
    {
        if(ok>1e5) cout << -1 << "\n";
        else cout << ok << "\n";
    }
    else
    {
        long long ws=0;
        for(auto &e:h)
        {
            ws+=e.second;
        }
        if(ws>=*min_element(begin(a),end(a)))
        {
            cout << 1 << "\n";
        }
        else
        {
            cout << 0 << "\n";
        }
    }
}
0