답안 #76819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76819 2018-09-18T12:35:20 Z vex Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 5268 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 dp2[maxn];
bool exist2(long long br0,int numb)
{
	long long br=1LL<<numb;
	for(int i=1;i<=n;i++)dp2[i]=b+1;
	dp2[0]=0;
            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 && dp2[j]+1<dp2[i])
            		{
            			 dp2[i]=dp2[j];
            		}
		}
		
	return dp2[n]<=b;
}
 
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;
    
   /* if(a==1)
    {
	for(int i=br-2;i>=0;i--)
	{
		obr+=1LL<<i;
		if(!exist2(obr,br))
		{
            		obr-=1LL<<i;
            		sol+=1LL<<i;
		}
	}
	cout<<sol<<endl;
	return 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 3 ms 376 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 472 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 616 KB Output is correct
10 Correct 2 ms 616 KB Output is correct
11 Correct 3 ms 616 KB Output is correct
12 Correct 2 ms 616 KB Output is correct
13 Correct 3 ms 744 KB Output is correct
14 Correct 2 ms 744 KB Output is correct
15 Correct 2 ms 744 KB Output is correct
16 Correct 2 ms 744 KB Output is correct
17 Correct 2 ms 744 KB Output is correct
18 Correct 3 ms 744 KB Output is correct
19 Correct 2 ms 744 KB Output is correct
20 Correct 2 ms 744 KB Output is correct
21 Correct 2 ms 744 KB Output is correct
22 Correct 2 ms 744 KB Output is correct
23 Correct 3 ms 744 KB Output is correct
24 Correct 2 ms 744 KB Output is correct
25 Correct 2 ms 744 KB Output is correct
26 Correct 2 ms 744 KB Output is correct
27 Correct 2 ms 744 KB Output is correct
28 Correct 2 ms 744 KB Output is correct
29 Correct 2 ms 744 KB Output is correct
30 Correct 2 ms 744 KB Output is correct
31 Correct 2 ms 748 KB Output is correct
32 Correct 2 ms 752 KB Output is correct
33 Correct 2 ms 820 KB Output is correct
34 Correct 2 ms 820 KB Output is correct
35 Correct 2 ms 824 KB Output is correct
36 Correct 2 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 824 KB Output is correct
2 Correct 2 ms 824 KB Output is correct
3 Correct 2 ms 824 KB Output is correct
4 Correct 2 ms 824 KB Output is correct
5 Correct 2 ms 824 KB Output is correct
6 Correct 2 ms 824 KB Output is correct
7 Correct 2 ms 824 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 2 ms 824 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 2 ms 860 KB Output is correct
12 Correct 2 ms 868 KB Output is correct
13 Correct 2 ms 868 KB Output is correct
14 Correct 2 ms 868 KB Output is correct
15 Correct 2 ms 868 KB Output is correct
16 Correct 2 ms 868 KB Output is correct
17 Correct 2 ms 868 KB Output is correct
18 Correct 2 ms 868 KB Output is correct
19 Correct 2 ms 920 KB Output is correct
20 Correct 3 ms 920 KB Output is correct
21 Correct 2 ms 920 KB Output is correct
22 Correct 2 ms 920 KB Output is correct
23 Correct 2 ms 920 KB Output is correct
24 Correct 2 ms 920 KB Output is correct
25 Correct 2 ms 920 KB Output is correct
26 Correct 2 ms 920 KB Output is correct
27 Correct 2 ms 920 KB Output is correct
28 Correct 2 ms 920 KB Output is correct
29 Correct 2 ms 920 KB Output is correct
30 Correct 2 ms 920 KB Output is correct
31 Correct 3 ms 920 KB Output is correct
32 Correct 2 ms 920 KB Output is correct
33 Correct 3 ms 920 KB Output is correct
34 Correct 2 ms 920 KB Output is correct
35 Correct 2 ms 920 KB Output is correct
36 Correct 2 ms 920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 920 KB Output is correct
2 Correct 2 ms 920 KB Output is correct
3 Correct 2 ms 920 KB Output is correct
4 Correct 2 ms 920 KB Output is correct
5 Correct 2 ms 920 KB Output is correct
6 Correct 2 ms 920 KB Output is correct
7 Correct 2 ms 924 KB Output is correct
8 Correct 2 ms 928 KB Output is correct
9 Correct 2 ms 936 KB Output is correct
10 Correct 2 ms 936 KB Output is correct
11 Correct 3 ms 940 KB Output is correct
12 Correct 2 ms 944 KB Output is correct
13 Correct 2 ms 948 KB Output is correct
14 Correct 2 ms 952 KB Output is correct
15 Correct 2 ms 1020 KB Output is correct
16 Correct 2 ms 1020 KB Output is correct
17 Correct 2 ms 1020 KB Output is correct
18 Correct 2 ms 1020 KB Output is correct
19 Correct 2 ms 1020 KB Output is correct
20 Correct 3 ms 1020 KB Output is correct
21 Correct 2 ms 1020 KB Output is correct
22 Correct 2 ms 1020 KB Output is correct
23 Correct 2 ms 1020 KB Output is correct
24 Correct 2 ms 1020 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 1180 KB Output is correct
31 Correct 2 ms 1180 KB Output is correct
32 Correct 2 ms 1180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1180 KB Output is correct
2 Correct 2 ms 1180 KB Output is correct
3 Correct 2 ms 1180 KB Output is correct
4 Correct 2 ms 1180 KB Output is correct
5 Correct 2 ms 1180 KB Output is correct
6 Correct 2 ms 1180 KB Output is correct
7 Correct 2 ms 1180 KB Output is correct
8 Correct 2 ms 1180 KB Output is correct
9 Correct 2 ms 1180 KB Output is correct
10 Correct 2 ms 1180 KB Output is correct
11 Correct 2 ms 1180 KB Output is correct
12 Correct 2 ms 1180 KB Output is correct
13 Correct 2 ms 1180 KB Output is correct
14 Correct 2 ms 1180 KB Output is correct
15 Correct 3 ms 1180 KB Output is correct
16 Correct 2 ms 1180 KB Output is correct
17 Correct 2 ms 1180 KB Output is correct
18 Correct 2 ms 1180 KB Output is correct
19 Correct 2 ms 1180 KB Output is correct
20 Correct 2 ms 1180 KB Output is correct
21 Correct 2 ms 1180 KB Output is correct
22 Correct 2 ms 1180 KB Output is correct
23 Correct 3 ms 1180 KB Output is correct
24 Correct 2 ms 1180 KB Output is correct
25 Correct 2 ms 1180 KB Output is correct
26 Correct 2 ms 1180 KB Output is correct
27 Correct 2 ms 1180 KB Output is correct
28 Correct 2 ms 1180 KB Output is correct
29 Correct 2 ms 1180 KB Output is correct
30 Correct 2 ms 1204 KB Output is correct
31 Correct 2 ms 1204 KB Output is correct
32 Correct 2 ms 1204 KB Output is correct
33 Correct 2 ms 1204 KB Output is correct
34 Correct 2 ms 1204 KB Output is correct
35 Correct 2 ms 1204 KB Output is correct
36 Correct 2 ms 1204 KB Output is correct
37 Correct 2 ms 1204 KB Output is correct
38 Correct 2 ms 1204 KB Output is correct
39 Correct 3 ms 1204 KB Output is correct
40 Correct 2 ms 1204 KB Output is correct
41 Correct 2 ms 1204 KB Output is correct
42 Correct 2 ms 1204 KB Output is correct
43 Correct 2 ms 1204 KB Output is correct
44 Correct 2 ms 1204 KB Output is correct
45 Correct 2 ms 1204 KB Output is correct
46 Correct 2 ms 1204 KB Output is correct
47 Correct 2 ms 1328 KB Output is correct
48 Correct 2 ms 1332 KB Output is correct
49 Correct 2 ms 1336 KB Output is correct
50 Correct 3 ms 1340 KB Output is correct
51 Correct 2 ms 1344 KB Output is correct
52 Correct 2 ms 1348 KB Output is correct
53 Correct 5 ms 1352 KB Output is correct
54 Correct 2 ms 1356 KB Output is correct
55 Correct 3 ms 1360 KB Output is correct
56 Correct 3 ms 1360 KB Output is correct
57 Correct 3 ms 1368 KB Output is correct
58 Correct 3 ms 1372 KB Output is correct
59 Correct 3 ms 1376 KB Output is correct
60 Correct 3 ms 1380 KB Output is correct
61 Correct 5 ms 1384 KB Output is correct
62 Correct 5 ms 1388 KB Output is correct
63 Correct 4 ms 1392 KB Output is correct
64 Correct 2 ms 1400 KB Output is correct
65 Correct 3 ms 1400 KB Output is correct
66 Correct 3 ms 1408 KB Output is correct
67 Correct 3 ms 1408 KB Output is correct
68 Correct 3 ms 1412 KB Output is correct
69 Correct 3 ms 1416 KB Output is correct
70 Correct 3 ms 1456 KB Output is correct
71 Correct 4 ms 1460 KB Output is correct
72 Correct 4 ms 1460 KB Output is correct
73 Correct 4 ms 1460 KB Output is correct
74 Correct 5 ms 1472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1472 KB Output is correct
2 Correct 2 ms 1472 KB Output is correct
3 Correct 2 ms 1472 KB Output is correct
4 Correct 2 ms 1472 KB Output is correct
5 Correct 2 ms 1472 KB Output is correct
6 Correct 2 ms 1472 KB Output is correct
7 Correct 2 ms 1472 KB Output is correct
8 Correct 2 ms 1472 KB Output is correct
9 Correct 2 ms 1472 KB Output is correct
10 Correct 2 ms 1472 KB Output is correct
11 Correct 2 ms 1472 KB Output is correct
12 Correct 2 ms 1472 KB Output is correct
13 Correct 2 ms 1472 KB Output is correct
14 Correct 2 ms 1472 KB Output is correct
15 Correct 2 ms 1472 KB Output is correct
16 Correct 2 ms 1472 KB Output is correct
17 Correct 2 ms 1472 KB Output is correct
18 Correct 3 ms 1472 KB Output is correct
19 Correct 2 ms 1472 KB Output is correct
20 Correct 2 ms 1472 KB Output is correct
21 Correct 2 ms 1472 KB Output is correct
22 Correct 3 ms 1472 KB Output is correct
23 Correct 2 ms 1472 KB Output is correct
24 Correct 2 ms 1472 KB Output is correct
25 Correct 2 ms 1472 KB Output is correct
26 Correct 2 ms 1472 KB Output is correct
27 Correct 2 ms 1472 KB Output is correct
28 Correct 2 ms 1472 KB Output is correct
29 Correct 2 ms 1472 KB Output is correct
30 Correct 3 ms 1472 KB Output is correct
31 Correct 2 ms 1472 KB Output is correct
32 Correct 2 ms 1472 KB Output is correct
33 Correct 2 ms 1472 KB Output is correct
34 Correct 2 ms 1472 KB Output is correct
35 Correct 2 ms 1472 KB Output is correct
36 Correct 2 ms 1472 KB Output is correct
37 Correct 2 ms 1472 KB Output is correct
38 Correct 2 ms 1472 KB Output is correct
39 Correct 3 ms 1472 KB Output is correct
40 Correct 4 ms 1472 KB Output is correct
41 Correct 2 ms 1476 KB Output is correct
42 Correct 2 ms 1476 KB Output is correct
43 Correct 2 ms 1476 KB Output is correct
44 Correct 3 ms 1476 KB Output is correct
45 Correct 3 ms 1476 KB Output is correct
46 Correct 4 ms 1476 KB Output is correct
47 Correct 3 ms 1500 KB Output is correct
48 Correct 4 ms 1500 KB Output is correct
49 Correct 5 ms 1500 KB Output is correct
50 Correct 5 ms 1500 KB Output is correct
51 Correct 3 ms 1500 KB Output is correct
52 Correct 52 ms 2460 KB Output is correct
53 Correct 69 ms 2920 KB Output is correct
54 Correct 307 ms 3356 KB Output is correct
55 Correct 141 ms 3356 KB Output is correct
56 Correct 630 ms 5268 KB Output is correct
57 Correct 504 ms 5268 KB Output is correct
58 Correct 180 ms 5268 KB Output is correct
59 Correct 197 ms 5268 KB Output is correct
60 Execution timed out 1080 ms 5268 KB Time limit exceeded
61 Halted 0 ms 0 KB -