結果
問題 | No.941 商とあまり |
ユーザー |
![]() |
提出日時 | 2019-12-04 12:56:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,381 ms / 2,000 ms |
コード長 | 2,023 bytes |
コンパイル時間 | 1,073 ms |
コンパイル使用メモリ | 115,152 KB |
実行使用メモリ | 254,992 KB |
最終ジャッジ日時 | 2024-11-30 06:47:53 |
合計ジャッジ時間 | 10,438 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 104 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<ll, ll> P; int main() { int n, x; cin>>n>>x; int a[101]; int mn=x; for(int i=0; i<n; i++){ cin>>a[i]; mn=min(mn, a[i]); } string s; for(int i=0; i<x; i++) s+='0'; if(n==1){ if(a[0]<=x) s[a[0]-1]='1'; cout<<s<<endl; return 0; } ll p=1; for(int i=0; i<n; i++){ p*=(a[i]+1); if(p>=x+2){ cout<<s<<endl; return 0; } } p--; bool dp[500050]={}; for(int i=0; i<n; i++){ for(int j=p; j<=x; j+=a[i]){ dp[j]=1; } } if(mn==1 || n==2){ for(int i=1; i<=x; i++) if(dp[i]) s[i-1]='1'; cout<<s<<endl; return 0; } for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(i==j) continue; bool dp1[500050]={}; for(int k=p; k<=x; k+=a[j]) dp1[k]=1; for(int k=p; k<=x-a[i]*(a[j]+1); k++){ if(dp1[k]) dp1[k+a[i]*(a[j]+1)]=1; } for(int k=p; k<=x; k++) if(dp1[k]) dp[k]=1; } } if(mn==2 || n==3){ for(int i=1; i<=x; i++) if(dp[i]) s[i-1]='1'; cout<<s<<endl; return 0; } bool dp1[1<<9][500050]={}; dp1[0][0]=1; for(int i=1; i<(1<<n); i++){ for(int j=0; j<n; j++){ if(!((i>>j)&1)) continue; bool dp2[500050]={}; for(int k=0; k<=(x-p)/(a[j]+1); k++){ if(dp1[i^(1<<j)][k]) dp2[k*(a[j]+1)]=1; } for(int k=0; k<=x-p-a[j]; k++){ if(dp2[k]) dp2[k+a[j]]=1; } for(int k=0; k<=x-p; k++){ if(dp2[k]) dp1[i][k]=1; } } } for(int i=0; i<n; i++){ for(int k=0; k<=x-p; k++){ if(dp1[((1<<n)-1)^(1<<i)][k]) dp[k+p]=1; } } for(int i=1; i<=x; i++) if(dp[i]) s[i-1]='1'; cout<<s<<endl; return 0; }