結果
問題 | No.1008 Bench Craftsman |
ユーザー | ngtkana |
提出日時 | 2020-04-09 10:12:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 1,705 bytes |
コンパイル時間 | 2,196 ms |
コンパイル使用メモリ | 206,608 KB |
実行使用メモリ | 9,388 KB |
最終ジャッジ日時 | 2023-09-28 21:59:08 |
合計ジャッジ時間 | 5,763 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 114 ms
9,132 KB |
testcase_06 | AC | 39 ms
7,948 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 20 ms
6,336 KB |
testcase_09 | AC | 80 ms
7,968 KB |
testcase_10 | AC | 108 ms
9,280 KB |
testcase_11 | AC | 108 ms
9,144 KB |
testcase_12 | AC | 109 ms
9,104 KB |
testcase_13 | AC | 107 ms
9,204 KB |
testcase_14 | AC | 108 ms
9,216 KB |
testcase_15 | AC | 104 ms
9,288 KB |
testcase_16 | AC | 107 ms
9,128 KB |
testcase_17 | AC | 105 ms
9,196 KB |
testcase_18 | AC | 108 ms
9,388 KB |
testcase_19 | AC | 109 ms
9,320 KB |
testcase_20 | AC | 44 ms
7,360 KB |
testcase_21 | AC | 47 ms
7,392 KB |
testcase_22 | AC | 74 ms
7,816 KB |
testcase_23 | AC | 87 ms
8,420 KB |
testcase_24 | AC | 86 ms
8,548 KB |
testcase_25 | AC | 39 ms
7,736 KB |
testcase_26 | AC | 34 ms
7,408 KB |
testcase_27 | AC | 63 ms
7,580 KB |
testcase_28 | AC | 62 ms
8,152 KB |
testcase_29 | AC | 92 ms
8,708 KB |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using ld=long double; void cmx(lint&x,lint y){if(x<y)x=y;} #define ENABLE_DEBUG 1 #ifdef NGTKANA #include<debug.hpp> #else #define DEBUG(...)(void)0 #endif int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n,m;std::cin>>n>>m; std::vector<lint>a(n); for(lint&x:a)std::cin>>x; std::vector<std::pair<lint,lint>>xw(m); for(auto&&[x,w]:xw){ std::cin>>x>>w;x--; } lint inf=std::numeric_limits<lint>::max(); { lint wmax=0; for(auto&&[x,w]:xw)cmx(wmax,w); for(auto&&[x,w]:xw)x+=wmax; std::vector<lint>swp(n+2*wmax,inf); std::copy(ALL(a),swp.begin()+wmax); n+=2*wmax; swp.swap(a); } auto ok=[&](lint c){ if(c==0){ lint sum=0; for(auto&&[x,w]:xw)sum+=w; return std::all_of(ALL(a),[sum](lint x){return sum<=x;}); } std::vector<lint>b(n+1); for(auto&&[x,w]:xw){ lint q=w/c; b.at(x-q+1)+=c; b.at(x+1)-=2*c; b.at(x+q+1)+=c; } std::partial_sum(ALL(b),b.begin()); for(auto&&[x,w]:xw){ lint q=w/c,r=w%c; b.at(x-q)+=r; b.at(x+q+1)-=r; } std::partial_sum(ALL(b),b.begin()); for(lint i=0;i<n;i++){ if(a.at(i)<=b.at(i))return false; } return true; }; lint imp=1'000'000; lint l=-1,r=imp; while(1<r-l){ lint c=(l+r)/2; (ok(c)?r:l)=c; } std::cout<<(r==imp?-1:r)<<'\n'; }