답안 #74696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74696 2018-09-06T14:49:30 Z kjain_1810 Brunhilda’s Birthday (BOI13_brunhilda) C++17
97.7778 / 100
342 ms 41296 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ind(n) scanf("%d", &n)
#define ind2(n, m) scanf("%d%d", &n, &m)
#define ind3(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define inlld(n) scanf("%lld", &n)
#define inlld2(n, m) scanf("%lld%lld", &n, &m)
#define inlld3(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)

using namespace std;

const int N=1e7+5;
const int MOD=1e9+7;

typedef long long ll;
typedef long double ld;

int n, q;
int arr[N], dp[N];

int solve(int i)
{
    if(i==0)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    int ans=-1e8, best=0;
    // if(q==1)
    // {
    //     for(int a=n; a>=1; a--)
    //     {
    //         if(i%arr[a]==0)
    //             continue;
    //         if(i%arr[a]>ans)
    //         {
    //             ans=i%arr[a];
    //             best=a;
    //         }
    //     }
    // }
    // else
    // {
        for(int a=n; a>=max(1, n-500); a--)
        {
            if(i%arr[a]==0)
                continue;
            if(i%arr[a]>ans)
            {
                ans=i%arr[a];
                best=a;
            }
        }
    // }
    if(best)
        return dp[i]=solve(i-ans)+1;
    else
        return dp[i]=2e8;
}

signed main()
{
    ind2(n, q);
    for(int a=1; a<=n; a++)
        ind(arr[a]);
    memset(dp, -1, sizeof(dp));
    while(q--)
    {
        int x;
        ind(x);
        int ans=solve(x);
        if(ans<2e8)
            printf("%d\n", ans);
        else
            printf("oo\n");
    }
    return 0;
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:6:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ind2(n, m) scanf("%d%d", &n, &m)
                    ~~~~~^~~~~~~~~~~~~~~~
brunhilda.cpp:64:5: note: in expansion of macro 'ind2'
     ind2(n, q);
     ^~~~
brunhilda.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ind(n) scanf("%d", &n)
                ~~~~~^~~~~~~~~~
brunhilda.cpp:66:9: note: in expansion of macro 'ind'
         ind(arr[a]);
         ^~~
brunhilda.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ind(n) scanf("%d", &n)
                ~~~~~^~~~~~~~~~
brunhilda.cpp:71:9: note: in expansion of macro 'ind'
         ind(x);
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 39416 KB Output is correct
2 Correct 32 ms 39540 KB Output is correct
3 Correct 31 ms 39608 KB Output is correct
4 Correct 40 ms 39656 KB Output is correct
5 Correct 33 ms 39656 KB Output is correct
6 Correct 32 ms 39732 KB Output is correct
7 Correct 32 ms 39732 KB Output is correct
8 Correct 32 ms 39732 KB Output is correct
9 Correct 39 ms 39732 KB Output is correct
10 Correct 33 ms 39732 KB Output is correct
11 Correct 33 ms 39732 KB Output is correct
12 Correct 33 ms 39732 KB Output is correct
13 Correct 35 ms 39732 KB Output is correct
14 Correct 54 ms 39732 KB Output is correct
15 Correct 32 ms 39732 KB Output is correct
16 Correct 34 ms 39752 KB Output is correct
17 Correct 37 ms 39856 KB Output is correct
18 Correct 38 ms 39856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 39856 KB Output is correct
2 Correct 44 ms 40072 KB Output is correct
3 Correct 42 ms 40072 KB Output is correct
4 Correct 32 ms 40072 KB Output is correct
5 Correct 40 ms 40072 KB Output is correct
6 Correct 33 ms 40072 KB Output is correct
7 Correct 36 ms 40072 KB Output is correct
8 Correct 39 ms 40072 KB Output is correct
9 Correct 47 ms 40072 KB Output is correct
10 Correct 43 ms 40072 KB Output is correct
11 Incorrect 38 ms 40072 KB Output isn't correct
12 Correct 33 ms 40072 KB Output is correct
13 Correct 32 ms 40072 KB Output is correct
14 Correct 33 ms 40072 KB Output is correct
15 Correct 38 ms 40072 KB Output is correct
16 Correct 44 ms 40072 KB Output is correct
17 Correct 33 ms 40072 KB Output is correct
18 Incorrect 46 ms 40072 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 40072 KB Output is correct
2 Correct 113 ms 40072 KB Output is correct
3 Correct 179 ms 40156 KB Output is correct
4 Correct 294 ms 40156 KB Output is correct
5 Correct 299 ms 40368 KB Output is correct
6 Correct 338 ms 40368 KB Output is correct
7 Correct 183 ms 40368 KB Output is correct
8 Correct 155 ms 40368 KB Output is correct
9 Correct 152 ms 40368 KB Output is correct
10 Correct 98 ms 40368 KB Output is correct
11 Correct 124 ms 40368 KB Output is correct
12 Correct 128 ms 40368 KB Output is correct
13 Correct 257 ms 40368 KB Output is correct
14 Correct 100 ms 41296 KB Output is correct
15 Correct 143 ms 41296 KB Output is correct
16 Correct 155 ms 41296 KB Output is correct
17 Correct 76 ms 41296 KB Output is correct
18 Correct 122 ms 41296 KB Output is correct
19 Correct 104 ms 41296 KB Output is correct
20 Correct 166 ms 41296 KB Output is correct
21 Correct 120 ms 41296 KB Output is correct
22 Correct 307 ms 41296 KB Output is correct
23 Correct 305 ms 41296 KB Output is correct
24 Correct 298 ms 41296 KB Output is correct
25 Correct 323 ms 41296 KB Output is correct
26 Correct 292 ms 41296 KB Output is correct
27 Correct 185 ms 41296 KB Output is correct
28 Correct 263 ms 41296 KB Output is correct
29 Correct 323 ms 41296 KB Output is correct
30 Correct 310 ms 41296 KB Output is correct
31 Correct 270 ms 41296 KB Output is correct
32 Correct 299 ms 41296 KB Output is correct
33 Correct 279 ms 41296 KB Output is correct
34 Correct 180 ms 41296 KB Output is correct
35 Correct 272 ms 41296 KB Output is correct
36 Correct 342 ms 41296 KB Output is correct
37 Correct 299 ms 41296 KB Output is correct
38 Correct 317 ms 41296 KB Output is correct
39 Correct 314 ms 41296 KB Output is correct
40 Correct 312 ms 41296 KB Output is correct
41 Correct 189 ms 41296 KB Output is correct
42 Correct 275 ms 41296 KB Output is correct