結果
問題 | No.1715 Dinner 2 |
ユーザー | hari64 |
提出日時 | 2021-10-22 23:48:00 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,995 bytes |
コンパイル時間 | 1,713 ms |
コンパイル使用メモリ | 178,680 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 07:02:11 |
合計ジャッジ時間 | 2,811 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | WA | - |
testcase_11 | AC | 7 ms
6,940 KB |
testcase_12 | AC | 9 ms
6,940 KB |
testcase_13 | AC | 10 ms
6,940 KB |
testcase_14 | AC | 8 ms
6,944 KB |
testcase_15 | AC | 9 ms
6,940 KB |
testcase_16 | AC | 6 ms
6,944 KB |
testcase_17 | AC | 4 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 11 ms
6,940 KB |
testcase_33 | AC | 11 ms
6,940 KB |
testcase_34 | AC | 11 ms
6,940 KB |
testcase_35 | AC | 10 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; // clang-format off namespace viewer {template<class T>string f(T i){string s=(i==1001001001||i==1001001001001001001?"inf":to_string(i));s=string(max(0,3-(int)s.size()),' ')+s;return s;} void view(const char c,string end="\n"){cerr<<c<<end;} void view(const string&s,string end="\n"){cerr<<s<<end;} template<class T>void view(const T&x,string end="\n"){cerr<<f(x)<<end;} template<class T0,class T1>void view(const pair<T0,T1>&p,string end="\n"){cerr<<"("<<f(get<0>(p))<<", "<<f(get<1>(p))<<")"<<end;} template<class T0,class T1>void view(const tuple<T0,T1>&p,string end="\n"){cerr<<"("<<f(get<0>(p))<<", "<<f(get<1>(p))<<")"<<end;} template<class T0,class T1,class T2>void view(const tuple<T0,T1,T2>&t,string end="\n"){cerr<<"("<<f(get<0>(t))<<", "<<f(get<1>(t));cerr<<", "<<f(get<2>(t))<<")"<<end;} template<class T0,class T1,class T2,class T3>void view(const tuple<T0,T1,T2,T3>&t,string end="\n"){cerr<<"("<<f(get<0>(t))<<", "<<f(get<1>(t))<<", "<<f(get<2>(t))<<", "<<f(get<3>(t))<<")"<<end;} template<class T>void view(const vector<T>&vx,string _end=""){bool is_value=is_integral<T>();cerr<<"{"<<(vx.empty()||is_value?"":"\n");for(const T&x:vx){if(!is_value)cerr<<" ";view(x,(is_value?",":"\n"));};cerr<<"}\n"<<_end;} template<class T>void view(const set<T>&s){vector<T>v(s.begin(),s.end());view(v);} template<class T>void view(const multiset<T>&s){vector<T>v(s.begin(),s.end());view(v);} template<class T>void view(const unordered_set<T>&s){vector<T>v(s.begin(),s.end());view(v);} template<class T>void view(const deque<T>&s){vector<T>v(s.begin(),s.end());view(v);} template<class T>void view(const priority_queue<T>&p){priority_queue<T>q=p;vector<T>v;while(!q.empty()){v.push_back(q.top());q.pop();}view(v);} template<class T,class U>void view(const map<T, U>&m){cerr<<"{"<<(m.empty()?"":"\n");for(const auto&kv:m){cerr<<" [";view(kv.first,"");cerr<<"] : ";view(kv.second,"");cerr<<"\n";}cerr<<"}\n";} template<class T>void _view(const T&var,string var_name,int line_num){cerr<<line_num<<": "<<var_name<<" = ";view(var);} void view_grid(const vector<vector<bool>>&vvb){cerr<<"\n";for(const vector<bool>&vb:vvb){for(const bool&b:vb)cerr<<(b?".":"#");cerr<<"\n";}}} //グリッド用 "."と"#"は交換可 // clang-format on #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) #define debug(var) viewer::_view(var, #var, __LINE__) // constexpr int INF = 1001001001; constexpr long long INF = 1001001001001001001; int main() { cin.tie(0); ios::sync_with_stdio(false); long long N; cin >> N; long long D; cin >> D; vector<pair<long long, long long>> PQs(N); for (int i = 0; i < N; i++) { long long p; long long q; cin >> p >> q; PQs[i] = make_pair(p, q); } long long ans = -INF; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) { continue; } long long p1, q1, p2, q2; tie(p1, q1) = PQs[i]; tie(p2, q2) = PQs[j]; if (-p1 + q1 - p2 + q2 < 0) { long long temp = INF; long long loss = -p1 + q1 - p2 + q2; if (D % 2 == 0) { chmin(temp, ((D / 2) - 1) * loss + (-p1)); chmin(temp, ((D / 2) - 1) * loss + (-p1 + q1 - p2)); } else { chmin(temp, (D / 2) * loss + (-p1)); chmin(temp, ((D / 2) - 1) * loss + (-p1 + q1 - p2)); } chmax(ans, temp); } else { chmax(ans, min(-p1, -p1 + q1 - p2)); } } } if (D >= 3) { D--; sort(PQs.begin(), PQs.end()); long long minus = -PQs[0].first; long long geta = -PQs[0].first + PQs[0].second; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) { continue; } long long p1, q1, p2, q2; tie(p1, q1) = PQs[i]; tie(p2, q2) = PQs[j]; if (-p1 + q1 - p2 + q2 < 0) { long long temp = minus; long long loss = -p1 + q1 - p2 + q2; if (D % 2 == 0) { chmin(temp, geta + ((D / 2) - 1) * loss + (-p1)); chmin(temp, geta + ((D / 2) - 1) * loss + (-p1 + q1 - p2)); } else { chmin(temp, geta + (D / 2) * loss + (-p1)); chmin(temp, geta + ((D / 2) - 1) * loss + (-p1 + q1 - p2)); } chmax(ans, temp); } else { chmax(ans, min(minus, geta + min(-p1, -p1 + q1 - p2))); } } } } cout << ans << endl; return 0; }