Submission #71434

# Submission time Handle Problem Language Result Execution time Memory
71434 2018-08-24T14:09:09 Z someone_aa Brunhilda’s Birthday (BOI13_brunhilda) C++17
3.33333 / 100
1000 ms 263168 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxu = 10000100;
const int maxn = 100100;
bool prime[maxu], exist[maxu];
int primes[maxn], qi[maxn], dp[maxu], n, m, q;
int ind[maxn], tree[4*maxn], maxq, inf, maxx;
vector<int>p[maxu];

void sieve() {
    memset(prime,true,sizeof(prime));
    prime[0] = prime[1] = false;
    for(int i=2;i<maxx;i++) {
        if(prime[i]) {
            for(int j=i;j<maxx;j+=i) {
                if(exist[i])
                    p[j].pb(ind[i]);
                if(j > i) prime[j] = false;
            }
        }
    }
}

void update(int x, int val, int li=0, int ri=n-1, int index=1) {
    if(li==ri) tree[index] = val;
    else {
        int mid = (li+ri)/2;
        if(x <= mid) update(x,val,li,mid,2*index);
        else if(x>mid) update(x,val,mid+1,ri,2*index+1);
        tree[index] = min(tree[2*index], tree[2*index+1]);
    }
}

void solve() {
    inf = 1000000000;
    for(int i=1;i<=maxq;i++) {
        for(int j:p[i]) {
            update(j, inf);
        }
        dp[i] = tree[1] + 1;
        for(int j:p[i]) {
            update(j, dp[i]);
        }
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>q;
    for(int i=0;i<n;i++) {
        cin>>primes[i];
        exist[primes[i]] = true;
        ind[primes[i]] = i;
        maxx = max(maxx, primes[i] + 2);
    }

    sieve();
    for(int i=0;i<q;i++) {
        cin>>qi[i];
        maxq = max(maxq, qi[i]);
    }
    solve();
    for(int i=0;i<q;i++) {
        if(dp[qi[i]] >= inf) cout<<"oo\n";
        else cout<<dp[qi[i]]<<"\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 244984 KB Output isn't correct
2 Incorrect 228 ms 245224 KB Output isn't correct
3 Incorrect 246 ms 245252 KB Output isn't correct
4 Incorrect 226 ms 245528 KB Output isn't correct
5 Incorrect 226 ms 245528 KB Output isn't correct
6 Incorrect 226 ms 245528 KB Output isn't correct
7 Incorrect 243 ms 245528 KB Output isn't correct
8 Incorrect 250 ms 245528 KB Output isn't correct
9 Incorrect 238 ms 245528 KB Output isn't correct
10 Incorrect 237 ms 245644 KB Output isn't correct
11 Incorrect 220 ms 245644 KB Output isn't correct
12 Correct 234 ms 245644 KB Output is correct
13 Correct 228 ms 245820 KB Output is correct
14 Correct 241 ms 245908 KB Output is correct
15 Incorrect 228 ms 245908 KB Output isn't correct
16 Incorrect 225 ms 245908 KB Output isn't correct
17 Incorrect 263 ms 245908 KB Output isn't correct
18 Incorrect 230 ms 245908 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 603 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
2 Execution timed out 1045 ms 263168 KB Time limit exceeded
3 Execution timed out 1026 ms 263168 KB Time limit exceeded
4 Runtime error 497 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
5 Execution timed out 1046 ms 263168 KB Time limit exceeded
6 Runtime error 247 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
7 Runtime error 590 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
8 Runtime error 239 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
9 Execution timed out 1048 ms 263168 KB Time limit exceeded
10 Execution timed out 1085 ms 263168 KB Time limit exceeded
11 Execution timed out 1029 ms 263168 KB Time limit exceeded
12 Runtime error 470 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
13 Runtime error 540 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
14 Runtime error 492 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
15 Execution timed out 1046 ms 263168 KB Time limit exceeded
16 Execution timed out 1042 ms 263168 KB Time limit exceeded
17 Runtime error 523 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
18 Execution timed out 1072 ms 263168 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1106 ms 263168 KB Time limit exceeded
2 Execution timed out 1031 ms 263168 KB Time limit exceeded
3 Execution timed out 1062 ms 263168 KB Time limit exceeded
4 Runtime error 541 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
5 Execution timed out 1068 ms 263168 KB Time limit exceeded
6 Runtime error 631 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
7 Execution timed out 1081 ms 263168 KB Time limit exceeded
8 Execution timed out 1105 ms 263168 KB Time limit exceeded
9 Execution timed out 1109 ms 263168 KB Time limit exceeded
10 Runtime error 479 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
11 Runtime error 515 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
12 Runtime error 579 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
13 Execution timed out 1037 ms 263168 KB Time limit exceeded
14 Runtime error 384 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
15 Runtime error 583 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
16 Runtime error 589 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
17 Execution timed out 1039 ms 263168 KB Time limit exceeded
18 Execution timed out 1114 ms 263168 KB Time limit exceeded
19 Runtime error 831 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
20 Execution timed out 1050 ms 263168 KB Time limit exceeded
21 Runtime error 518 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
22 Execution timed out 1040 ms 263168 KB Time limit exceeded
23 Runtime error 759 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
24 Runtime error 554 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
25 Runtime error 616 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
26 Runtime error 576 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
27 Execution timed out 1102 ms 263168 KB Time limit exceeded
28 Runtime error 552 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
29 Execution timed out 1067 ms 263168 KB Time limit exceeded
30 Execution timed out 1063 ms 263168 KB Time limit exceeded
31 Runtime error 706 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
32 Runtime error 641 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
33 Runtime error 518 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
34 Execution timed out 1115 ms 263168 KB Time limit exceeded
35 Runtime error 586 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
36 Execution timed out 1049 ms 263168 KB Time limit exceeded
37 Execution timed out 720 ms 263168 KB Time limit exceeded (wall clock)
38 Runtime error 701 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
39 Runtime error 577 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
40 Runtime error 818 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 696 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 632 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.