Submission #313955

# Submission time Handle Problem Language Result Execution time Memory
313955 2020-10-17T15:15:10 Z shivensinha4 Brunhilda’s Birthday (BOI13_brunhilda) C++17
0 / 100
307 ms 262148 KB
#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 = 1e7;
vi facs[MXV+2];
int ans[MXV+2], curVal[MXV+2];


int main() {
	#ifdef shiven
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, q; cin >> n >> q;
	vi primes(n);
	for_(i, 0, n) cin >> primes[i];
	for (int i: primes) for (int j = i; j <= MXV; j += i) facs[j].push_back(i);
	
	multiset<int> vals;
	for (int i: primes) vals.insert(0);
	
	for_(i, 1, MXV+1) {
		for (auto p: facs[i]) vals.erase(vals.find(curVal[p]));
		if (vals.size()) ans[i] = *vals.begin()+1;
		else ans[i] = -1;
		for (auto p: facs[i]) vals.insert(curVal[p] = ans[i]);
	}
	
	for_(x, 0, q) {
		int k; cin >> k;
		if (ans[k] == -1) cout << "oo";
		else cout << ans[k];
		cout << endl;
	}

	return 0;
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:29:11: warning: unused variable 'i' [-Wunused-variable]
   29 |  for (int i: primes) vals.insert(0);
      |           ^
# Verdict Execution time Memory Grader output
1 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 184 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 259 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 177 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 181 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 174 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 176 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 178 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 279 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 178 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 175 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 178 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 196 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 267 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 267 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 207 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 179 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 182 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 268 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 185 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 178 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 179 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 179 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 211 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 189 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 183 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 177 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 179 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 175 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 307 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 195 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 181 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 184 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 174 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 182 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 174 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 175 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 182 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 182 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 176 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 182 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 174 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 193 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 301 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 191 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 177 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 189 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 174 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 186 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Runtime error 188 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
31 Runtime error 180 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Runtime error 183 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Runtime error 218 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 191 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 187 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 307 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 177 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 193 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Runtime error 176 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 187 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 174 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)