답안 #493708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493708 2021-12-12T16:20:53 Z _Monkey_ Brunhilda’s Birthday (BOI13_brunhilda) C++17
51.4286 / 100
1000 ms 39900 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define el '\n'
#define ld long double
const int maxn=1e5+1,nn=1e7+1;
int a[maxn],n,m,q,p,oo,ans,k,f[nn];
int t;
bool ok;
void check(){
    t=1;
    ok=0;
    for(int i=0;i<m;++i){
        k=t*a[i];
        if(t*a[i]<t || t*a[i]>oo || k/a[i]!=t){
            ok=1;
            return;
        }
        t=t*a[i];
    }
}
int sol(int z){
    if(f[z]>=0) return f[z];
    int ma=0;
    for(int i=m-1;i>=0;--i){
        if(ma>=a[i]) break;
        if(z%a[i]>ma) ma=z%a[i];
    }
    return sol(z-ma)+1;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> m >> q;
    for(int i=0;i<m;++i) cin >> a[i];
    sort(a+0,a+m);
    memset(f,-1,sizeof f);
    f[0]=0;
    oo=1e7;
    check();
    while(q--){
        cin >> n;
        if(ok){
            cout << sol(n);
        } else {
            if(n>=t){
                cout << "oo";
            } else {
                cout << sol(n);
            }
        }
        cout << el;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 39408 KB Output is correct
2 Correct 17 ms 39456 KB Output is correct
3 Correct 16 ms 39460 KB Output is correct
4 Correct 18 ms 39420 KB Output is correct
5 Correct 16 ms 39500 KB Output is correct
6 Correct 17 ms 39384 KB Output is correct
7 Correct 16 ms 39372 KB Output is correct
8 Correct 14 ms 39408 KB Output is correct
9 Correct 15 ms 39372 KB Output is correct
10 Correct 17 ms 39424 KB Output is correct
11 Correct 17 ms 39372 KB Output is correct
12 Correct 20 ms 39436 KB Output is correct
13 Correct 22 ms 39460 KB Output is correct
14 Correct 39 ms 39428 KB Output is correct
15 Correct 16 ms 39400 KB Output is correct
16 Correct 16 ms 39372 KB Output is correct
17 Correct 21 ms 39440 KB Output is correct
18 Correct 20 ms 39436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 39492 KB Output is correct
2 Correct 32 ms 39748 KB Output is correct
3 Correct 24 ms 39628 KB Output is correct
4 Correct 16 ms 39372 KB Output is correct
5 Correct 21 ms 39580 KB Output is correct
6 Correct 16 ms 39460 KB Output is correct
7 Correct 16 ms 39440 KB Output is correct
8 Correct 17 ms 39376 KB Output is correct
9 Correct 21 ms 39620 KB Output is correct
10 Correct 21 ms 39708 KB Output is correct
11 Correct 18 ms 39532 KB Output is correct
12 Correct 18 ms 39356 KB Output is correct
13 Correct 16 ms 39424 KB Output is correct
14 Correct 18 ms 39472 KB Output is correct
15 Correct 19 ms 39500 KB Output is correct
16 Correct 30 ms 39784 KB Output is correct
17 Correct 16 ms 39356 KB Output is correct
18 Correct 35 ms 39716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1099 ms 39644 KB Time limit exceeded
2 Execution timed out 1080 ms 39648 KB Time limit exceeded
3 Execution timed out 1088 ms 39760 KB Time limit exceeded
4 Execution timed out 1081 ms 39588 KB Time limit exceeded
5 Execution timed out 1066 ms 39820 KB Time limit exceeded
6 Execution timed out 1066 ms 39744 KB Time limit exceeded
7 Execution timed out 1087 ms 39824 KB Time limit exceeded
8 Execution timed out 1092 ms 39888 KB Time limit exceeded
9 Execution timed out 1051 ms 39644 KB Time limit exceeded
10 Correct 411 ms 39612 KB Output is correct
11 Correct 596 ms 39596 KB Output is correct
12 Correct 707 ms 39624 KB Output is correct
13 Execution timed out 1089 ms 39668 KB Time limit exceeded
14 Execution timed out 1092 ms 39436 KB Time limit exceeded
15 Correct 981 ms 39604 KB Output is correct
16 Correct 930 ms 39512 KB Output is correct
17 Execution timed out 1071 ms 39744 KB Time limit exceeded
18 Execution timed out 1075 ms 39748 KB Time limit exceeded
19 Correct 319 ms 39512 KB Output is correct
20 Execution timed out 1095 ms 39796 KB Time limit exceeded
21 Execution timed out 1088 ms 39444 KB Time limit exceeded
22 Execution timed out 1097 ms 39836 KB Time limit exceeded
23 Execution timed out 1086 ms 39568 KB Time limit exceeded
24 Execution timed out 1093 ms 39900 KB Time limit exceeded
25 Execution timed out 1086 ms 39716 KB Time limit exceeded
26 Execution timed out 1096 ms 39844 KB Time limit exceeded
27 Execution timed out 1098 ms 39820 KB Time limit exceeded
28 Execution timed out 1080 ms 39728 KB Time limit exceeded
29 Execution timed out 1089 ms 39824 KB Time limit exceeded
30 Execution timed out 1087 ms 39776 KB Time limit exceeded
31 Execution timed out 1090 ms 39744 KB Time limit exceeded
32 Execution timed out 1088 ms 39644 KB Time limit exceeded
33 Correct 694 ms 39736 KB Output is correct
34 Execution timed out 1091 ms 39824 KB Time limit exceeded
35 Execution timed out 1083 ms 39744 KB Time limit exceeded
36 Execution timed out 1089 ms 39792 KB Time limit exceeded
37 Execution timed out 1085 ms 39824 KB Time limit exceeded
38 Execution timed out 1084 ms 39800 KB Time limit exceeded
39 Execution timed out 1080 ms 39856 KB Time limit exceeded
40 Execution timed out 1092 ms 39628 KB Time limit exceeded
41 Correct 36 ms 39896 KB Output is correct
42 Execution timed out 1074 ms 39492 KB Time limit exceeded