Submission #74693

# Submission time Handle Problem Language Result Execution time Memory
74693 2018-09-06T14:47:50 Z kjain_1810 Brunhilda’s Birthday (BOI13_brunhilda) C++17
97.7778 / 100
354 ms 41152 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]=1e8;
}

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<1e8)
            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);
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 39416 KB Output is correct
2 Correct 39 ms 39648 KB Output is correct
3 Correct 41 ms 39648 KB Output is correct
4 Correct 45 ms 39696 KB Output is correct
5 Correct 45 ms 39696 KB Output is correct
6 Correct 37 ms 39696 KB Output is correct
7 Correct 34 ms 39696 KB Output is correct
8 Correct 32 ms 39696 KB Output is correct
9 Correct 33 ms 39696 KB Output is correct
10 Correct 33 ms 39696 KB Output is correct
11 Correct 32 ms 39696 KB Output is correct
12 Correct 34 ms 39696 KB Output is correct
13 Correct 36 ms 39696 KB Output is correct
14 Correct 55 ms 39808 KB Output is correct
15 Correct 33 ms 39808 KB Output is correct
16 Correct 34 ms 39808 KB Output is correct
17 Correct 39 ms 39808 KB Output is correct
18 Correct 39 ms 39808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 39824 KB Output is correct
2 Correct 47 ms 40080 KB Output is correct
3 Correct 48 ms 40080 KB Output is correct
4 Correct 34 ms 40080 KB Output is correct
5 Correct 40 ms 40080 KB Output is correct
6 Correct 35 ms 40080 KB Output is correct
7 Correct 35 ms 40080 KB Output is correct
8 Correct 35 ms 40080 KB Output is correct
9 Correct 43 ms 40080 KB Output is correct
10 Correct 47 ms 40080 KB Output is correct
11 Incorrect 41 ms 40080 KB Output isn't correct
12 Correct 32 ms 40080 KB Output is correct
13 Correct 35 ms 40080 KB Output is correct
14 Correct 33 ms 40080 KB Output is correct
15 Correct 39 ms 40080 KB Output is correct
16 Correct 48 ms 40080 KB Output is correct
17 Correct 36 ms 40080 KB Output is correct
18 Incorrect 48 ms 40080 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 40080 KB Output is correct
2 Correct 128 ms 40080 KB Output is correct
3 Correct 190 ms 40112 KB Output is correct
4 Correct 298 ms 40240 KB Output is correct
5 Correct 302 ms 40388 KB Output is correct
6 Correct 324 ms 40388 KB Output is correct
7 Correct 186 ms 40388 KB Output is correct
8 Correct 152 ms 40388 KB Output is correct
9 Correct 152 ms 40388 KB Output is correct
10 Correct 101 ms 40388 KB Output is correct
11 Correct 125 ms 40388 KB Output is correct
12 Correct 141 ms 40388 KB Output is correct
13 Correct 259 ms 40388 KB Output is correct
14 Correct 90 ms 41152 KB Output is correct
15 Correct 156 ms 41152 KB Output is correct
16 Correct 192 ms 41152 KB Output is correct
17 Correct 84 ms 41152 KB Output is correct
18 Correct 136 ms 41152 KB Output is correct
19 Correct 112 ms 41152 KB Output is correct
20 Correct 192 ms 41152 KB Output is correct
21 Correct 119 ms 41152 KB Output is correct
22 Correct 354 ms 41152 KB Output is correct
23 Correct 331 ms 41152 KB Output is correct
24 Correct 307 ms 41152 KB Output is correct
25 Correct 327 ms 41152 KB Output is correct
26 Correct 287 ms 41152 KB Output is correct
27 Correct 182 ms 41152 KB Output is correct
28 Correct 287 ms 41152 KB Output is correct
29 Correct 335 ms 41152 KB Output is correct
30 Correct 309 ms 41152 KB Output is correct
31 Correct 282 ms 41152 KB Output is correct
32 Correct 320 ms 41152 KB Output is correct
33 Correct 271 ms 41152 KB Output is correct
34 Correct 180 ms 41152 KB Output is correct
35 Correct 274 ms 41152 KB Output is correct
36 Correct 302 ms 41152 KB Output is correct
37 Correct 298 ms 41152 KB Output is correct
38 Correct 324 ms 41152 KB Output is correct
39 Correct 312 ms 41152 KB Output is correct
40 Correct 320 ms 41152 KB Output is correct
41 Correct 198 ms 41152 KB Output is correct
42 Correct 275 ms 41152 KB Output is correct