結果
問題 | No.288 貯金箱の仕事 |
ユーザー |
![]() |
提出日時 | 2017-07-30 06:58:01 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 863 bytes |
コンパイル時間 | 1,266 ms |
コンパイル使用メモリ | 158,088 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 21:46:20 |
合計ジャッジ時間 | 3,140 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 48 |
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] 17 | main(){ | ^~~~
ソースコード
#include <bits/stdc++.h> #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef set<int> si; const int inf = 1e8; const int mod = 1e9+7; int dp[250001]; int n, m, a[500], k[500], q; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; FOR(i, 0, n)cin >> a[i]; FOR(i, 0, n)cin >> k[i]; q = a[n - 1]; q *= q; FOR(i, 1, q)dp[i] = inf; m *= -1; FOR(i, 0, n)m += a[i] * k[i]; if(m < 0){ cout << -1 << endl; return 0; } FORR(i, n-1, 0){ int d = a[i]; FOR(j, d, q){ dp[j] = min(dp[j], dp[j - d] + 1); } } ll t = 0; if(m >= q){ t = (m - q)/a[n-1] + 1; m -= t * a[n-1]; } t += dp[m]; if(t >= inf)t = -1; cout << t << endl; }