結果

問題 No.1715 Dinner 2
ユーザー FukucchiFukucchi
提出日時 2021-10-23 12:15:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 12,269 bytes
コンパイル時間 4,716 ms
コンパイル使用メモリ 248,188 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 03:21:58
合計ジャッジ時間 6,307 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
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 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'S e()':
main.cpp:361:16: warning: overflow in conversion from 'long long int' to 'S' {aka 'int'} changes value from '-2305843009213693951' to '1' [-Woverflow]
  361 | S e() { return -INF; }
      |                ^~~~
main.cpp: In function 'bool isOK(int)':
main.cpp:380:29: warning: overflow in conversion from 'long long int' to 'int' changes value from '-2305843009213693951' to '1' [-Woverflow]
  380 |             seg_new.set(ni, -INF);
      |                             ^~~~
main.cpp:383:29: warning: overflow in conversion from 'long long int' to 'int' changes value from '-2305843009213693951' to '1' [-Woverflow]
  383 |             seg_pre.set(ni, -INF);
      |                             ^~~~
main.cpp: In function 'int bin_search()':
main.cpp:408:14: warning: overflow in conversion from 'long long int' to 'int' changes value from '2305843009213693951' to '-1' [-Woverflow]
  408 |     int ng = INF;
      |              ^~~
main.cpp:409:14: warning: overflow in conversion from 'long long int' to 'int' changes value from '-2305843009213693951' to '1' [-Woverflow]
  409 |     int ok = -INF;
      |              ^~~~

ソースコード

diff #

/* #region  header */
#pragma GCC optimize("O3") //コンパイラ最適化用

#ifdef LOCAL
#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#endif
#define _USE_MATH_DEFINES
#include <atcoder/all> // CodeForcesの場合ファイルごとに入れる
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace atcoder;
typedef long long LL;
typedef long double LD;

#define ALL(x) x.begin(), x.end()
const long long INF = numeric_limits<long long>::max() / 4;
const int MOD = 1e9 + 7;
// const int MOD=998244353;
//略記
#define FF first
#define SS second
// #define int long long
#define stoi stoll
#define pii pair<int, int>
#define PII pair<int, int>
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(x) (int)((x).size())
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VI vector<int>
#define VVI vector<vector<int>>

// rep macro
#define FOA(v, a) for (auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for (int i = 0; i < (x); ++i)
#define REP1(i, x) for (int i = 0; i < (x); ++i)
#define REP2(i, l, r) for (int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for (int i = (l); i < (r); i += (c))
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for (int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for (int i = (x)-1; i >= 0; --i)
#define RREP2(i, r, l) for (int i = (r)-1; i >= (l); --i)
#define RREP3(i, r, l, c) for (int i = (r)-1; i >= (l); i -= (c))

const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first >> p.second;
    return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v)
        is >> i;
    return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
    std::string s;
    is >> s;
    __int128_t ret = 0;
    for (int i = 0; i < s.length(); i++)
        if ('0' <= s[i] and s[i] <= '9')
            ret = 10 * ret + s[i] - '0';
    a = ret * (s[0] == '-' ? -1 : 1);
    return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
// void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U> void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T> void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail> void INPUT(Head &head, Tail &...tail) {
    scan(head);
    INPUT(tail...);
}
} // namespace scanner
#define VEC(type, name, size)                                                  \
    std::vector<type> name(size);                                              \
    scanner::INPUT(name)
#define VVEC(type, name, h, w)                                                 \
    std::vector<std::vector<type>> name(h, std::vector<type>(w));              \
    scanner::INPUT(name)
#define INT(...)                                                               \
    int __VA_ARGS__;                                                           \
    scanner::INPUT(__VA_ARGS__)
#define LONL(...)                                                              \
    long long __VA_ARGS__;                                                     \
    scanner::INPUT(__VA_ARGS__)
#define STR(...)                                                               \
    std::string __VA_ARGS__;                                                   \
    scanner::INPUT(__VA_ARGS__)
#define CHAR(...)                                                              \
    char __VA_ARGS__;                                                          \
    scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)                                                            \
    double __VA_ARGS__;                                                        \
    scanner::INPUT(__VA_ARGS__)
#define LOND(...)                                                              \
    long double __VA_ARGS__;                                                   \
    scanner::INPUT(__VA_ARGS__)
int in() {
    int x;
    cin >> x;
    return x;
}
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed#c%E3%81%A7%E3%81%AE%E5%AE%9F%E8%A3%85
void print() { cout << "\n"; }
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << "\n";
}
template <class T> void print(set<T> &set) {
    for (auto &a : set) {
        cout << a << " ";
    }
    cout << "\n";
}
template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "NO\n"; }

// debug macro
// https://atcoder.jp/contests/abc202/submissions/22815715
namespace debugger {
template <class T> void view(const std::vector<T> &a) {
    std::cerr << "{ ";
    for (const auto &v : a) {
        std::cerr << v << ", ";
    }
    std::cerr << "\b\b }";
}
template <class T> void view(const std::vector<std::vector<T>> &a) {
    std::cerr << "{\n";
    for (const auto &v : a) {
        std::cerr << "\t";
        view(v);
        std::cerr << "\n";
    }
    std::cerr << "}";
}
template <class T, class U> void view(const std::vector<std::pair<T, U>> &a) {
    std::cerr << "{\n";
    for (const auto &p : a)
        std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
    std::cerr << "}";
}
template <class T, class U> void view(const std::map<T, U> &m) {
    std::cerr << "{\n";
    for (const auto &p : m)
        std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
    std::cerr << "}";
}
template <class T, class U> void view(const std::pair<T, U> &p) {
    std::cerr << "(" << p.first << ", " << p.second << ")";
}
template <class T> void view(const std::set<T> &s) {
    std::cerr << "{ ";
    for (auto &v : s) {
        view(v);
        std::cerr << ", ";
    }
    std::cerr << "\b\b }";
}

template <class T> void view(const T &e) { std::cerr << e; }
} // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
    debugger::view(H);
    std::cerr << ", ";
    debug_out(T...);
}
#define debug(...)                                                             \
    do {                                                                       \
        std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : [";              \
        debug_out(__VA_ARGS__);                                                \
        std::cerr << "\b\b]\n";                                                \
    } while (false)
#else
#define debug(...) (void(0))
#endif

long long power(long long x, long long n) {
    // O(logn)
    // https://algo-logic.info/calc-pow/#toc_id_1_2
    long long ret = 1;
    while (n > 0) {
        if (n & 1)
            ret *= x; // n の最下位bitが 1 ならば x^(2^i) をかける
        x *= x;
        n >>= 1; // n を1bit 左にずらす
    }
    return ret;
}
// @brief nCr. O(r log n)。あるいは前処理 O(n), 本処理 O(1)で求められる modint
// の bc を検討。
int comb(int n, int r) {
    // https://www.geeksforgeeks.org/program-to-calculate-the-value-of-ncr-efficiently/
    if (n < r)
        return 0;

    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...
    long long p = 1, k = 1;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;

            // gcd of p, k
            long long m = __gcd(p, k);

            // dividing by gcd, to simplify
            // product division by their gcd
            // saves from the overflow
            p /= m;
            k /= m;

            n--;
            r--;
        }

        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }

    else
        p = 1;

    // if our approach is correct p = ans and k =1
    return p;
}

// MOD
void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// 負数も含む丸め
long long ceildiv(long long a, long long b) {
    if (b < 0)
        a = -a, b = -b;
    if (a >= 0)
        return (a + b - 1) / b;
    else
        return a / b;
}
long long floordiv(long long a, long long b) {
    if (b < 0)
        a = -a, b = -b;
    if (a >= 0)
        return a / b;
    else
        return (a - b + 1) / b;
}
long long floorsqrt(long long x) {
    assert(x >= 0);
    long long ok = 0;
    long long ng = 1;
    while (ng * ng <= x)
        ng <<= 1;
    while (ng - ok > 1) {
        long long mid = (ng + ok) >> 1;
        if (mid * mid <= x)
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

// @brief a^n mod mod
long long modpower(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// @brief s が c を含むか
template <class T> bool contain(const std::string &s, const T &c) {
    return s.find(c) != std::string::npos;
}

__attribute__((constructor)) void faster_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cerr.tie(nullptr);
}
/* #endregion */
// ACL はオーバーフローに注意!!!

// https://tumoiyorozu.github.io/single-file-ac-library/document_ja/segtree.html
using S = int;
// s[l,m), s[m,r) から s[l,r) を計算する式
S op(S s_l, S s_r) {
    return max(s_l, s_r); // return s_l+s_r;
}
S e() { return -INF; }

/*
using S = int;
S op(S l, S r) { return min(l, r); }
S e() { return INF; }
*/

// segtree<S, op, e> seg(maxa);
int n, d;
VI P, Q;
segtree<S, op, e> seg_pre(1010), seg_new(1010);

// idx が条件を満たすかどうか
bool isOK(int idx) {
    REP(ni, n) { seg_pre.set(ni, 0); }
    debug(idx);
    REP(di, d) {
        REP(ni, n) {
            seg_new.set(ni, -INF);

            int v = seg_pre.get(ni);
            seg_pre.set(ni, -INF);
            int Mv = seg_pre.all_prod();
            seg_pre.set(ni, v);
            debug(idx, di, ni, Mv - P[ni] + Q[ni]);

            if (Mv - P[ni] < idx) {
                continue;
            }
            if (seg_new.get(ni) < Mv - P[ni] + Q[ni]) {
                seg_new.set(ni, Mv - P[ni] + Q[ni]);
            }
        }
        seg_pre = seg_new;
    }
    int ans = seg_pre.all_prod();
    debug(idx, ans);
    if (ans > -INF) {
        return true;
    } else
        return false;
}

int bin_search() {
    // ng, okともに広めにとる
    // 1 以上の整数なら、ng = 0。-1 でバグったことあり
    int ng = INF;
    int ok = -INF;

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}
signed main() {
    cin >> n >> d;
    P.resize(n);
    Q.resize(n);

    REP(ni, n) { cin >> P[ni] >> Q[ni]; }
    debug(P);
    debug(Q);

    print(bin_search());
}
0