結果
問題 | No.1008 Bench Craftsman |
ユーザー | どらら |
提出日時 | 2020-03-06 23:58:32 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 694 ms / 2,000 ms |
コード長 | 2,204 bytes |
コンパイル時間 | 1,752 ms |
コンパイル使用メモリ | 174,916 KB |
実行使用メモリ | 8,840 KB |
最終ジャッジ日時 | 2024-10-14 10:14:35 |
合計ジャッジ時間 | 12,906 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 694 ms
8,712 KB |
testcase_06 | AC | 141 ms
7,580 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 10 ms
6,816 KB |
testcase_09 | AC | 110 ms
6,816 KB |
testcase_10 | AC | 678 ms
8,716 KB |
testcase_11 | AC | 693 ms
8,708 KB |
testcase_12 | AC | 687 ms
8,716 KB |
testcase_13 | AC | 689 ms
8,708 KB |
testcase_14 | AC | 681 ms
8,708 KB |
testcase_15 | AC | 97 ms
7,024 KB |
testcase_16 | AC | 676 ms
8,840 KB |
testcase_17 | AC | 98 ms
7,028 KB |
testcase_18 | AC | 684 ms
8,740 KB |
testcase_19 | AC | 663 ms
8,708 KB |
testcase_20 | AC | 182 ms
6,816 KB |
testcase_21 | AC | 218 ms
6,816 KB |
testcase_22 | AC | 394 ms
6,816 KB |
testcase_23 | AC | 471 ms
7,096 KB |
testcase_24 | AC | 480 ms
6,820 KB |
testcase_25 | AC | 149 ms
6,996 KB |
testcase_26 | AC | 116 ms
6,816 KB |
testcase_27 | AC | 323 ms
6,816 KB |
testcase_28 | AC | 330 ms
6,828 KB |
testcase_29 | AC | 564 ms
7,772 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; bool check(ll c, const vector<ll>& v, const vector<pair<ll,ll>>& w){ if(c == -1) return false; vector<ll> base(v.size()+1, 0); vector<ll> imos(v.size()+1, 0); vector<ll> diff(v.size()+1, 0); rep(i,w.size()){ ll j = w[i].first; ll k = w[i].second; ll lhs_i, rhs_i; ll lhs_w, rhs_w; { ll lb = 0, ub = v.size(); while(ub-lb>1){ ll mid = (lb+ub)/2; if(j-mid<0) ub = mid; else{ if(k-c*mid<0) ub = mid; else lb = mid; } } lhs_i = j-lb; lhs_w = k-c*lb; } { ll lb = 0, ub = v.size(); while(ub-lb>1){ ll mid = (lb+ub)/2; if(j+mid>=v.size()) ub = mid; else{ if(k-c*mid<0) ub = mid; else lb = mid; } } rhs_i = j+lb; rhs_w = k-c*lb; } //cout << j << " " << k << " " << lhs_i << " " << lhs_w << " " << rhs_i << " " << rhs_w << endl; base[lhs_i] += lhs_w; imos[lhs_i] += c; imos[j] -= c; imos[j] -= c; imos[rhs_i] += c; base[rhs_i+1] -= rhs_w; } ll imos_base = 0; rep(i,imos.size()){ imos_base += imos[i]; diff[i] = imos_base; } bool flg = true; ll ww = 0; rep(i,v.size()){ ww += base[i]; //cout << i << "\t" << ww << endl; if(v[i]<=ww) flg = false; ww += diff[i]; } return flg; } int main(){ int N, M; cin >> N >> M; vector<ll> v; rep(i,N){ ll a; cin >> a; v.push_back(a); } vector<ll> sum(N,0); vector<pair<ll,ll>> w; rep(i,M){ ll a, b; cin >> a >> b; a--; sum[a] += b; w.emplace_back(a,b); } rep(i,N){ if(sum[i] >= v[i]){ cout << -1 << endl; return 0; } } ll lb=-1, ub=1e12; while(ub-lb>1){ ll mid = (lb+ub)/2; if(!check(mid, v, w)) lb = mid; else ub = mid; } cout << ub << endl; return 0; }