結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
iiljj
|
| 提出日時 | 2020-02-08 11:28:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 7,771 bytes |
| コンパイル時間 | 1,566 ms |
| コンパイル使用メモリ | 167,624 KB |
| 最終ジャッジ日時 | 2024-11-14 22:06:25 |
| 合計ジャッジ時間 | 2,420 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In instantiation of 'std::istream& operator>>(std::istream&, std::vector<_Tp>&) [with T = std::pair<long long int, long long int>; std::istream = std::basic_istream<char>]':
main.cpp:236:12: required from here
main.cpp:35:12: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'std::pair<long long int, long long int>')
35 | is >> x;
| ~~~^~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
from main.cpp:3:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:120:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]'
120 | operator>>(__istream_type& (*__pf)(__istream_type&))
| ^~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:120:36: note: no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'}
120 | operator>>(__istream_type& (*__pf)(__istream_type&))
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:124:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with
ソースコード
/* #region Head */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vvs = vector<vs>;
#define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i))
#define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i))
#define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i))
#define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d))
#define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d))
#define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) begin(x), end(x)
#define SIZE(x) ((ll)(x).size())
constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
for (T &x : vec)
is >> x;
return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
ll len = SIZE(vec);
os << "{";
for (int i = 0; i < len; i++)
os << vec[i] << (i == len - 1 ? "" : ", ");
os << "}";
return os;
}
// pair入力
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &pair_var)
{
is >> pair_var.first >> pair_var.second;
return is;
}
// pair出力
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var)
{
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// map出力
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var)
{
os << "{";
REPI(itr, map_var)
{
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set 出力
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var)
{
os << "{";
REPI(itr, set_var)
{
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// dump
#define DUMPOUT cerr
void dump_func()
{
DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail)
{
DUMPOUT << head;
if (sizeof...(Tail) > 0)
{
DUMPOUT << ", ";
}
dump_func(move(tail)...);
}
// _max の終端.
template <class Head>
ll _max(Head &&head)
{
return head;
}
// 最大値を求める.max({}) の代わり.これにしないと vscode が壊れる.
template <class Head, class... Tail>
ll _max(Head &&head, Tail &&... tail)
{
return max((ll)head, _max((tail)...));
}
// _min の終端.
template <class Head>
ll _min(Head &&head)
{
return head;
}
// 最小値を求める.min({}) の代わり.これにしないと vscode が壊れる.
template <class Head, class... Tail>
ll _min(Head &&head, Tail &&... tail)
{
return min((ll)head, _min((tail)...));
}
// chmax (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
if (comp(xmax, x))
{
xmax = x;
return true;
}
return false;
}
// chmin (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
if (comp(x, xmin))
{
xmin = x;
return true;
}
return false;
}
// container 内の最初の element のインデックスを探す
template <class Container>
ll indexof(const Container &container, const typename Container::value_type &element)
{
auto iter = find(container.begin(), container.end(), element);
size_t index = distance(container.begin(), iter);
if (index == container.size())
{
index = -1;
}
return index;
}
// ローカル用
#define DEBUG_
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
<< endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
struct AtCoderInitialize
{
static constexpr int IOS_PREC = 15;
static constexpr bool AUTOFLUSH = false;
AtCoderInitialize()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH)
cout << unitbuf;
}
} ATCODER_INITIALIZE;
/* #endregion */
/**
問題文
tempura さんはピザ屋さんに行きました。
ピザ屋さんには N 枚のピザが売られています。 i 番目のピザ (1 <= i <= N) の価格は P_i 円で、美味しさは D_i です。
いま、このピザ屋さんでは無料キャンペーンが行われています。tempura さんは以下を何回か繰り返してピザを購入することができます。
・P_i 円を払って i 番目のピザを買う。
・その後、価格が P_i 円以下のピザが残っているならば、そのうちの 1 枚を選んで無料で買うことができる。
支払うお金の合計を K 円以下にしたときの、購入したピザの美味しさの合計の最大値を求めてください。
・1 <= N <= 5000
・1 <= K <= 5000
・1 <= P_i <= K
・1 <= D_i <= 5000
・入力はすべて整数である。
*/
void solve()
{
ll n, k;
cin >> n >> k;
vector<pll> pd(n);
cin >> pd;
// P_i <= K なので,ピザは必ず1枚以上購入できる.
// N <= 5000 なので二重ループでも大丈夫
sort(ALL(pd));
reverse(ALL(pd));
// 最大 2K 枚を選べるナップザック問題 ただしボーナス
// dp[i+1][w][j]: i 番目までを選んで価格総和が w 以下となるよう選んだときの美味しさ総和の最大値, j:=ボーナス発生させられる
// vector<vvll> dp(n + 1, vvll(k + 1, vll(2, 0)));
vector<vvll> dp(2, vvll(k + 1, vll(2, 0)));
REP(i, 0, n) // ピザのループ
{
REPM(price, 0, k) // このピザまでの価格総和のループ
{
// i 番目のピザは買えない (買うと price を超えてしまう)
if (price < pd[i].first)
{
dp[(i + 1) % 2][price][0] = dp[i % 2][price][0];
dp[(i + 1) % 2][price][1] = dp[i % 2][price][1];
}
else
{
// i 番目のピザは買おうと思えば買える
// dp[i + 1][price] = max(dp[i][price], );
ll tmp0 = dp[i % 2][price - pd[i].first][0] + pd[i].second; // 有料で買った場合のおいしさ総和
ll tmp1 = dp[i % 2][price][1] + pd[i].second; // 無料で買った場合のおいしさ総和
dp[(i + 1) % 2][price][0] = max(tmp1, dp[i % 2][price][0]); // 次は有料で買わないといけない
dp[(i + 1) % 2][price][1] = max(tmp0, dp[i % 2][price][1]); // 次は無料でもらえる
}
}
}
// dump(dp);
cout << *max_element(ALL(dp[n % 2][k])) << endl;
}
/**
* エントリポイント.
* @return 0.
*/
int main()
{
solve();
return 0;
}
iiljj