제출 #1107363

#제출 시각아이디문제언어결과실행 시간메모리
1107363vjudge1은행 (IZhO14_bank)C++17
44 / 100
1057 ms49232 KiB
#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 = 5e6 + 7; int a[N], b[N], n, m, dp1[2][M], pw[N], dp[N], dp2[22][1007]; void solve() { cin>>n>>m; for(int i = 1; i <= n; i++)cin>>a[i]; for(int i = 1; i <= m; i++)cin>>b[i]; if(n == 1) { dp[0] = 1; for(int i = 1; i <= m; i++) { for(int j = a[1]; j >= b[i]; j--) { dp[j] = max(dp[j], dp[j - b[i]]); } } cout << (dp[a[1]] ? "YES\n" : "NO\n"); return; } if(n <= 10 && m <= 10) { bool ok = 0; for(int i = 1; i <= n; i++) { for(int mask = 0; mask < (1 << m); mask ++) { vector<int> pos; for(int j = 0; j < m; j++) { if((1 << j) & mask)pos.push_back(j + 1); } int k = pos.size(); for(int maskk = 0; maskk < (1 << k); maskk ++) { int sum = 0, res = mask; for(int j = 0; j < k; j++) { if((1 << j) & maskk) { sum += b[pos[j]]; res -= (1 << (pos[j] - 1)); } } if(sum == a[i] && dp2[i - 1][res] == i - 1)dp2[i][mask] = dp2[i - 1][res] + 1; if(i == n && dp2[i][mask] == n)ok = 1; } } } cout << (ok ? "YES\n" : "NO\n"); return; } if(m <= 14) { pw[0] = 1; for(int i = 1; i <= 14; i++)pw[i] = (pw[i - 1] * 3ll); bool ok = 0; // cout << pw[14] << '\n'; for(int i = 1; i <= n; i++) { for(int mask = 0; mask < pw[m]; mask ++) { int full = mask; vector<int> us(m, 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]) { // cout << mask << ' ' << res << ' ' << sum << '\n'; dp1[1][mask] = max(dp1[1][mask], dp1[0][res] + 1); } if(dp1[1][mask] == n)ok = 1; } for(int mask = 0; mask < pw[m]; mask ++)dp1[0][mask] = dp1[1][mask]; } cout << (ok ? "YES\n" : "NO\n"); return; } cout << "PNX\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); //Freopen(); int T = 1; // cin>>T; while(T --)solve(); }

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize("g", on)
      | 
bank.cpp: In function 'void Freopen()':
bank.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...