답안 #409444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409444 2021-05-20T18:36:42 Z TLP39 Bali Sculptures (APIO15_sculpture) C++14
50 / 100
186 ms 4420 KB
#include <stdio.h>
#include <math.h>
#include <utility>
#include <string.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pp;

int n,a,b;
ll y[2001];
ll qs[2001]={};
bool cango[2001][2001];
int dist[2001];
ll tot=0;

void init()
{
    scanf("%d %d %d",&n,&a,&b);
    qs[0]=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&y[i]);
        qs[i]=qs[i-1]+y[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            cango[i][j]=true;
        }
    }
}

bool checkgo(int p,int q,int r)
{
    return ((qs[q]-qs[p])>>r)&1;
}

bool testgo(int r)
{
    dist[0]=0;
    for(int i=1;i<=n;i++) dist[i]=1000000;
    for(int i=0;i<n;i++)
    {
        if(dist[i]==1000000) continue;
        for(int j=i+1;j<=n;j++)
        {
            if(!cango[i][j]) continue;
            if(!checkgo(i,j,r)) dist[j]=min(dist[j],dist[i]+1);
        }
        if(dist[n]<=b) return true;
    }
    return false;
}

void solve_big()
{
    bool res;
    for(int i=40;i>=0;i--)
    {
        res=testgo(i);
        if(res)
        {
            for(int j=0;j<n;j++)
            {
                for(int ii=j+1;ii<=n;ii++)
                {
                    if(checkgo(j,ii,i)) cango[j][ii]=false;
                }
            }
        }
        else
        {
            tot|=(1ll<<i);
        }
    }
}

int main()
{
    init();
    if(a==1)
    {
        solve_big();
        printf("%lld",tot);
        return 0;
    }
    ll ans[101][101];
    for(int i=1;i<=n;i++)
    {
        ans[1][i]=qs[i];
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            ans[i][j]=(1ll<<50);
            for(int ii=i-1;ii<j;ii++)
            {
                ans[i][j]=min(ans[i][j],ans[i-1][ii]|(qs[j]-qs[ii]));
            }
        }
    }
    ll fin_ans=(1ll<<50);
    for(int i=a;i<=b;i++)
    {
        fin_ans=min(fin_ans,ans[i][n]);
    }
    printf("%lld",fin_ans);
    return 0;
}

Compilation message

sculpture.cpp: In function 'void init()':
sculpture.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d %d %d",&n,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%lld",&y[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 380 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 380 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 380 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 508 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 1 ms 388 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 380 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 380 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 548 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 1 ms 380 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 508 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 1 ms 588 KB Output is correct
41 Correct 1 ms 588 KB Output is correct
42 Correct 1 ms 588 KB Output is correct
43 Correct 1 ms 572 KB Output is correct
44 Correct 1 ms 512 KB Output is correct
45 Correct 1 ms 508 KB Output is correct
46 Correct 1 ms 588 KB Output is correct
47 Correct 1 ms 588 KB Output is correct
48 Correct 1 ms 588 KB Output is correct
49 Correct 1 ms 588 KB Output is correct
50 Correct 1 ms 588 KB Output is correct
51 Correct 1 ms 512 KB Output is correct
52 Correct 12 ms 1484 KB Output is correct
53 Correct 12 ms 1876 KB Output is correct
54 Correct 46 ms 2252 KB Output is correct
55 Correct 31 ms 2252 KB Output is correct
56 Correct 77 ms 4232 KB Output is correct
57 Correct 82 ms 4300 KB Output is correct
58 Correct 128 ms 4340 KB Output is correct
59 Correct 186 ms 4300 KB Output is correct
60 Correct 124 ms 4344 KB Output is correct
61 Correct 1 ms 588 KB Output is correct
62 Correct 12 ms 1868 KB Output is correct
63 Correct 46 ms 2252 KB Output is correct
64 Correct 21 ms 2376 KB Output is correct
65 Correct 40 ms 3148 KB Output is correct
66 Correct 62 ms 3788 KB Output is correct
67 Correct 167 ms 4300 KB Output is correct
68 Correct 153 ms 4328 KB Output is correct
69 Correct 80 ms 4420 KB Output is correct