Submission #90476

# Submission time Handle Problem Language Result Execution time Memory
90476 2018-12-21T19:26:14 Z radoslav11 Brunhilda’s Birthday (BOI13_brunhilda) C++14
1.11111 / 100
1000 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];
}

forward_list<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].push_front(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;
}

# Verdict Execution time Memory Grader output
1 Correct 411 ms 174072 KB Output is correct
2 Runtime error 340 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 341 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 434 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
5 Runtime error 742 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
6 Runtime error 378 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
7 Runtime error 327 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 315 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 341 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 344 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 342 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 345 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
13 Runtime error 337 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 336 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 328 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 345 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Execution timed out 1080 ms 263168 KB Time limit exceeded
18 Runtime error 406 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
# Verdict Execution time Memory Grader output
1 Runtime error 879 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Runtime error 255 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
3 Runtime error 344 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 866 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 345 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 311 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 781 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
8 Execution timed out 1094 ms 263168 KB Time limit exceeded
9 Runtime error 356 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 301 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 500 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 313 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 707 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
14 Runtime error 687 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 329 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 257 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
17 Runtime error 345 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 438 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 345 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 340 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 341 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 336 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 801 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
6 Runtime error 339 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 914 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 343 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 329 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 438 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 643 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 316 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 323 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 294 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 302 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 293 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 324 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 277 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 880 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
20 Runtime error 286 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 276 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 296 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Execution timed out 1077 ms 263168 KB Time limit exceeded
24 Runtime error 802 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
25 Runtime error 361 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 335 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 343 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Execution timed out 1086 ms 263168 KB Time limit exceeded
29 Runtime error 821 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Execution timed out 1014 ms 263168 KB Time limit exceeded
31 Execution timed out 1087 ms 263168 KB Time limit exceeded
32 Runtime error 657 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Runtime error 492 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
34 Runtime error 733 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Execution timed out 1092 ms 263168 KB Time limit exceeded
36 Runtime error 341 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 819 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
38 Runtime error 329 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Execution timed out 1086 ms 263168 KB Time limit exceeded
40 Runtime error 319 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Execution timed out 1094 ms 263168 KB Time limit exceeded
42 Runtime error 312 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)