제출 #671868

#제출 시각아이디문제언어결과실행 시간메모리
671868Baytoro은행 (IZhO14_bank)C++17
100 / 100
201 ms16820 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define int long long #define endl '\n' void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int INF=1e18,mod=1e9+7; int n,m; void get(int x){ for(int i=0;i<m;i++) cout<<((x&(1<<i))?1:0); cout<<endl; } int dp[(1<<20)+5],ok[(1<<20)+5],sum[(1<<20)+5]; void build(vector<int> a, vector<int> b){ for(int i=1;i<(1<<m);i++){ for(int j=0;j<m;j++){ if(i&(1<<j)) sum[i]=sum[(i^(1<<j))]+b[j]; } } } int pref[25]; void f(int x,int id){ for(int i=0;i<m;i++){ if(id!=-1 && sum[(x|(1<<i))]<=pref[id]) ok[(x|(1<<i))]=1; if(id==-1) ok[(x|(1<<i))]=1; } } void solve(){ cin>>n>>m; vector<int> a(n+1),b(m+1); for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++) cin>>b[i]; build(a,b); pref[0]=a[0]; for(int i=1;i<n;i++) pref[i]=a[i]+pref[i-1]; f(0,0); for(int i=0;i<n;i++){ for(int mask=1;mask<(1<<m);mask++){ if(sum[mask]>pref[i] || (i>0 && sum[mask]<pref[i-1])) continue; if(!ok[mask]) continue; /*if(i==1) get(mask);*/ f(mask,i); if(sum[mask]==pref[i]){ if(i==n-1){ cout<<"YES\n"; return; } } /*for(int j=0;j<m;j++){ if(mask&(1<<j)){ if(ok[mask^(1<<j)]<i-1) continue; dp[mask]=(dp[mask^(1<<j)])+b[j]; if(dp[mask]>a[i]) continue; ok[mask]=i-1; if(dp[mask]==a[i]){ dp[mask]=0; ok[mask]=i; //get(mask); if(i==n-1){ cout<<"YES\n"; return; } } break; } }*/ } } cout<<"NO\n"; } main(){ ios; int T=1; //cin>>T; while(T--){ solve(); } }

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

bank.cpp:86:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   86 | main(){
      | ^~~~
bank.cpp: In function 'void fopn(std::string)':
bank.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".out").c_str(),"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...