結果
問題 | No.1008 Bench Craftsman |
ユーザー | koi_kotya |
提出日時 | 2020-03-06 23:16:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,368 bytes |
コンパイル時間 | 1,680 ms |
コンパイル使用メモリ | 172,560 KB |
実行使用メモリ | 8,588 KB |
最終ジャッジ日時 | 2024-10-14 09:46:36 |
合計ジャッジ時間 | 5,523 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 191 ms
8,464 KB |
testcase_06 | AC | 62 ms
7,296 KB |
testcase_07 | WA | - |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 34 ms
6,016 KB |
testcase_16 | AC | 183 ms
8,448 KB |
testcase_17 | AC | 34 ms
6,016 KB |
testcase_18 | WA | - |
testcase_19 | AC | 185 ms
8,336 KB |
testcase_20 | AC | 63 ms
5,912 KB |
testcase_21 | AC | 63 ms
5,632 KB |
testcase_22 | AC | 97 ms
5,508 KB |
testcase_23 | AC | 141 ms
6,912 KB |
testcase_24 | AC | 131 ms
6,272 KB |
testcase_25 | AC | 61 ms
6,680 KB |
testcase_26 | AC | 47 ms
6,016 KB |
testcase_27 | AC | 81 ms
5,248 KB |
testcase_28 | AC | 98 ms
6,864 KB |
testcase_29 | AC | 150 ms
7,464 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} int main() { int n,m; cin >> n >> m; vector<ll> a(n),w(m),sum(n,0); vector<int> x(m); for (int i = 0;i < n;++i) scanf("%lld",&a[i]); for (int i = 0;i < m;++i) scanf("%d%lld",&x[i],&w[i]),x[i]--; for (int i = 0;i < m;++i) sum[x[i]] += w[i]; for (int i = 0;i < n;++i) if (a[i] < sum[i]) { cout << -1 << endl; return 0; } ll s = 0; for (int i = 0;i < m;++i) s += w[i]; bool f = true; for (int i = 0;i < n;++i) if (a[i] < s) {f = false;break;} if (f) { cout << 0 << endl; return 0; } ll mn = 0,mx = 1e9; while (mx-mn > 1) { int mid = (mn+mx)/2; vector<ll> sum1(n,0),sum2(n,0),sum3(n,0); for (int i = 0;i < m;++i) { int c = w[i]/mid; sum1[max(0,x[i]-c)] += w[i]; if (x[i]+c+1 < n) sum1[x[i]+c+1] -= w[i]; if (x[i]+1 < n) sum2[x[i]+1] += mid; if (x[i]+1+c < n) sum2[x[i]+c+1] -= mid; if (x[i]-1 >= 0) sum3[x[i]-1] += mid; if (x[i]-1-c >= 0) sum3[x[i]-1-c] -= mid; } for (int i = 1;i < n;++i) sum1[i] += sum1[i-1]; for (int i = 1;i < n;++i) sum2[i] += sum2[i-1]; for (int i = n-1;i > 0;--i) sum3[i-1] += sum3[i]; for (int i = 0;i < m;++i) { int c = w[i]/mid; if (x[i]+1+c+1 < n) sum2[x[i]+c+2] -= (ll)c*mid; if (x[i]-c-2 >= 0) sum3[x[i]-c-2] -= (ll)c*mid; } for (int i = 1;i < n;++i) sum2[i] += sum2[i-1]; for (int i = n-1;i > 0;--i) sum3[i-1] += sum3[i]; bool ok = true; for (int i = 0;i < n;++i) if (sum1[i]-sum2[i]-sum3[i] > a[i]) { ok = false; break; } (ok ? mx : mn) = mid; } cout << mx << endl; }