# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107339 | vjudge1 | Bank (IZhO14_bank) | C++17 | 1066 ms | 52552 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma optimize("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
void Freopen () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
using namespace std;
#define fi first
#define se second
#define int long long
const int N = 2e5 + 7, M = 2e6;
int a[N], b[N], n, m, dp[22][M], pw[N];
void solve() {
cin>>n>>m;
pw[0] = 1;
for(int i = 1; i <= max(n, m); i++)pw[i] = (pw[i - 1] * 3);
for(int i = 1; i <= n; i++)cin>>a[i];
for(int i = 1; i <= m; i++)cin>>b[i];
bool ok = 0;
for(int i = 1; i <= n; i++) {
for(int mask = 0; mask < pw[m]; mask ++) {
int full = mask;
vector<int> us(m + 1, 0);
for(int j = m - 1; j >= 0; j--) {
int x = pw[j];
while(full >= x) {
full -= x;
us[j] ++;
}
}
int sum = 0, res = 0;
for(int j = 0; j < m; j++) {
if(us[j] == 2)sum += b[j + 1];
if(us[j] == 1)res += pw[j];
}
// cout << sum << ' ' << res << "\n";
if(sum == a[i] && dp[i - 1][res] == i - 1)dp[i][mask] = dp[i - 1][res] + 1;
if(dp[i][mask] == n)ok = 1;
}
}
cout << (ok ? "YES\n" : "NO\n");
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
// Freopen();
int T = 1;
// cin>>T;
while(T --)solve();
}
Compilation message (stderr)
# | 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... |