답안 #77371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77371 2018-09-26T23:17:23 Z xiaowuc1 Brunhilda’s Birthday (BOI13_brunhilda) C++14
100 / 100
69 ms 39564 KB
#include <bits/stdc++.h>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

int primes[100000];
int thresh[10000000];

int main() {
  int n;
  int q;
  scanf("%d%d", &n, &q);
  for(int i = n-1; i >= 0; i--) {
    scanf("%d", &primes[i]);
  }
  thresh[1] = primes[0]-1;
  int ans = 2;
  while(thresh[ans-1] <= 10000000) {
    int last = thresh[ans-1];
    int best = last;
    for(int i = 0; i < n; i++) {
      if((last+1)%primes[i] == 0) continue;
      int t = last - (last) % primes[i] + primes[i] - 1;
      if(t > best) {
        best = t;
      }
      if(last + primes[i] - 1 <= best) break;
    }
    if(last == best) break;
    thresh[ans++] = best;
    last = best;
  }
  ans--;
  while(q--) {
    int goal;
    scanf("%d", &goal);
    if(goal > thresh[ans]) {
      printf("oo\n");
    }
    else {
      int lhs = 1;
      int rhs = ans;
      while(lhs != rhs) {
        int mid = (lhs+rhs)/2;
        if(thresh[mid] < goal) lhs = mid+1;
        else rhs = mid;
      }
      printf("%d\n", lhs);
    }
  }
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &q);
   ~~~~~^~~~~~~~~~~~~~~~
brunhilda.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &primes[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~
brunhilda.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &goal);
     ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 520 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 5 ms 584 KB Output is correct
5 Correct 13 ms 1304 KB Output is correct
6 Correct 2 ms 1304 KB Output is correct
7 Correct 2 ms 1304 KB Output is correct
8 Correct 3 ms 1304 KB Output is correct
9 Correct 14 ms 1728 KB Output is correct
10 Correct 6 ms 1728 KB Output is correct
11 Correct 10 ms 1728 KB Output is correct
12 Correct 2 ms 1728 KB Output is correct
13 Correct 3 ms 1728 KB Output is correct
14 Correct 5 ms 1728 KB Output is correct
15 Correct 5 ms 1728 KB Output is correct
16 Correct 5 ms 1728 KB Output is correct
17 Correct 7 ms 1728 KB Output is correct
18 Correct 5 ms 1728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1728 KB Output is correct
2 Correct 17 ms 2120 KB Output is correct
3 Correct 13 ms 2524 KB Output is correct
4 Correct 2 ms 2524 KB Output is correct
5 Correct 10 ms 2808 KB Output is correct
6 Correct 2 ms 2808 KB Output is correct
7 Correct 4 ms 2844 KB Output is correct
8 Correct 2 ms 2844 KB Output is correct
9 Correct 12 ms 3556 KB Output is correct
10 Correct 12 ms 4072 KB Output is correct
11 Correct 8 ms 4160 KB Output is correct
12 Correct 2 ms 4160 KB Output is correct
13 Correct 2 ms 4160 KB Output is correct
14 Correct 3 ms 4160 KB Output is correct
15 Correct 8 ms 4476 KB Output is correct
16 Correct 16 ms 5396 KB Output is correct
17 Correct 2 ms 5396 KB Output is correct
18 Correct 19 ms 6124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 6720 KB Output is correct
2 Correct 17 ms 7240 KB Output is correct
3 Correct 23 ms 8032 KB Output is correct
4 Correct 32 ms 8680 KB Output is correct
5 Correct 45 ms 10528 KB Output is correct
6 Correct 35 ms 11032 KB Output is correct
7 Correct 50 ms 12312 KB Output is correct
8 Correct 22 ms 12840 KB Output is correct
9 Correct 26 ms 13404 KB Output is correct
10 Correct 8 ms 13404 KB Output is correct
11 Correct 10 ms 13620 KB Output is correct
12 Correct 10 ms 13820 KB Output is correct
13 Correct 32 ms 15032 KB Output is correct
14 Correct 38 ms 16184 KB Output is correct
15 Correct 12 ms 16184 KB Output is correct
16 Correct 14 ms 16184 KB Output is correct
17 Correct 12 ms 16352 KB Output is correct
18 Correct 19 ms 17000 KB Output is correct
19 Correct 9 ms 17024 KB Output is correct
20 Correct 24 ms 17992 KB Output is correct
21 Correct 34 ms 19152 KB Output is correct
22 Correct 45 ms 20576 KB Output is correct
23 Correct 36 ms 21296 KB Output is correct
24 Correct 35 ms 21900 KB Output is correct
25 Correct 38 ms 22760 KB Output is correct
26 Correct 33 ms 23376 KB Output is correct
27 Correct 30 ms 24712 KB Output is correct
28 Correct 31 ms 25308 KB Output is correct
29 Correct 69 ms 27148 KB Output is correct
30 Correct 41 ms 28252 KB Output is correct
31 Correct 32 ms 28752 KB Output is correct
32 Correct 34 ms 29588 KB Output is correct
33 Correct 32 ms 30216 KB Output is correct
34 Correct 31 ms 31552 KB Output is correct
35 Correct 31 ms 32200 KB Output is correct
36 Correct 46 ms 33896 KB Output is correct
37 Correct 47 ms 35496 KB Output is correct
38 Correct 36 ms 35936 KB Output is correct
39 Correct 36 ms 36700 KB Output is correct
40 Correct 36 ms 37484 KB Output is correct
41 Correct 33 ms 38888 KB Output is correct
42 Correct 31 ms 39564 KB Output is correct