結果

問題 No.1715 Dinner 2
ユーザー hari64hari64
提出日時 2021-10-22 23:20:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,758 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 173,556 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 15:24:17
合計ジャッジ時間 2,582 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 7 ms
4,348 KB
testcase_33 AC 6 ms
4,348 KB
testcase_34 AC 7 ms
4,348 KB
testcase_35 AC 7 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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));
            }
        }
    }

    cout << ans << endl;

    return 0;
}
0