답안 #76816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76816 2018-09-18T12:26:47 Z vex Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 5720 KB
#include <bits/stdc++.h>
#define maxn 2005
using namespace std;

int n,a,b;
long long s[maxn];

bool moze(int x)
{
    int g=0;
    int pr=0;
    long long tr=1LL<<x;
    for(int i=1;i<=n;i++)
    {
        if(s[i]-s[pr]>=tr)
        {
            if(i==pr+1)return false;
            g++;
            pr=i-1;
            i--;
        }
        else if(i==n)g++;
    }
    if(g<=b)return true;
    return false;
}
int numbit()
{
    int l=0;
    int r=50;
    int sol;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(moze(mid))
        {
            sol=mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    return sol;
}

bool t[maxn][maxn];
bool exist(long long br0,int numb)
{
    long long br=1LL<<numb;
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)t[i][j]=false;
    
    t[0][0]=true;
    for(int i=1;i<=n;i++)
        for(int j=0;j<i;j++)
        {
            if(((s[i]-s[j])&br0)==0LL && (s[i]-s[j])<br)
            {
                for(int k=0;k<=n-1;k++)if(t[j][k])t[i][k+1]=true;
            }
        }

    for(int i=a;i<=b;i++)if(t[n][i])return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin>>n>>a>>b;s[0]=0LL;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }

    int br=numbit();
    if(br==0)
    {
    	cout<<0<<endl;
    	return 0;
    }
    
    long long sol=1LL<<(br-1);
    long long obr=0;
    for(int i=br-2;i>=0;i--)
    {
        obr+=1LL<<i;
        if(!exist(obr,br))
        {
            obr-=1LL<<i;
            sol+=1LL<<i;
        }
    }
    cout<<sol<<endl;
    return 0;
}
/*
6 1 3
8 1 2 1 5 4
*/

Compilation message

sculpture.cpp: In function 'int numbit()':
sculpture.cpp:42:12: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return sol;
            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 676 KB Output is correct
6 Correct 2 ms 676 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 2 ms 676 KB Output is correct
18 Correct 2 ms 676 KB Output is correct
19 Correct 2 ms 756 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
21 Correct 2 ms 760 KB Output is correct
22 Correct 2 ms 760 KB Output is correct
23 Correct 2 ms 760 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 2 ms 760 KB Output is correct
26 Correct 2 ms 760 KB Output is correct
27 Correct 2 ms 760 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 796 KB Output is correct
30 Correct 2 ms 796 KB Output is correct
31 Correct 2 ms 800 KB Output is correct
32 Correct 2 ms 800 KB Output is correct
33 Correct 2 ms 800 KB Output is correct
34 Correct 2 ms 800 KB Output is correct
35 Correct 2 ms 800 KB Output is correct
36 Correct 2 ms 800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 800 KB Output is correct
2 Correct 2 ms 800 KB Output is correct
3 Correct 2 ms 800 KB Output is correct
4 Correct 2 ms 800 KB Output is correct
5 Correct 2 ms 800 KB Output is correct
6 Correct 2 ms 800 KB Output is correct
7 Correct 2 ms 832 KB Output is correct
8 Correct 2 ms 832 KB Output is correct
9 Correct 2 ms 832 KB Output is correct
10 Correct 3 ms 832 KB Output is correct
11 Correct 2 ms 832 KB Output is correct
12 Correct 2 ms 832 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Correct 2 ms 832 KB Output is correct
15 Correct 2 ms 832 KB Output is correct
16 Correct 2 ms 832 KB Output is correct
17 Correct 3 ms 832 KB Output is correct
18 Correct 2 ms 832 KB Output is correct
19 Correct 2 ms 832 KB Output is correct
20 Correct 2 ms 840 KB Output is correct
21 Correct 2 ms 844 KB Output is correct
22 Correct 2 ms 848 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 2 ms 864 KB Output is correct
27 Correct 2 ms 932 KB Output is correct
28 Correct 2 ms 932 KB Output is correct
29 Correct 2 ms 932 KB Output is correct
30 Correct 2 ms 932 KB Output is correct
31 Correct 2 ms 932 KB Output is correct
32 Correct 3 ms 932 KB Output is correct
33 Correct 2 ms 932 KB Output is correct
34 Correct 2 ms 932 KB Output is correct
35 Correct 2 ms 932 KB Output is correct
36 Correct 2 ms 932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 932 KB Output is correct
2 Correct 2 ms 932 KB Output is correct
3 Correct 2 ms 932 KB Output is correct
4 Correct 2 ms 932 KB Output is correct
5 Correct 2 ms 932 KB Output is correct
6 Correct 2 ms 932 KB Output is correct
7 Correct 2 ms 932 KB Output is correct
8 Correct 2 ms 932 KB Output is correct
9 Correct 2 ms 944 KB Output is correct
10 Correct 2 ms 944 KB Output is correct
11 Correct 2 ms 944 KB Output is correct
12 Correct 2 ms 956 KB Output is correct
13 Correct 2 ms 956 KB Output is correct
14 Correct 2 ms 956 KB Output is correct
15 Correct 2 ms 956 KB Output is correct
16 Correct 2 ms 1016 KB Output is correct
17 Correct 2 ms 1052 KB Output is correct
18 Correct 2 ms 1076 KB Output is correct
19 Correct 2 ms 1076 KB Output is correct
20 Correct 3 ms 1104 KB Output is correct
21 Correct 2 ms 1104 KB Output is correct
22 Correct 2 ms 1104 KB Output is correct
23 Correct 2 ms 1104 KB Output is correct
24 Correct 2 ms 1104 KB Output is correct
25 Correct 2 ms 1124 KB Output is correct
26 Correct 2 ms 1128 KB Output is correct
27 Correct 2 ms 1132 KB Output is correct
28 Correct 2 ms 1136 KB Output is correct
29 Correct 2 ms 1140 KB Output is correct
30 Correct 5 ms 1144 KB Output is correct
31 Correct 2 ms 1184 KB Output is correct
32 Correct 2 ms 1184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1184 KB Output is correct
2 Correct 2 ms 1184 KB Output is correct
3 Correct 2 ms 1184 KB Output is correct
4 Correct 2 ms 1184 KB Output is correct
5 Correct 2 ms 1184 KB Output is correct
6 Correct 2 ms 1184 KB Output is correct
7 Correct 2 ms 1184 KB Output is correct
8 Correct 2 ms 1184 KB Output is correct
9 Correct 2 ms 1184 KB Output is correct
10 Correct 2 ms 1184 KB Output is correct
11 Correct 2 ms 1184 KB Output is correct
12 Correct 2 ms 1184 KB Output is correct
13 Correct 2 ms 1184 KB Output is correct
14 Correct 2 ms 1184 KB Output is correct
15 Correct 2 ms 1184 KB Output is correct
16 Correct 2 ms 1184 KB Output is correct
17 Correct 2 ms 1184 KB Output is correct
18 Correct 2 ms 1184 KB Output is correct
19 Correct 2 ms 1184 KB Output is correct
20 Correct 3 ms 1184 KB Output is correct
21 Correct 2 ms 1184 KB Output is correct
22 Correct 2 ms 1184 KB Output is correct
23 Correct 2 ms 1184 KB Output is correct
24 Correct 2 ms 1184 KB Output is correct
25 Correct 2 ms 1184 KB Output is correct
26 Correct 2 ms 1184 KB Output is correct
27 Correct 2 ms 1184 KB Output is correct
28 Correct 2 ms 1184 KB Output is correct
29 Correct 2 ms 1184 KB Output is correct
30 Correct 2 ms 1184 KB Output is correct
31 Correct 2 ms 1184 KB Output is correct
32 Correct 2 ms 1184 KB Output is correct
33 Correct 2 ms 1184 KB Output is correct
34 Correct 2 ms 1184 KB Output is correct
35 Correct 3 ms 1184 KB Output is correct
36 Correct 2 ms 1184 KB Output is correct
37 Correct 2 ms 1184 KB Output is correct
38 Correct 2 ms 1184 KB Output is correct
39 Correct 2 ms 1240 KB Output is correct
40 Correct 2 ms 1240 KB Output is correct
41 Correct 2 ms 1240 KB Output is correct
42 Correct 3 ms 1240 KB Output is correct
43 Correct 3 ms 1240 KB Output is correct
44 Correct 2 ms 1240 KB Output is correct
45 Correct 3 ms 1240 KB Output is correct
46 Correct 3 ms 1240 KB Output is correct
47 Correct 2 ms 1240 KB Output is correct
48 Correct 2 ms 1340 KB Output is correct
49 Correct 2 ms 1344 KB Output is correct
50 Correct 2 ms 1344 KB Output is correct
51 Correct 2 ms 1352 KB Output is correct
52 Correct 2 ms 1396 KB Output is correct
53 Correct 5 ms 1396 KB Output is correct
54 Correct 3 ms 1396 KB Output is correct
55 Correct 2 ms 1496 KB Output is correct
56 Correct 3 ms 1496 KB Output is correct
57 Correct 4 ms 1496 KB Output is correct
58 Correct 4 ms 1496 KB Output is correct
59 Correct 3 ms 1496 KB Output is correct
60 Correct 3 ms 1496 KB Output is correct
61 Correct 4 ms 1496 KB Output is correct
62 Correct 4 ms 1532 KB Output is correct
63 Correct 4 ms 1532 KB Output is correct
64 Correct 2 ms 1532 KB Output is correct
65 Correct 3 ms 1532 KB Output is correct
66 Correct 3 ms 1532 KB Output is correct
67 Correct 3 ms 1532 KB Output is correct
68 Correct 3 ms 1532 KB Output is correct
69 Correct 3 ms 1532 KB Output is correct
70 Correct 3 ms 1532 KB Output is correct
71 Correct 5 ms 1532 KB Output is correct
72 Correct 4 ms 1532 KB Output is correct
73 Correct 4 ms 1532 KB Output is correct
74 Correct 5 ms 1532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1532 KB Output is correct
2 Correct 2 ms 1532 KB Output is correct
3 Correct 2 ms 1532 KB Output is correct
4 Correct 2 ms 1532 KB Output is correct
5 Correct 3 ms 1532 KB Output is correct
6 Correct 2 ms 1532 KB Output is correct
7 Correct 2 ms 1532 KB Output is correct
8 Correct 2 ms 1532 KB Output is correct
9 Correct 2 ms 1532 KB Output is correct
10 Correct 3 ms 1532 KB Output is correct
11 Correct 2 ms 1532 KB Output is correct
12 Correct 2 ms 1532 KB Output is correct
13 Correct 2 ms 1532 KB Output is correct
14 Correct 2 ms 1532 KB Output is correct
15 Correct 2 ms 1532 KB Output is correct
16 Correct 2 ms 1532 KB Output is correct
17 Correct 2 ms 1532 KB Output is correct
18 Correct 2 ms 1532 KB Output is correct
19 Correct 3 ms 1532 KB Output is correct
20 Correct 3 ms 1532 KB Output is correct
21 Correct 2 ms 1532 KB Output is correct
22 Correct 3 ms 1532 KB Output is correct
23 Correct 2 ms 1532 KB Output is correct
24 Correct 2 ms 1532 KB Output is correct
25 Correct 2 ms 1532 KB Output is correct
26 Correct 2 ms 1532 KB Output is correct
27 Correct 2 ms 1532 KB Output is correct
28 Correct 2 ms 1532 KB Output is correct
29 Correct 2 ms 1532 KB Output is correct
30 Correct 2 ms 1532 KB Output is correct
31 Correct 3 ms 1532 KB Output is correct
32 Correct 3 ms 1532 KB Output is correct
33 Correct 2 ms 1532 KB Output is correct
34 Correct 2 ms 1532 KB Output is correct
35 Correct 2 ms 1592 KB Output is correct
36 Correct 2 ms 1592 KB Output is correct
37 Correct 2 ms 1592 KB Output is correct
38 Correct 2 ms 1604 KB Output is correct
39 Correct 2 ms 1608 KB Output is correct
40 Correct 5 ms 1652 KB Output is correct
41 Correct 2 ms 1700 KB Output is correct
42 Correct 2 ms 1700 KB Output is correct
43 Correct 2 ms 1700 KB Output is correct
44 Correct 3 ms 1700 KB Output is correct
45 Correct 3 ms 1700 KB Output is correct
46 Correct 3 ms 1700 KB Output is correct
47 Correct 3 ms 1700 KB Output is correct
48 Correct 4 ms 1700 KB Output is correct
49 Correct 4 ms 1700 KB Output is correct
50 Correct 4 ms 1700 KB Output is correct
51 Correct 4 ms 1700 KB Output is correct
52 Correct 49 ms 2804 KB Output is correct
53 Correct 70 ms 3068 KB Output is correct
54 Correct 319 ms 3460 KB Output is correct
55 Correct 139 ms 3508 KB Output is correct
56 Correct 621 ms 5532 KB Output is correct
57 Correct 481 ms 5552 KB Output is correct
58 Correct 185 ms 5572 KB Output is correct
59 Correct 204 ms 5720 KB Output is correct
60 Execution timed out 1066 ms 5720 KB Time limit exceeded
61 Halted 0 ms 0 KB -