Submission #631264

# Submission time Handle Problem Language Result Execution time Memory
631264 2022-08-18T01:40:53 Z TranGiaHuy1508 Brunhilda’s Birthday (BOI13_brunhilda) C++17
8.09524 / 100
29 ms 2892 KB
/*
	Unknown's C++ Template (v3.2)
*/

#include "bits/stdc++.h"
using namespace std;

#define int long long

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
template <class T> using maxpq = priority_queue<T>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mid ((l+r)>>1)
#define fi first
#define se second

#ifdef LOCAL
	#define debug(x) cout << #x << " = " << x << "\n";
#else
	#define debug(x) ;
#endif

template <class A, class B>
ostream& operator << (ostream& out, pair<A, B> x)
{ out << "(" << x.first << ", " << x.second << ")"; return out; }

template <class T>
ostream& operator << (ostream& out, vector<T> x){
	out << "[";
	for (int i=0; i<sz(x); i++) { out << (i ? ", " : "") << x[i]; }
	out << "]"; return out;
}

template <class T>
istream& operator >> (istream& in, vector<T> &x){
	for (auto &i: x) in >> i;
	return in;
}

const ld PI = acos(-1.0);
const int allmod[3] = {(int)1e9+7, 998244353, (int)1e9+9};
const int mod = allmod[0];
const int maxn = 2e5 + 64;
const ll inf = 1e18;
const ld eps = 1e-6;
const int multitest = 0;

const int maxval = 1e7;

void main_program(){
	int m, q; cin >> m >> q;
	vi v(m); cin >> v; sort(all(v), greater<int>());

	int LCM = 1;
	for (int i = 0; i < m; i++){
		LCM = lcm(LCM, v[i]);
		if (LCM > maxval) break;
	}

	for (int i = 0; i < q; i++){
		int x; cin >> x;
		if (x >= LCM){
			cout << "oo\n";
			continue;
		}

		int res = 0;
		if (x % v[0]) res++;
		x -= x % v[0];

		int j = 0, crr = 2;
		while (x){
			x /= v[j];
			j++;

			res += crr * (x % v[j]);
			crr *= v[j];
			x -= x % v[j];
		}

		cout << res << "\n";
	}
}

void pre_main(){

}

signed main(){
	#ifdef LOCAL
		auto stime = chrono::high_resolution_clock::now();
	#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
		if (fopen(".inp", "r")){
			freopen(".inp", "r", stdin);
			freopen(".out", "w", stdout);
		}
	#endif
	int t = 1; if (multitest) cin >> t;
	pre_main();
	while (t--) main_program();
	#ifdef LOCAL
		auto etime = chrono::high_resolution_clock::now();
		auto duration = chrono::duration_cast<chrono::milliseconds>(etime-stime).count();
		cout << "\n[" << duration << "ms]\n";
	#endif
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:106:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |    freopen(".inp", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~
brunhilda.cpp:107:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |    freopen(".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 1 ms 324 KB Output isn't correct
7 Incorrect 0 ms 316 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Correct 0 ms 212 KB Output is correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Incorrect 2 ms 380 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Incorrect 1 ms 212 KB Output isn't correct
17 Incorrect 3 ms 332 KB Output isn't correct
18 Incorrect 2 ms 372 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 464 KB Output isn't correct
2 Correct 9 ms 1748 KB Output is correct
3 Correct 6 ms 1252 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 5 ms 980 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Incorrect 2 ms 504 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Incorrect 10 ms 1364 KB Output isn't correct
10 Correct 7 ms 1236 KB Output is correct
11 Incorrect 4 ms 852 KB Output isn't correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 4 ms 852 KB Output isn't correct
16 Correct 10 ms 1676 KB Output is correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Incorrect 10 ms 1744 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1364 KB Output isn't correct
2 Incorrect 9 ms 1244 KB Output isn't correct
3 Incorrect 17 ms 1536 KB Output isn't correct
4 Incorrect 18 ms 1236 KB Output isn't correct
5 Incorrect 24 ms 2744 KB Output isn't correct
6 Incorrect 15 ms 1364 KB Output isn't correct
7 Incorrect 17 ms 2308 KB Output isn't correct
8 Incorrect 10 ms 1492 KB Output isn't correct
9 Incorrect 11 ms 1492 KB Output isn't correct
10 Incorrect 3 ms 464 KB Output isn't correct
11 Incorrect 4 ms 596 KB Output isn't correct
12 Incorrect 5 ms 620 KB Output isn't correct
13 Incorrect 16 ms 1712 KB Output isn't correct
14 Incorrect 22 ms 1612 KB Output isn't correct
15 Incorrect 5 ms 596 KB Output isn't correct
16 Incorrect 4 ms 588 KB Output isn't correct
17 Incorrect 8 ms 980 KB Output isn't correct
18 Incorrect 9 ms 1248 KB Output isn't correct
19 Incorrect 4 ms 592 KB Output isn't correct
20 Incorrect 13 ms 1560 KB Output isn't correct
21 Incorrect 18 ms 1700 KB Output isn't correct
22 Incorrect 26 ms 2756 KB Output isn't correct
23 Incorrect 18 ms 1748 KB Output isn't correct
24 Incorrect 16 ms 1356 KB Output isn't correct
25 Incorrect 15 ms 1352 KB Output isn't correct
26 Incorrect 14 ms 1236 KB Output isn't correct
27 Incorrect 17 ms 2244 KB Output isn't correct
28 Incorrect 16 ms 1448 KB Output isn't correct
29 Incorrect 24 ms 2892 KB Output isn't correct
30 Incorrect 28 ms 2332 KB Output isn't correct
31 Incorrect 14 ms 1232 KB Output isn't correct
32 Incorrect 17 ms 1360 KB Output isn't correct
33 Incorrect 15 ms 1212 KB Output isn't correct
34 Incorrect 18 ms 2260 KB Output isn't correct
35 Incorrect 17 ms 1504 KB Output isn't correct
36 Incorrect 29 ms 2632 KB Output isn't correct
37 Incorrect 26 ms 2760 KB Output isn't correct
38 Incorrect 16 ms 1404 KB Output isn't correct
39 Incorrect 17 ms 1352 KB Output isn't correct
40 Incorrect 15 ms 1408 KB Output isn't correct
41 Correct 17 ms 2372 KB Output is correct
42 Incorrect 16 ms 1496 KB Output isn't correct