Submission #631319

# Submission time Handle Problem Language Result Execution time Memory
631319 2022-08-18T03:15:23 Z mousey Brunhilda’s Birthday (BOI13_brunhilda) C++14
16.9841 / 100
1000 ms 79272 KB
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define vllp vector<pair<ll, ll> >
#define pdb pair <double, double> 
#define YES cout<<"YES"
#define NO cout<<"NO"
#define endl cout<<"\n"
#define vv vector <vector <ll> >
#define pll pair <ll, ll> 
#define mp make_pair
#define pb push_back
#define f first
#define s second
using namespace std;

const ll mod=1e9+7;
const ll modx=998244353;
const double eps=1e-9;
const ll INF=INT_MAX;
const ll INFINF=LLONG_MAX;
const ll N=1e5, MAXN=1e7;
ll n, q;
ll a[N+5];
ll ans[MAXN+5];
ll product=1;

void input()
{
	cin >> n >> q;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		product*=a[i];
		if(product>=MAXN) product=MAXN;
	}
}

void solve()
{
	ll cur=n;
	for(int i = 2; i <= MAXN; i++)
	{
		if(i>=product) 
		{
			ans[i]=INFINF;
			continue;	
		}
		if(i<a[n])
		{
			ans[i]=1;
			continue;
		}
		ll cnt=0;
		ll curmax=0;
		for(int j = n; j >= 1 && a[j] > curmax; j--)
		{
			if(i%a[j]==0)
			{
				cnt++;
				if(cnt>=5) break;
			}
			curmax=max(curmax, i%a[j]);
		}
		ans[i]=ans[i-curmax]+1;
	}
	while(q--)
	{
		ll x;
		cin >> x;
		if(ans[x]==INFINF) cout << "oo";
		else cout << ans[x];
		endl;
	}
}

int main() 
{
//	auto start_time = chrono::high_resolution_clock::now();
//	freopen("test.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
    input();
    solve();
//    auto end_time = chrono::high_resolution_clock::now();
//        double duration = chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count();
//        cout << "\n[ " << duration << " ms ]\n"; 
}

Compilation message

brunhilda.cpp: In function 'void solve()':
brunhilda.cpp:41:5: warning: unused variable 'cur' [-Wunused-variable]
   41 |  ll cur=n;
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 78548 KB Output is correct
2 Correct 588 ms 78732 KB Output is correct
3 Correct 38 ms 78540 KB Output is correct
4 Correct 544 ms 78616 KB Output is correct
5 Correct 327 ms 78476 KB Output is correct
6 Correct 36 ms 78560 KB Output is correct
7 Correct 39 ms 78528 KB Output is correct
8 Correct 47 ms 78556 KB Output is correct
9 Correct 203 ms 78484 KB Output is correct
10 Correct 215 ms 78544 KB Output is correct
11 Correct 234 ms 78568 KB Output is correct
12 Execution timed out 1098 ms 76176 KB Time limit exceeded
13 Execution timed out 1095 ms 36712 KB Time limit exceeded
14 Execution timed out 1095 ms 36116 KB Time limit exceeded
15 Correct 453 ms 78564 KB Output is correct
16 Correct 585 ms 78532 KB Output is correct
17 Incorrect 449 ms 78628 KB Output isn't correct
18 Correct 552 ms 78704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 7776 KB Time limit exceeded
2 Execution timed out 1098 ms 71616 KB Time limit exceeded
3 Execution timed out 1085 ms 20504 KB Time limit exceeded
4 Execution timed out 1086 ms 5268 KB Time limit exceeded
5 Execution timed out 1095 ms 10920 KB Time limit exceeded
6 Execution timed out 1096 ms 29644 KB Time limit exceeded
7 Execution timed out 1083 ms 7888 KB Time limit exceeded
8 Execution timed out 1092 ms 38980 KB Time limit exceeded
9 Execution timed out 1084 ms 11344 KB Time limit exceeded
10 Execution timed out 1095 ms 20444 KB Time limit exceeded
11 Execution timed out 1073 ms 8520 KB Time limit exceeded
12 Execution timed out 1088 ms 17956 KB Time limit exceeded
13 Execution timed out 1073 ms 5868 KB Time limit exceeded
14 Execution timed out 1089 ms 5360 KB Time limit exceeded
15 Execution timed out 1095 ms 7188 KB Time limit exceeded
16 Execution timed out 1083 ms 71736 KB Time limit exceeded
17 Execution timed out 1073 ms 47232 KB Time limit exceeded
18 Execution timed out 1088 ms 40344 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 8700 KB Time limit exceeded
2 Execution timed out 1093 ms 6356 KB Time limit exceeded
3 Execution timed out 1094 ms 8484 KB Time limit exceeded
4 Execution timed out 1084 ms 5248 KB Time limit exceeded
5 Execution timed out 1093 ms 36060 KB Time limit exceeded
6 Execution timed out 1092 ms 2232 KB Time limit exceeded
7 Execution timed out 1091 ms 23752 KB Time limit exceeded
8 Execution timed out 1090 ms 8804 KB Time limit exceeded
9 Execution timed out 1094 ms 8704 KB Time limit exceeded
10 Execution timed out 1091 ms 2832 KB Time limit exceeded
11 Execution timed out 1085 ms 3612 KB Time limit exceeded
12 Execution timed out 1083 ms 2968 KB Time limit exceeded
13 Execution timed out 1080 ms 7164 KB Time limit exceeded
14 Correct 390 ms 79072 KB Output is correct
15 Execution timed out 1087 ms 3032 KB Time limit exceeded
16 Execution timed out 1086 ms 2716 KB Time limit exceeded
17 Execution timed out 1086 ms 7128 KB Time limit exceeded
18 Execution timed out 1097 ms 6412 KB Time limit exceeded
19 Execution timed out 1093 ms 6760 KB Time limit exceeded
20 Execution timed out 1090 ms 8444 KB Time limit exceeded
21 Incorrect 420 ms 79272 KB Output isn't correct
22 Execution timed out 1088 ms 12992 KB Time limit exceeded
23 Execution timed out 1091 ms 8708 KB Time limit exceeded
24 Execution timed out 1076 ms 32832 KB Time limit exceeded
25 Execution timed out 1071 ms 11320 KB Time limit exceeded
26 Execution timed out 1094 ms 5276 KB Time limit exceeded
27 Execution timed out 1087 ms 14072 KB Time limit exceeded
28 Execution timed out 1057 ms 60928 KB Time limit exceeded
29 Execution timed out 1083 ms 13108 KB Time limit exceeded
30 Execution timed out 1073 ms 8824 KB Time limit exceeded
31 Execution timed out 1098 ms 3812 KB Time limit exceeded
32 Execution timed out 1083 ms 6848 KB Time limit exceeded
33 Execution timed out 1094 ms 14544 KB Time limit exceeded
34 Execution timed out 1059 ms 23368 KB Time limit exceeded
35 Execution timed out 1091 ms 33556 KB Time limit exceeded
36 Execution timed out 1091 ms 12876 KB Time limit exceeded
37 Execution timed out 1053 ms 35932 KB Time limit exceeded
38 Execution timed out 1046 ms 2116 KB Time limit exceeded
39 Execution timed out 1095 ms 8748 KB Time limit exceeded
40 Execution timed out 1086 ms 2504 KB Time limit exceeded
41 Execution timed out 1092 ms 58860 KB Time limit exceeded
42 Execution timed out 1093 ms 37320 KB Time limit exceeded