제출 #318077

#제출 시각아이디문제언어결과실행 시간메모리
318077shivensinha4Brunhilda’s Birthday (BOI13_brunhilda)C++17
20 / 100
4 ms1644 KiB
#include "bits/stdc++.h"
using namespace std; 
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'

const int MXV = 1e4;
int ans[MXV+2];
vi fac[MXV+2];

int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int m, q; cin >> m >> q;
	int mxp = -1;
	for_(i, 0, m)  {
		int p; cin >> p;
		fac[p].push_back(p);
		mxp = max(mxp, p);
	}
	
	vector<ii> last; // {val, nxt}
	last.push_back({0, mxp});
	int pt = 0;
	for_(i, 1, MXV+1) {
		if (pt < last.size() and last[pt].second == i) pt++;
		
		if (pt < last.size()) {
			ans[i] = ans[last[pt].first]+1;
		}
		
		for (int f: fac[i]) {
			int nxt = i+f;
			if (ans[i] and last.back().second < nxt) last.push_back({i, nxt});
			if (nxt <= MXV) fac[nxt].push_back(f);
		}
	}
	
	for_(i, 0, q) {
		int k; cin >> k;
		assert(k <= MXV);
		if (!ans[k]) cout << "oo";
		else cout << ans[k];
		cout << endl;
	}
	

	return 0;
}

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

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:34:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   if (pt < last.size() and last[pt].second == i) pt++;
      |       ~~~^~~~~~~~~~~~~
brunhilda.cpp:36:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   if (pt < last.size()) {
      |       ~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...