Submission #31850

#TimeUsernameProblemLanguageResultExecution timeMemory
31850ToMo01Brunhilda’s Birthday (BOI13_brunhilda)C++14
13.33 / 100
73 ms66244 KiB
/*input
2 2
2 3
5
6
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 10000007;

int cost[N], p[100007], n, Q;
vector<pair<int, int> > v;

int main(){
	iostream::sync_with_stdio(false); cin.tie(0);
	cin >> n >> Q;
	for(int i = 1; i <= n; ++i)
		cin >> p[i];
	sort(p + 1, p + n + 1);

	for(int i = p[n] - 1; i > 0; --i)
		cost[i] = 1;

	for(int i = 1; i <= n; ++i)
		v.push_back({p[i], i});

	int l = 0;
	for(int i = 1; i < N; ++i){
		if(cost[i] == 1) continue;
		while(v[l].first + p[v[l].second] - 1 < i) v.push_back({v[l].first + p[v[l].second], v[l++].second});
		if(v[l].first < i) cost[i] = cost[v[l].first] + 1;
		else cost[i] = N;
	}	

	while(Q--){
		int x; cin >> x;
		if(cost[x] == N) cout << "oo\n";
		else cout << cost[x] << "\n";
	}
}

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:30:103: warning: operation on 'l' may be undefined [-Wsequence-point]
   while(v[l].first + p[v[l].second] - 1 < i) v.push_back({v[l].first + p[v[l].second], v[l++].second});
                                                                                                       ^
brunhilda.cpp:30:103: warning: operation on 'l' may be undefined [-Wsequence-point]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...