結果
| 問題 | No.3711 Udon, Tempura |
| コンテスト | |
| ユーザー |
C
|
| 提出日時 | 2026-09-30 03:03:20 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 27 ms / 2,000 ms |
| + 912µs | |
| コード長 | 1,436 bytes |
| 記録 | |
| コンパイル時間 | 6,322 ms |
| コンパイル使用メモリ | 392,216 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-09-30 03:03:33 |
| 合計ジャッジ時間 | 8,520 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using pll=pair<ll,ll>;
// using mint=modint;
// template<class K,class V>
// using ordered_map=tree<K,V,less<K>,rb_tree_tag,tree_order_statistics_node_update>;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
//合計金額を一つずつチェックすればいい
//まずナップサックdpを天ぷらに回す、達成できる金額を記録する
//合計金額xのok条件はx-Uはdpから達成できるようなUが存在すること
ll N,M;
cin>>N>>M;
vll U(N),T(M);
for(int i=0;i<N;++i)cin>>U[i];
for(int i=0;i<M;++i)cin>>T[i];
ll sumT=0;
for(int i=0;i<M;++i)sumT+=T[i];
vector<bool>dp(sumT+1,false);
dp[0]=true;
for(auto t:T){
//同じ天ぷらが複数使われないように、後ろから回す
for(ll s=sumT;s>=t;--s){
if(dp[s-t])dp[s]=true;
}
}
ll mxU=*max_element(U.begin(),U.end());
vector<bool>ok(mxU+sumT+1,false);
for(auto u:U){
for(ll s=0;s<=sumT;++s){
if(dp[s])ok[s+u]=true;
}
}
ll ans=0;
for(auto x:ok){
if(x)ans++;
}
cout<<ans<<endl;
}
C