結果
問題 | No.1008 Bench Craftsman |
ユーザー | ゆきのん |
提出日時 | 2020-03-10 06:41:24 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 584 ms / 2,000 ms |
コード長 | 2,852 bytes |
コンパイル時間 | 1,800 ms |
コンパイル使用メモリ | 176,336 KB |
実行使用メモリ | 18,212 KB |
最終ジャッジ日時 | 2024-04-27 18:31:04 |
合計ジャッジ時間 | 10,176 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 584 ms
18,044 KB |
testcase_06 | AC | 231 ms
16,612 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 6 ms
6,944 KB |
testcase_09 | AC | 92 ms
6,940 KB |
testcase_10 | AC | 493 ms
18,048 KB |
testcase_11 | AC | 524 ms
18,048 KB |
testcase_12 | AC | 526 ms
18,212 KB |
testcase_13 | AC | 509 ms
18,048 KB |
testcase_14 | AC | 511 ms
18,048 KB |
testcase_15 | AC | 82 ms
6,940 KB |
testcase_16 | AC | 491 ms
18,092 KB |
testcase_17 | AC | 83 ms
6,940 KB |
testcase_18 | AC | 476 ms
18,128 KB |
testcase_19 | AC | 486 ms
18,048 KB |
testcase_20 | AC | 180 ms
11,648 KB |
testcase_21 | AC | 163 ms
10,180 KB |
testcase_22 | AC | 174 ms
8,192 KB |
testcase_23 | AC | 304 ms
12,996 KB |
testcase_24 | AC | 247 ms
11,136 KB |
testcase_25 | AC | 216 ms
14,684 KB |
testcase_26 | AC | 154 ms
11,928 KB |
testcase_27 | AC | 133 ms
6,940 KB |
testcase_28 | AC | 275 ms
13,528 KB |
testcase_29 | AC | 434 ms
15,632 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair<LL,LL> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;} const LL mod=1000000007; const LL LINF=1LL<<60; const int INF=1<<30; int dx[]={1,0,-1,0,1,-1,1,-1}; int dy[]={0,1,0,-1,1,-1,-1,1}; int main(){ int n,m;cin >> n >> m; vector<LL> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<LL> x(m), w(m); bool fl = true; vector<LL> p(n, 0); for (int i = 0; i < m; i++) { cin >> x[i] >> w[i]; x[i]--; p[x[i]] += w[i]; } for (int i = 0; i < n; i++) { if(a[i] <= p[i]) fl = false; } if(not fl){ puts("-1"); } else if(*min_element(ALL(a)) > accumulate(ALL(w),0LL)){ puts("0"); } else{ LL l = 0,r = *max_element(ALL(w)); while(abs(r - l) > 1){ LL c = (r + l) / 2; vector<vector<LL>> imosr(n+1,vector<LL> (3,0)); vector<vector<LL>> imosl(n+1,vector<LL> (3,0)); vector<LL> v(n, 0); for (int i = 0; i < m; i++) { LL k = w[i] / c; imosr[x[i]+1][2] += w[i]; imosr[x[i]+1][0] -= c; if(x[i] + k + 1<= n){ imosr[x[i]+k+1][0] += c; imosr[x[i]+k+1][2] -= w[i]%c; } if(x[i] - 1 >= 0){ imosl[x[i]-1][0] -= c; imosl[x[i]-1][2] += w[i]; } if(x[i] - k - 1 >= 0){ imosl[x[i]-k-1][0] += c; imosl[x[i]-k-1][2] -= w[i]%c; } v[x[i]] += w[i]; } for (int i = 0; i < n; i++) { for (int j = 1; j < 3; j++) { imosr[i][j] += imosr[i][j-1]; if(i) imosr[i][j] += imosr[i-1][j]; } } for (int i = n-1; i >= 0; i--) { for (int j = 1; j < 3; j++) { imosl[i][j] += imosl[i][j-1]; imosl[i][j] += imosl[i+1][j]; } } for (int i = 0; i < n; i++) { v[i] += imosr[i][2] + imosl[i][2]; } bool f = true; for (int i = 0; i < n; i++) { if(a[i] <= v[i]) f = false; } if(f) r = c; else l = c; } cout << r << endl; } return 0; }