結果
問題 | No.555 世界史のレポート |
ユーザー |
![]() |
提出日時 | 2017-08-11 23:09:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 139 ms / 2,000 ms |
コード長 | 834 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 43,640 KB |
実行使用メモリ | 15,180 KB |
最終ジャッジ日時 | 2024-10-12 21:44:57 |
合計ジャッジ時間 | 1,633 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include<cstdio> #include<queue> using namespace std; using vi=vector<int>; struct q_t { int c, cn, n; bool operator<(const q_t&rhs) const { return c>rhs.c; } }; class que_t { priority_queue<q_t> q; public: void push(int c, int cn, int n) { q.push((q_t){c, cn, n}); } bool pop(int&c, int&cn, int&n) { if(q.empty()) return false; c=q.top().c; cn=q.top().cn; n=q.top().n; q.pop(); return true; } }; int solve(int n, int c, int v) { que_t q; int rc=0, rcn=0, rn=1; q.push(rc, rcn, rn); while(q.pop(rc, rcn, rn)) { //printf("c=%d cn=%d n=%d\n", rc, rcn, rn); if(rn>=n) return rc; q.push(rc+c+v, rn, rn+rn); if(rcn>0) q.push(rc+v, rcn, rn+rcn); } return -1; } int main(void) { int n, c, v; while(scanf("%d%d%d", &n, &c, &v)==3) { printf("%d\n", solve(n, c, v)); } return 0; }