답안 #90470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90470 2018-12-21T19:19:08 Z radoslav11 Brunhilda’s Birthday (BOI13_brunhilda) C++14
0 / 100
284 ms 263168 KB
/*
	There is a simple solution with upper bound on the time equal to O(MAX * log(log(MAX)) * log(MAX)) with DP and maintaining a heap. Probably the actual complexity is smaller.
*/

#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
const int B = (int)1e7 + 42;
const int inf = B + 42;

int n, q;
int dp[B + 42], cnt[inf + 42];
int a[MAXN];

void read()
{
	cin >> n >> q;
	for(int i = 0; i < n; i++)
		cin >> a[i];
}

vector<int> li[B + 42];
priority_queue<int, vector<int>, greater<int> > Q;
int last[MAXN];

void fix()
{
	while(!Q.empty() && cnt[Q.top()])
	{
		cnt[Q.top()]--;
		Q.pop();
	}
}

void solve()
{
	for(int i = 0; i < a[n - 1]; i++) dp[i] = 1;
	for(int i = a[n - 1]; i <= B; i++) dp[i] = inf;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j <= B; j += a[i])
			if(dp[j] != 1)
				li[j].pb(i);
	}

	for(int i = 0; i < n - 1; i++)
		Q.push(1), last[i] = 1;

	for(int d = a[n - 1]; d <= B; d++)
	{
		for(int i: li[d]) cnt[last[i]]++;
		fix();	
		if(!Q.empty()) 
			chkmin(dp[d], Q.top() + 1);
	
		for(int i: li[d])
		{
			Q.push(dp[d]);
			last[i] = dp[d];
		}
	}

	while(q--)
	{
		int x;
		cin >> x;
		if(dp[x] == inf) cout << "oo" << endl;
		else cout << dp[x] << endl;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	read();
	solve();
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Runtime error 190 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 213 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 209 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 203 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 209 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 211 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 211 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 193 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 209 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 209 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 181 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 181 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 184 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 185 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 180 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 187 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 182 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 166 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 189 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 219 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 197 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 209 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 284 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 257 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 182 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 208 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 215 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 219 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 211 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 214 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 208 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 212 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 212 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 218 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 183 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 206 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 237 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 192 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 191 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 181 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 218 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 221 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 189 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 195 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 197 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 206 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 214 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 210 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 219 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 171 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 170 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 217 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 186 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 183 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 229 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 174 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 214 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 201 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 219 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 208 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 205 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 210 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 210 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 212 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 219 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Runtime error 219 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
31 Runtime error 221 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Runtime error 195 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Runtime error 193 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 225 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 195 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 220 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 223 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 202 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 203 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Runtime error 220 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 217 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 213 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)