結果
| 問題 |
No.842 初詣
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-19 09:46:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 866 bytes |
| コンパイル時間 | 896 ms |
| コンパイル使用メモリ | 76,688 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-19 09:46:23 |
| 合計ジャッジ時間 | 1,772 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | rep(i,MAX_MONEY)scanf("%d",&id_to_cnt[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%d",&g);
| ~~~~~^~~~~~~~~
ソースコード
#include<iostream>
#include<vector>
#include<cassert>
#define rep(i,n) for(i=0;i<(int)(n);i++)
#define MAX_MONEY 6
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int id_to_cnt[MAX_MONEY],g;
const int id_to_money[MAX_MONEY]={500,100,50,10,5,1};
int main(){
int i,j;
rep(i,MAX_MONEY)scanf("%d",&id_to_cnt[i]);
scanf("%d",&g);
vector<int> money;
rep(i,MAX_MONEY){
j=1;
while(j<=id_to_cnt[i]){
id_to_cnt[i]-=j;
money.push_back(id_to_money[i]*j);
j*=2;
}
money.push_back(id_to_money[i]*id_to_cnt[i]);
}
vector<bool> dp(g+1,false);
dp[0]=true;
rep(i,money.size()){
vector<bool> now=dp;
rep(j,g+1)if(j+money[i]<=g&&dp[j])now[j+money[i]]=true;
swap(now,dp);
}
printf("%s\n",dp[g]?"YES":"NO");
return 0;
}