結果

問題 No.1782 ManyCoins
ユーザー 👑 kmjpkmjp
提出日時 2021-12-11 00:13:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 720 ms / 2,000 ms
コード長 1,340 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 206,496 KB
実行使用メモリ 28,760 KB
最終ジャッジ日時 2023-09-26 00:56:58
合計ジャッジ時間 11,120 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,204 KB
testcase_01 AC 6 ms
11,160 KB
testcase_02 AC 5 ms
11,356 KB
testcase_03 AC 5 ms
11,356 KB
testcase_04 AC 5 ms
11,152 KB
testcase_05 AC 5 ms
11,244 KB
testcase_06 AC 5 ms
11,216 KB
testcase_07 AC 5 ms
11,140 KB
testcase_08 AC 6 ms
11,220 KB
testcase_09 AC 6 ms
11,208 KB
testcase_10 AC 5 ms
11,232 KB
testcase_11 AC 5 ms
11,292 KB
testcase_12 AC 5 ms
11,208 KB
testcase_13 AC 146 ms
11,144 KB
testcase_14 AC 515 ms
20,272 KB
testcase_15 AC 246 ms
16,144 KB
testcase_16 AC 289 ms
15,244 KB
testcase_17 AC 516 ms
19,568 KB
testcase_18 AC 302 ms
15,440 KB
testcase_19 AC 6 ms
11,156 KB
testcase_20 AC 418 ms
19,528 KB
testcase_21 AC 514 ms
19,732 KB
testcase_22 AC 647 ms
28,000 KB
testcase_23 AC 575 ms
19,828 KB
testcase_24 AC 7 ms
11,176 KB
testcase_25 AC 720 ms
27,872 KB
testcase_26 AC 200 ms
12,912 KB
testcase_27 AC 583 ms
28,760 KB
testcase_28 AC 7 ms
11,280 KB
testcase_29 AC 44 ms
11,156 KB
testcase_30 AC 42 ms
11,284 KB
testcase_31 AC 61 ms
11,184 KB
testcase_32 AC 74 ms
11,288 KB
testcase_33 AC 135 ms
11,140 KB
testcase_34 AC 183 ms
11,160 KB
testcase_35 AC 239 ms
11,140 KB
testcase_36 AC 34 ms
11,288 KB
testcase_37 AC 11 ms
11,352 KB
testcase_38 AC 7 ms
11,196 KB
testcase_39 AC 6 ms
11,172 KB
testcase_40 AC 6 ms
11,364 KB
testcase_41 AC 7 ms
11,220 KB
testcase_42 AC 6 ms
11,196 KB
testcase_43 AC 5 ms
11,280 KB
testcase_44 AC 7 ms
11,256 KB
testcase_45 AC 6 ms
11,156 KB
testcase_46 AC 18 ms
11,204 KB
testcase_47 AC 18 ms
11,212 KB
testcase_48 AC 6 ms
11,188 KB
testcase_49 AC 6 ms
11,156 KB
testcase_50 AC 6 ms
11,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N;
ll L;
ll W[22];
ll dp[1010101];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>L;
	FOR(i,N) cin>>W[i];
	sort(W,W+N);
	
	ll M=W[N-1];
	
	FOR(i,1000000) dp[i]=1LL<<60;
	dp[0]=0;
	priority_queue<pair<ll,int>> Q;
	Q.push({0,0});
	
	while(Q.size()) {
		ll c=-Q.top().first;
		ll a=Q.top().second;
		Q.pop();
		if(dp[a]!=c) continue;
		FOR(i,N-1) {
			ll v=c+W[i];
			if(dp[v%M]>v) {
				dp[v%M]=v;
				Q.push({-v,v%M});
			}
		}
	}
	
	ll ret=-1;
	FOR(i,M) {
		if(dp[i]<=L) {
			ret+=(L-dp[i])/M+1;
		}
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0