제출 #461792

#제출 시각아이디문제언어결과실행 시간메모리
461792the_visitor2341은행 (IZhO14_bank)C++14
100 / 100
139 ms16708 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define repp(a) F0R(_,a) #define each(a,x) for (auto& a: x) #define all(x) begin(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)(x).size() #define lb lower_bound #define ub upper_bound #define f first #define s second #define eb emplace_back #define pb push_back #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front #define rtn return #define trav(it,v) for(auto&it:(v)) #define rsz resize #define tcT template<class T #define tcTU tcT,class U typedef string str; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vl; typedef vector<str> vs; typedef vector<pii> vpii; tcT> using V = vector<T>; tcT, size_t SZ> using AR = array<T,SZ>; tcT> using PR = pair<T,T>; tcT> using pqg = priority_queue<T,vector<T>,greater<T>>; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b) - begin(a)); } const int MOD = 1e9 + 7; const ll INF = 1e18; const db PI = acos((db)-1); const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; constexpr int pct(int x) { return __builtin_popcount(x); } constexpr int bits(int x) { // assert(x >= 0); return x == 0 ? 0 : 31-__builtin_clz(x); } constexpr int p2(int x) { return 1<<x; } constexpr int msk2(int x) { return p2(x)-1; } tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } tcT> bool ckmax(T& a, const T& b) { return b > a ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } tcTU> T fstTrue(T lo ,T hi, U f) { hi++ ; assert(lo <= hi); while(lo < hi) { T mid = lo + (hi - lo)/2; f(mid) ? hi = mid : lo = mid+1; } return lo; } tcTU> T lstTrue(T lo, T hi, U f) { lo--; assert(lo <= hi); while(lo < hi) { T mid = lo + (hi-lo+1)/2; f(mid) ? lo = mid : hi = mid-1; } return lo; } tcT> void remDup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); } void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif void setPrec() { cout << fixed << setprecision(16); } void setIO(str name = "") { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); setPrec(); if(sz(name)) { freopen((name + ".in").c_str(),"r",stdin); freopen((name + ".out").c_str(),"w",stdout); } } const int MASK = 1<<21; struct dya { int cvr=-1, lf=-1, prev_mask=-1, pson=-1; } dp[MASK]; int N,M; int sal[25],note[25]; void solve() { cin>>N>>M; F0R(i,N) cin>>sal[i]; F0R(i,M) cin>>note[i]; dp[0].cvr=dp[0].lf=0; F0R(mask,1<<M) { F0R(lst,M) { if(mask>>lst&1) { int prvmsk = mask&~(1<<lst); if(~dp[prvmsk].cvr) { int have = dp[prvmsk].lf+note[lst]; if(have<sal[dp[prvmsk].cvr]) { dp[mask]=dp[prvmsk]; dp[mask].lf=have; dp[mask].prev_mask=prvmsk; } else if(have==sal[dp[prvmsk].cvr]) { dp[mask].cvr=dp[prvmsk].cvr+1; dp[mask].lf=0; dp[mask].prev_mask=prvmsk; dp[mask].pson=dp[prvmsk].cvr; } } } } if(dp[mask].cvr==N) return void(cout<<"YES\n"); } cout << "NO\n"; } //#define TC int main() { setIO(); int t=1; #ifdef TC cin>>t; #endif while(t-- > 0) { solve(); } return 0; }

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

bank.cpp: In function 'void setIO(str)':
bank.cpp:122:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |   freopen((name + ".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:123:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |   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...