結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | Ashurnasirpal |
提出日時 | 2018-02-06 21:30:06 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,846 bytes |
コンパイル時間 | 1,721 ms |
コンパイル使用メモリ | 174,568 KB |
実行使用メモリ | 29,528 KB |
最終ジャッジ日時 | 2024-07-19 07:00:05 |
合計ジャッジ時間 | 10,466 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 217 ms
15,316 KB |
testcase_18 | AC | 28 ms
5,376 KB |
testcase_19 | WA | - |
testcase_20 | AC | 90 ms
9,176 KB |
testcase_21 | AC | 302 ms
19,924 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 33 ms
5,376 KB |
testcase_32 | AC | 38 ms
5,460 KB |
testcase_33 | WA | - |
testcase_34 | AC | 339 ms
19,668 KB |
testcase_35 | WA | - |
testcase_36 | AC | 335 ms
20,820 KB |
testcase_37 | WA | - |
testcase_38 | AC | 334 ms
19,408 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll>; const ll inf = numeric_limits<ll>::max()/3; int n; ll k; vector< P > tasks; ll tree[1000000]; void init(int k,int l,int r){ if(r - l == 1){ tree[k] = -inf; // init leaf }else{ int chl = k*2+1; int chr = k*2+2; tree[k] = -inf; // init internal-node init(chl, l, (l+r)/2); init(chr, (l+r)/2, r); } } void update(int i,int x,int k,int l, int r){ if(l <= i && i < r){ if(r - l == 1){ tree[k] = x; }else{ int chl = k*2+1; int chr = k*2+2; update(i,x,chl,l,(l+r)/2); update(i,x,chr,(l+r)/2,r); tree[k] = max(tree[chl],tree[chr]); } } } ll find(int a,int b,int k,int l,int r){ // not cross if(r <= a || b <= l)return -inf; // [a,b) contain [l,r) else if(a <= l && r <= b)return tree[k]; // otherwise else{ int chl = k*2+1; int chr = k*2+2; ll vl = find(a,b,chl,l,(l+r)/2); ll vr = find(a,b,chr,(l+r)/2,r); return max(vl,vr); } } bool detect(ll m){ ll last = -inf; for(int i = 0;i < n;++i){ if(tasks[i].second > m){ if(tasks[i].first - last < k) return false; last = tasks[i].first; } } return true; } int main(void){ cin >> n >> k; tasks.clear(); // find dmax (by bsearch) ll tot = 0; set< ll > diff_set; vector< ll > diff_vec; diff_set.insert(0LL); for(int i = 0;i < n;++i){ ll t,d; cin >> t >> d; tasks.push_back(P(t,d)); diff_set.insert(d); tot += d; } for(auto d : diff_set){ diff_vec.push_back(d); } sort(diff_vec.begin(),diff_vec.end()); int l = -1,r = (int)diff_vec.size()-1; while(r - l > 1){ int mid = (l+r)/2; //cout << diff_vec[mid] << " " << detect(diff_vec[mid]) << endl; if(detect(diff_vec[mid])) r = mid; else l = mid; } ll dmax = diff_vec[r]; // remove unavalilable tasks vector< ll > used; used.push_back(-inf); for(int i = 0;i < n;++i){ if(tasks[i].second > dmax){ used.push_back(tasks[i].first); tot -= tasks[i].second; } } used.push_back(inf); vector< P > tasks2; int j = 1; for(int i = 0;i < n;++i){ while(used[j] < tasks[i].first) ++j; if(used[j-1] + k <= tasks[i].first && tasks[i].first <= used[j] - k){ tasks2.push_back(tasks[i]); } } // find optimal sum int size = (int)tasks2.size(); init(0,0,size+1); vector< ll > tms; tms.push_back(0); update(0,0,0,0,size+1); for(int i = 0;i < size;++i){ int j = (upper_bound(tms.begin(), tms.end(), tasks2[i].first - 1) - tms.begin()); ll calc = find(0,j,0,0,size+1); update(i+1,calc+tasks2[i].second,0,0,size+1); tms.push_back(tasks2[i].first + k); } cout << dmax << endl; cout << tot - find(0,size+1,0,0,size+1) << endl; return 0; }