이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 20 + 1;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> v[N];
ll n,m,a[N],b[N],dd[N],dp[N][2000000];
ll cal(){
ll res = 0;
for (ll i = 1;i <= m;i++) res += dd[i]*b[i];
return res;
}
ll Get_num(){
ll res = 0;
for (ll i = 1;i <= m;i++) if (dd[i]) res += (1ll << (i - 1));
return res;
}
void backtrack(ll i,ll pos){
if (i > m){
if (cal() == a[pos]) v[pos].push_back(Get_num());
return;
}
dd[i] = 1; backtrack(i + 1,pos);
dd[i] = 0; backtrack(i + 1,pos);
}
ll f(ll pos,ll mask){
if (pos > n){
cout<<"YES\n"; exit(0);
}
if (dp[pos][mask] != -1) return dp[pos][mask];
ll ans = 0;
for (auto i : v[pos]){
ll now = (mask & i);
if (!now) ans = max(ans,f(pos + 1,mask | i));
}
return dp[pos][mask] = ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>m; memset(dp,-1,sizeof(dp));
for (ll i = 1;i <= n;i++) cin>>a[i];
for (ll i = 1;i <= m;i++) cin>>b[i];
for (ll i = 1;i <= n;i++) backtrack(1,i);
if (f(1,0)) cout<<"YES";
else cout<<"NO";
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
bank.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
bank.cpp: In function 'int main()':
bank.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |