답안 #31287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31287 2017-08-17T21:13:46 Z imaxblue Brunhilda’s Birthday (BOI13_brunhilda) C++14
100 / 100
459 ms 81368 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define foxr1(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)

int n, q, x, t, l2, k, lo=(1 << 30), dp[10000005], f[10000005];
vector<bool> p=vector<bool>(10000005);
int main(){
    scanf("%i%i", &n, &q);
    fox(l, n){
        scanf("%i", &x);
        p[x]=1;
        lo=min(lo, 10000000/x*x);
    }
    for(int l=2; l<=10000000; l++){
        if (f[l]!=0) continue;
        if (p[l]) k=l; else k=-1;
        if (k==-1){
            if (l>10000) continue;
            for (l2=l*l; l2<=10000000; l2+=l){
                f[l2]=(f[l2]==0) ? -1 : f[l2];
            }
        } else {
            for (l2=l; l2<=10000000; l2+=l){
                f[l2]=l;
            }
        }
    }
    foxr1(l, 10000000){
        t=lo;
        lo=min(lo, l-max(0, f[l]));
        f[l]=t;
        //cout << f[l] << endl;
    }
    fox1(l, 10000000){
        if (f[l]==l) dp[l]=(1 << 30);
        dp[l]=dp[f[l]]+1;
    }
    fox(l, q){
        scanf("%i", &x);
        if (dp[x]>=(1 << 30)){
            printf("oo\n");
        }
        else {
            printf("%i\n", dp[x]);
        }
    }
    return 0;
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:29:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i", &n, &q);
                          ^
brunhilda.cpp:31:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i", &x);
                        ^
brunhilda.cpp:60:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i", &x);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 81368 KB Output is correct
2 Correct 269 ms 81368 KB Output is correct
3 Correct 263 ms 81368 KB Output is correct
4 Correct 256 ms 81368 KB Output is correct
5 Correct 269 ms 81368 KB Output is correct
6 Correct 259 ms 81368 KB Output is correct
7 Correct 216 ms 81368 KB Output is correct
8 Correct 253 ms 81368 KB Output is correct
9 Correct 263 ms 81368 KB Output is correct
10 Correct 246 ms 81368 KB Output is correct
11 Correct 169 ms 81368 KB Output is correct
12 Correct 209 ms 81368 KB Output is correct
13 Correct 289 ms 81368 KB Output is correct
14 Correct 299 ms 81368 KB Output is correct
15 Correct 249 ms 81368 KB Output is correct
16 Correct 269 ms 81368 KB Output is correct
17 Correct 233 ms 81368 KB Output is correct
18 Correct 259 ms 81368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 299 ms 81368 KB Output is correct
2 Correct 306 ms 81368 KB Output is correct
3 Correct 423 ms 81368 KB Output is correct
4 Correct 229 ms 81368 KB Output is correct
5 Correct 343 ms 81368 KB Output is correct
6 Correct 279 ms 81368 KB Output is correct
7 Correct 263 ms 81368 KB Output is correct
8 Correct 276 ms 81368 KB Output is correct
9 Correct 329 ms 81368 KB Output is correct
10 Correct 306 ms 81368 KB Output is correct
11 Correct 296 ms 81368 KB Output is correct
12 Correct 216 ms 81368 KB Output is correct
13 Correct 276 ms 81368 KB Output is correct
14 Correct 223 ms 81368 KB Output is correct
15 Correct 356 ms 81368 KB Output is correct
16 Correct 286 ms 81368 KB Output is correct
17 Correct 336 ms 81368 KB Output is correct
18 Correct 399 ms 81368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 393 ms 81368 KB Output is correct
2 Correct 436 ms 81368 KB Output is correct
3 Correct 423 ms 81368 KB Output is correct
4 Correct 266 ms 81368 KB Output is correct
5 Correct 379 ms 81368 KB Output is correct
6 Correct 353 ms 81368 KB Output is correct
7 Correct 393 ms 81368 KB Output is correct
8 Correct 389 ms 81368 KB Output is correct
9 Correct 409 ms 81368 KB Output is correct
10 Correct 313 ms 81368 KB Output is correct
11 Correct 343 ms 81368 KB Output is correct
12 Correct 289 ms 81368 KB Output is correct
13 Correct 409 ms 81368 KB Output is correct
14 Correct 279 ms 81368 KB Output is correct
15 Correct 333 ms 81368 KB Output is correct
16 Correct 289 ms 81368 KB Output is correct
17 Correct 383 ms 81368 KB Output is correct
18 Correct 429 ms 81368 KB Output is correct
19 Correct 283 ms 81368 KB Output is correct
20 Correct 376 ms 81368 KB Output is correct
21 Correct 239 ms 81368 KB Output is correct
22 Correct 426 ms 81368 KB Output is correct
23 Correct 353 ms 81368 KB Output is correct
24 Correct 309 ms 81368 KB Output is correct
25 Correct 376 ms 81368 KB Output is correct
26 Correct 346 ms 81368 KB Output is correct
27 Correct 369 ms 81368 KB Output is correct
28 Correct 319 ms 81368 KB Output is correct
29 Correct 459 ms 81368 KB Output is correct
30 Correct 383 ms 81368 KB Output is correct
31 Correct 279 ms 81368 KB Output is correct
32 Correct 343 ms 81368 KB Output is correct
33 Correct 213 ms 81368 KB Output is correct
34 Correct 369 ms 81368 KB Output is correct
35 Correct 333 ms 81368 KB Output is correct
36 Correct 449 ms 81368 KB Output is correct
37 Correct 286 ms 81368 KB Output is correct
38 Correct 396 ms 81368 KB Output is correct
39 Correct 329 ms 81368 KB Output is correct
40 Correct 416 ms 81368 KB Output is correct
41 Correct 349 ms 81368 KB Output is correct
42 Correct 363 ms 81368 KB Output is correct