結果

問題 No.1008 Bench Craftsman
ユーザー jelljell
提出日時 2020-03-15 23:06:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,996 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 154,340 KB
実行使用メモリ 5,128 KB
最終ジャッジ日時 2023-08-17 10:26:37
合計ジャッジ時間 6,864 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 175 ms
4,884 KB
testcase_06 AC 50 ms
4,420 KB
testcase_07 WA -
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 134 ms
4,380 KB
testcase_10 AC 173 ms
4,860 KB
testcase_11 AC 171 ms
4,844 KB
testcase_12 AC 172 ms
4,884 KB
testcase_13 AC 164 ms
4,952 KB
testcase_14 AC 173 ms
4,956 KB
testcase_15 AC 173 ms
4,904 KB
testcase_16 AC 174 ms
4,836 KB
testcase_17 AC 174 ms
4,840 KB
testcase_18 WA -
testcase_19 AC 172 ms
5,128 KB
testcase_20 AC 56 ms
4,376 KB
testcase_21 AC 63 ms
4,380 KB
testcase_22 AC 110 ms
4,380 KB
testcase_23 AC 129 ms
4,436 KB
testcase_24 AC 137 ms
4,432 KB
testcase_25 AC 53 ms
4,380 KB
testcase_26 AC 43 ms
4,380 KB
testcase_27 AC 93 ms
4,376 KB
testcase_28 AC 91 ms
4,396 KB
testcase_29 AC 142 ms
4,748 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