結果

問題 No.860 買い物
ユーザー kagasankagasan
提出日時 2019-10-08 19:35:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 1,853 ms
コンパイル使用メモリ 175,900 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-04-25 02:48:08
合計ジャッジ時間 9,304 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 115 ms
13,424 KB
testcase_12 AC 117 ms
11,008 KB
testcase_13 AC 931 ms
71,296 KB
testcase_14 AC 581 ms
72,192 KB
testcase_15 AC 129 ms
14,336 KB
testcase_16 WA -
testcase_17 AC 146 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
template<class T> bool find_from_set(set<T> &S, const T &t){
    return S.find(t) != S.end();
}
typedef pair<ll, P> LP;

int main(){

    ll N;
	cin >> N;
	vector<ll>A(N), B(N);
	rep(i, N)cin >> A[i] >> B[i];
	priority_queue<LP, vector<LP>, greater<LP> >Q;
	set<P>S;
	Q.push(LP(A[0] * 2, P(1, A[0])));
	while(!Q.empty()){
		ll cst = Q.top().first;
		P p = Q.top().second;
		Q.pop();
		if(find_from_set(S, p))continue;
		S.insert(p);
		ll idx = p.first, mum = p.second;
		if(idx == N){
			cout << cst << endl;
			break;
		}
		Q.push(LP(cst + A[idx] * 2, P(idx + 1, A[idx])));
		cst += A[idx] + B[idx];
		if(mum > A[idx]){
			cst -= mum;
			cst += A[idx];			
		}
		Q.push(LP(cst, P(idx + 1, min(A[idx], mum))));		
	}

    return 0;
}
0