Submission #631288

# Submission time Handle Problem Language Result Execution time Memory
631288 2022-08-18T02:44:24 Z TranGiaHuy1508 Brunhilda’s Birthday (BOI13_brunhilda) C++17
10.3175 / 100
1000 ms 1204 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, mx = 0;
		while (x){
			for (auto j: v){
				if (mx >= j-1) break;
				mx = max(mx, x % j);
			}
			if (mx == 0) break;
			x -= mx; res++;
		}
		if (x) cout << "oo\n";
		else 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:102:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |    freopen(".inp", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~
brunhilda.cpp:103:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |    freopen(".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1099 ms 212 KB Time limit exceeded
2 Execution timed out 1049 ms 212 KB Time limit exceeded
3 Execution timed out 1090 ms 212 KB Time limit exceeded
4 Execution timed out 1081 ms 212 KB Time limit exceeded
5 Execution timed out 1070 ms 212 KB Time limit exceeded
6 Execution timed out 1073 ms 216 KB Time limit exceeded
7 Execution timed out 1064 ms 212 KB Time limit exceeded
8 Execution timed out 1079 ms 212 KB Time limit exceeded
9 Execution timed out 1096 ms 212 KB Time limit exceeded
10 Execution timed out 1006 ms 212 KB Time limit exceeded
11 Execution timed out 1070 ms 212 KB Time limit exceeded
12 Correct 1 ms 256 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 23 ms 340 KB Output is correct
15 Execution timed out 1084 ms 212 KB Time limit exceeded
16 Execution timed out 1088 ms 212 KB Time limit exceeded
17 Execution timed out 1070 ms 212 KB Time limit exceeded
18 Execution timed out 1068 ms 212 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Correct 29 ms 980 KB Output is correct
3 Execution timed out 1094 ms 852 KB Time limit exceeded
4 Incorrect 1 ms 340 KB Output isn't correct
5 Execution timed out 1083 ms 724 KB Time limit exceeded
6 Execution timed out 1091 ms 212 KB Time limit exceeded
7 Incorrect 2 ms 340 KB Output isn't correct
8 Execution timed out 1073 ms 212 KB Time limit exceeded
9 Correct 7 ms 852 KB Output is correct
10 Execution timed out 1078 ms 852 KB Time limit exceeded
11 Execution timed out 1076 ms 596 KB Time limit exceeded
12 Incorrect 1 ms 340 KB Output isn't correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 10 ms 980 KB Output is correct
17 Execution timed out 1093 ms 212 KB Time limit exceeded
18 Execution timed out 1083 ms 1108 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 724 KB Time limit exceeded
2 Execution timed out 1097 ms 724 KB Time limit exceeded
3 Execution timed out 1063 ms 724 KB Time limit exceeded
4 Execution timed out 1088 ms 340 KB Time limit exceeded
5 Execution timed out 1073 ms 1080 KB Time limit exceeded
6 Execution timed out 1085 ms 340 KB Time limit exceeded
7 Execution timed out 1059 ms 1108 KB Time limit exceeded
8 Execution timed out 1096 ms 596 KB Time limit exceeded
9 Execution timed out 1094 ms 724 KB Time limit exceeded
10 Execution timed out 1063 ms 340 KB Time limit exceeded
11 Execution timed out 1075 ms 340 KB Time limit exceeded
12 Execution timed out 1049 ms 340 KB Time limit exceeded
13 Execution timed out 1088 ms 468 KB Time limit exceeded
14 Execution timed out 1098 ms 212 KB Time limit exceeded
15 Execution timed out 1091 ms 340 KB Time limit exceeded
16 Execution timed out 1090 ms 340 KB Time limit exceeded
17 Execution timed out 1078 ms 596 KB Time limit exceeded
18 Execution timed out 1063 ms 724 KB Time limit exceeded
19 Execution timed out 1083 ms 340 KB Time limit exceeded
20 Execution timed out 1095 ms 724 KB Time limit exceeded
21 Execution timed out 1064 ms 212 KB Time limit exceeded
22 Execution timed out 1081 ms 1108 KB Time limit exceeded
23 Execution timed out 1071 ms 548 KB Time limit exceeded
24 Execution timed out 1079 ms 212 KB Time limit exceeded
25 Execution timed out 1089 ms 340 KB Time limit exceeded
26 Execution timed out 1084 ms 340 KB Time limit exceeded
27 Execution timed out 1074 ms 1108 KB Time limit exceeded
28 Execution timed out 1070 ms 212 KB Time limit exceeded
29 Execution timed out 1084 ms 1108 KB Time limit exceeded
30 Execution timed out 1095 ms 860 KB Time limit exceeded
31 Execution timed out 1091 ms 340 KB Time limit exceeded
32 Execution timed out 1074 ms 340 KB Time limit exceeded
33 Execution timed out 1099 ms 212 KB Time limit exceeded
34 Execution timed out 1088 ms 1108 KB Time limit exceeded
35 Execution timed out 1083 ms 212 KB Time limit exceeded
36 Execution timed out 1085 ms 1024 KB Time limit exceeded
37 Execution timed out 1085 ms 1108 KB Time limit exceeded
38 Execution timed out 1085 ms 340 KB Time limit exceeded
39 Execution timed out 1080 ms 212 KB Time limit exceeded
40 Execution timed out 1089 ms 340 KB Time limit exceeded
41 Correct 17 ms 1204 KB Output is correct
42 Execution timed out 1099 ms 212 KB Time limit exceeded