結果

問題 No.286 Modulo Discount Store
ユーザー fura
提出日時 2020-06-08 08:59:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 2,622 ms
コンパイル使用メモリ 192,820 KB
最終ジャッジ日時 2025-01-11 00:08:03
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,n) scanf("%d",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int dp[1<<15];
	rep(S,1<<n) dp[S]=INF;
	dp[0]=0;
	rep(S,1<<n){
		int sum=0;
		rep(i,n) if(S>>i&1) sum+=a[i];
		rep(i,n) if((S>>i&1)==0) {
			dp[S|1<<i]=min(dp[S|1<<i],dp[S]+max(a[i]-sum%1000,0));
		}
	}
	printf("%d\n",dp[(1<<n)-1]);

	return 0;
}
0