제출 #1262773

#제출 시각아이디문제언어결과실행 시간메모리
1262773blueviolet은행 (IZhO14_bank)C++20
100 / 100
97 ms8596 KiB
#include             <bits/stdc++.h>
    
#define             ll   long long
#define          io(x)   if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
#define        TimeRun   {End=clock();cerr<<"Time run: "<<(float)(End-Begin)/CLOCKS_PER_SEC<<"s"<<el;}
#define      mem(c, x)   memset(c, x, sizeof(c))
#define         all(c)   c.begin(), c.end()
#define       bit(i,j)   ((i >> j) & 1)
#define             se   second     
#define             fi   first
#define             el   '\n'
using namespace std;  

template<class X, class Y> bool maximize(X &a, const Y &b) { return (a <= b ? a = b, 1 : 0); }
template<class X, class Y> bool minimize(X &a, const Y &b) { return (a > b ? a = b, 1 : 0); }

int dx[8] = {0, 1, 0,-1, 1, 1,-1,-1};
int dy[8] = {1, 0,-1, 0, 1,-1,-1, 1};
const int  maxn  = 21	;
const int  Inf   = 2e9 + 7;
const ll   Infll = 1e18 + 9;
const ll   Mod   = 1e9 + 7;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int a[maxn], b[maxn], Left[1 << maxn], cover[1 << maxn], n, m;

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];

	for (int mask=1; mask<(1 << m); mask++) {
		for (int i=0; i<m; i++) {
			if (!bit(mask, i)) continue;
			int prev = mask ^ (1 << i), nxtCover = 0, target = a[cover[prev] + 1], nxtLeft = 0;
			if (b[i + 1] + Left[prev] == target) {
				nxtCover = cover[prev] + 1;
				nxtLeft = 0;
			} else
			if (b[i + 1] == target) {
				nxtCover = cover[prev] + 1;
				nxtLeft = Left[prev];
			} else
			if (Left[prev] == target) {
				nxtCover = cover[prev] + 1;
				nxtLeft = b[i + 1];
			} else {
				nxtCover = cover[prev];
				nxtLeft = b[i + 1] + Left[prev];
			}

			if (maximize(cover[mask], nxtCover)) { // >=
				Left[mask] = nxtLeft;
			}
		}

		if (cover[mask] == n) return void(cout << "YES");
	}


	cout << "NO";
}

signed main() {
    
    ios_base::sync_with_stdio(false);  cin.tie(0); cout.tie(0); clock_t Begin = clock(), End;
    io("task"); 

    solve();
    
    TimeRun; return (0 ^ 0);
}

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

bank.cpp: In function 'int main()':
bank.cpp:4:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define          io(x)   if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~
bank.cpp:66:5: note: in expansion of macro 'io'
   66 |     io("task");
      |     ^~
bank.cpp:4:85: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define          io(x)   if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
      |                                                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~
bank.cpp:66:5: note: in expansion of macro 'io'
   66 |     io("task");
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...