結果
問題 | No.2693 Sword |
ユーザー |
|
提出日時 | 2024-03-22 21:30:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 3,562 bytes |
コンパイル時間 | 2,260 ms |
コンパイル使用メモリ | 202,000 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-09-30 10:52:58 |
合計ジャッジ時間 | 2,719 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 1 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 1 ms
5,248 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 1 ms
5,248 KB |
testcase_26 | AC | 1 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 1 ms
5,248 KB |
testcase_32 | AC | 5 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; struct stable_int{ long long v; stable_int() : v(0) {} stable_int(long long _v) : v(_v){} stable_int& operator++() { if(__builtin_add_overflow(v, 1, &v))v = std::numeric_limits<long long>::max(); return *this; } stable_int& operator--() { if(__builtin_sub_overflow(v, 1, &v))v = std::numeric_limits<long long>::min(); return *this; } stable_int operator++(int) { stable_int result = *this; ++*this; return result; } stable_int operator--(int) { stable_int result = *this; --*this; return result; } stable_int& operator+=(const stable_int& rhs) { if(__builtin_add_overflow(v, rhs.v, &v))v = std::numeric_limits<long long>::max(); return *this; } stable_int& operator-=(const stable_int& rhs) { if(__builtin_sub_overflow(v, rhs.v, &v))v = std::numeric_limits<long long>::min(); return *this; } stable_int& operator*=(const stable_int& rhs) { long long pre = v; if(__builtin_mul_overflow(v, rhs.v, &v)){ v = (pre > 0) ^ (rhs.v > 0) ? std::numeric_limits<long long>::min() : std::numeric_limits<long long>::max(); } return *this; } stable_int& operator/=(const stable_int& rhs) { v /= rhs.v; return *this ; } stable_int operator+() const { return *this; } stable_int operator-() const { return stable_int() - *this; } friend stable_int operator+(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) += rhs; } friend stable_int operator-(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) -= rhs; } friend stable_int operator*(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) *= rhs; } friend stable_int operator/(const stable_int& lhs, const stable_int& rhs) { return stable_int(lhs) /= rhs; } friend bool operator==(const stable_int& lhs, const stable_int& rhs) { return (lhs.v == rhs.v); } friend bool operator!=(const stable_int& lhs, const stable_int& rhs) { return (lhs.v != rhs.v); } friend bool operator<(const stable_int& lhs, const stable_int& rhs) { return (lhs.v < rhs.v); } friend bool operator<=(const stable_int& lhs, const stable_int& rhs) { return (lhs.v <= rhs.v); } friend bool operator>(const stable_int& lhs, const stable_int& rhs) { return (lhs.v > rhs.v); } friend bool operator>=(const stable_int& lhs, const stable_int& rhs) { return (lhs.v >= rhs.v); } friend istream& operator>>(istream& is,stable_int& rhs) noexcept { long long _v; rhs = stable_int{(is >> _v, _v)}; return is; } friend ostream& operator << (ostream &os, const stable_int& rhs) noexcept { return os << rhs.v; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n, p, k; ll mx = 1'000'000'000'000'000'000ll; cin >> n >> p >> k; vector<stable_int> dp(k + 1, -mx); dp[0] = p; for(int i = 0; i < n; i++){ ll t, b; cin >> t >> b; for(int j = k - 1; j >= 0; j--){ if(t == 1) dp[j + 1] = max(dp[j + 1], dp[j] + b); else dp[j + 1] = max(dp[j + 1], dp[j] * 2); } } stable_int ans = dp[k]; if(ans > mx) ans = -1; cout << ans << '\n'; }