답안 #368405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
368405 2021-02-20T03:18:04 Z cpp219 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
256 ms 32256 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e3 + 9;
const ll inf = 1e16 + 7;
typedef pair<int,int> LL;

ll n,a[N],A,B,sum,dp[N][N],b[N],ans = (1ll << 45) - 1;
ll dp1[N],mask;
ll f(ll pos,ll grp){
    if (pos > n){
        if (A <= grp&&grp <= B) return 1;
        return 0;
    }
    if (dp[pos][grp] != -1) return dp[pos][grp];
    ll ans = 0;
    for (ll i = pos;i <= n;i++){
        ll p = b[i] - b[pos - 1];
        if ((mask | p) == mask) ans = max(ans,f(i + 1,grp + 1));
    }
    return dp[pos][grp] = ans;
}

void Sub4(){
    for (ll i = 44;i >= 0;i--){
        memset(dp,-1,sizeof(dp)); mask = ans - (1ll << i);
        //cout<<f(1,0)<<" x "<<mask<<"\n"; //exit(0);
        if (f(1,0)) ans = mask;
    }
    cout<<ans;
}

ll f1(ll pos){
    if (pos > n) return 0;
    if (dp1[pos] != -1) return dp1[pos];
    ll ans = inf;
    for (ll i = pos;i <= n;i++){
        ll p = b[i] - b[pos - 1];
        if ((mask | p) == mask) ans = min(ans,1 + f1(i + 1));
    }
    return dp1[pos] = ans;
}

void Sub5(){
    for (ll i = 44;i >= 0;i--){
        memset(dp1,-1,sizeof(dp1)); mask = ans - (1ll << i);
        if (f1(1) <= B) ans = mask;
    }
    cout<<ans;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n>>A>>B;
    for (ll i = 1;i <= n;i++) cin>>a[i],b[i] = b[i - 1] + a[i];
    if (n <= 100) Sub4();
    else Sub5();
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   59 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 32108 KB Output is correct
2 Correct 202 ms 31980 KB Output is correct
3 Correct 200 ms 31980 KB Output is correct
4 Correct 202 ms 32000 KB Output is correct
5 Correct 202 ms 32000 KB Output is correct
6 Correct 199 ms 31980 KB Output is correct
7 Correct 203 ms 32000 KB Output is correct
8 Correct 201 ms 31980 KB Output is correct
9 Correct 200 ms 31980 KB Output is correct
10 Correct 200 ms 31980 KB Output is correct
11 Correct 201 ms 31980 KB Output is correct
12 Correct 205 ms 31980 KB Output is correct
13 Correct 203 ms 32108 KB Output is correct
14 Correct 198 ms 31980 KB Output is correct
15 Correct 210 ms 31980 KB Output is correct
16 Correct 201 ms 32108 KB Output is correct
17 Correct 202 ms 31980 KB Output is correct
18 Correct 200 ms 32000 KB Output is correct
19 Correct 200 ms 31980 KB Output is correct
20 Correct 197 ms 32108 KB Output is correct
21 Correct 204 ms 32128 KB Output is correct
22 Correct 200 ms 31980 KB Output is correct
23 Correct 202 ms 31980 KB Output is correct
24 Correct 203 ms 31980 KB Output is correct
25 Correct 201 ms 32000 KB Output is correct
26 Correct 201 ms 32108 KB Output is correct
27 Correct 206 ms 31980 KB Output is correct
28 Correct 208 ms 31980 KB Output is correct
29 Correct 202 ms 31980 KB Output is correct
30 Correct 202 ms 31980 KB Output is correct
31 Correct 204 ms 32000 KB Output is correct
32 Correct 198 ms 31980 KB Output is correct
33 Correct 204 ms 31980 KB Output is correct
34 Correct 202 ms 31980 KB Output is correct
35 Correct 203 ms 32088 KB Output is correct
36 Correct 202 ms 31980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 32108 KB Output is correct
2 Correct 201 ms 32000 KB Output is correct
3 Correct 203 ms 32128 KB Output is correct
4 Correct 201 ms 32108 KB Output is correct
5 Correct 204 ms 32108 KB Output is correct
6 Correct 201 ms 31980 KB Output is correct
7 Correct 202 ms 32108 KB Output is correct
8 Correct 200 ms 32108 KB Output is correct
9 Correct 211 ms 31980 KB Output is correct
10 Correct 201 ms 31980 KB Output is correct
11 Correct 198 ms 32108 KB Output is correct
12 Correct 201 ms 31980 KB Output is correct
13 Correct 204 ms 32108 KB Output is correct
14 Correct 204 ms 31980 KB Output is correct
15 Correct 199 ms 32108 KB Output is correct
16 Correct 206 ms 31980 KB Output is correct
17 Correct 203 ms 32108 KB Output is correct
18 Correct 205 ms 31980 KB Output is correct
19 Correct 202 ms 32128 KB Output is correct
20 Correct 197 ms 31980 KB Output is correct
21 Correct 212 ms 31980 KB Output is correct
22 Correct 202 ms 32000 KB Output is correct
23 Correct 200 ms 32108 KB Output is correct
24 Correct 204 ms 31980 KB Output is correct
25 Correct 201 ms 31980 KB Output is correct
26 Correct 203 ms 32108 KB Output is correct
27 Correct 204 ms 32016 KB Output is correct
28 Correct 205 ms 31980 KB Output is correct
29 Correct 200 ms 32236 KB Output is correct
30 Correct 208 ms 32108 KB Output is correct
31 Correct 203 ms 31980 KB Output is correct
32 Correct 203 ms 32000 KB Output is correct
33 Correct 214 ms 32256 KB Output is correct
34 Correct 210 ms 32108 KB Output is correct
35 Correct 210 ms 31980 KB Output is correct
36 Correct 215 ms 32108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 32108 KB Output is correct
2 Correct 204 ms 31980 KB Output is correct
3 Correct 208 ms 31980 KB Output is correct
4 Correct 198 ms 31980 KB Output is correct
5 Correct 200 ms 32108 KB Output is correct
6 Correct 202 ms 32108 KB Output is correct
7 Correct 196 ms 32000 KB Output is correct
8 Correct 203 ms 32108 KB Output is correct
9 Correct 203 ms 32000 KB Output is correct
10 Correct 198 ms 32108 KB Output is correct
11 Correct 202 ms 31980 KB Output is correct
12 Correct 203 ms 31980 KB Output is correct
13 Correct 202 ms 31980 KB Output is correct
14 Correct 200 ms 31980 KB Output is correct
15 Correct 200 ms 31980 KB Output is correct
16 Correct 203 ms 31980 KB Output is correct
17 Correct 206 ms 31980 KB Output is correct
18 Correct 207 ms 32108 KB Output is correct
19 Correct 203 ms 31980 KB Output is correct
20 Correct 208 ms 32108 KB Output is correct
21 Correct 211 ms 32000 KB Output is correct
22 Correct 203 ms 32108 KB Output is correct
23 Correct 203 ms 32108 KB Output is correct
24 Correct 212 ms 31980 KB Output is correct
25 Correct 214 ms 31980 KB Output is correct
26 Correct 224 ms 31980 KB Output is correct
27 Correct 234 ms 32108 KB Output is correct
28 Correct 239 ms 31980 KB Output is correct
29 Correct 241 ms 31980 KB Output is correct
30 Correct 256 ms 31980 KB Output is correct
31 Correct 240 ms 32004 KB Output is correct
32 Correct 237 ms 32108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 32108 KB Output is correct
2 Correct 196 ms 32000 KB Output is correct
3 Correct 205 ms 32108 KB Output is correct
4 Correct 204 ms 32108 KB Output is correct
5 Correct 197 ms 32000 KB Output is correct
6 Correct 201 ms 31980 KB Output is correct
7 Correct 204 ms 32236 KB Output is correct
8 Correct 200 ms 31980 KB Output is correct
9 Correct 205 ms 32000 KB Output is correct
10 Correct 201 ms 31980 KB Output is correct
11 Correct 199 ms 32116 KB Output is correct
12 Correct 203 ms 31980 KB Output is correct
13 Correct 198 ms 31980 KB Output is correct
14 Correct 206 ms 32108 KB Output is correct
15 Correct 205 ms 31980 KB Output is correct
16 Correct 198 ms 31980 KB Output is correct
17 Correct 199 ms 32108 KB Output is correct
18 Correct 202 ms 32108 KB Output is correct
19 Correct 200 ms 31980 KB Output is correct
20 Correct 197 ms 32000 KB Output is correct
21 Correct 205 ms 31980 KB Output is correct
22 Correct 204 ms 31980 KB Output is correct
23 Correct 200 ms 32128 KB Output is correct
24 Correct 204 ms 31980 KB Output is correct
25 Correct 200 ms 32108 KB Output is correct
26 Correct 194 ms 31980 KB Output is correct
27 Correct 200 ms 32108 KB Output is correct
28 Correct 199 ms 32108 KB Output is correct
29 Correct 204 ms 31980 KB Output is correct
30 Correct 202 ms 32108 KB Output is correct
31 Correct 197 ms 31980 KB Output is correct
32 Correct 201 ms 31980 KB Output is correct
33 Correct 199 ms 31932 KB Output is correct
34 Correct 205 ms 32108 KB Output is correct
35 Correct 196 ms 31980 KB Output is correct
36 Correct 195 ms 31980 KB Output is correct
37 Correct 203 ms 31980 KB Output is correct
38 Correct 207 ms 31980 KB Output is correct
39 Correct 204 ms 31980 KB Output is correct
40 Correct 206 ms 31980 KB Output is correct
41 Correct 204 ms 32108 KB Output is correct
42 Correct 203 ms 31980 KB Output is correct
43 Correct 208 ms 32108 KB Output is correct
44 Correct 208 ms 32108 KB Output is correct
45 Correct 202 ms 32108 KB Output is correct
46 Correct 206 ms 31980 KB Output is correct
47 Correct 203 ms 32000 KB Output is correct
48 Correct 208 ms 32108 KB Output is correct
49 Correct 219 ms 31980 KB Output is correct
50 Correct 229 ms 32108 KB Output is correct
51 Correct 241 ms 32108 KB Output is correct
52 Correct 239 ms 32108 KB Output is correct
53 Correct 243 ms 32108 KB Output is correct
54 Correct 238 ms 31980 KB Output is correct
55 Correct 239 ms 32004 KB Output is correct
56 Correct 202 ms 32056 KB Output is correct
57 Correct 211 ms 32108 KB Output is correct
58 Correct 215 ms 32116 KB Output is correct
59 Correct 211 ms 32004 KB Output is correct
60 Correct 210 ms 32108 KB Output is correct
61 Correct 215 ms 31980 KB Output is correct
62 Correct 217 ms 32108 KB Output is correct
63 Correct 218 ms 32004 KB Output is correct
64 Correct 233 ms 32108 KB Output is correct
65 Correct 203 ms 31980 KB Output is correct
66 Correct 203 ms 31980 KB Output is correct
67 Correct 206 ms 32052 KB Output is correct
68 Correct 213 ms 31980 KB Output is correct
69 Correct 215 ms 32004 KB Output is correct
70 Correct 209 ms 32004 KB Output is correct
71 Correct 215 ms 31980 KB Output is correct
72 Correct 216 ms 32108 KB Output is correct
73 Correct 219 ms 31980 KB Output is correct
74 Correct 227 ms 32108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 32000 KB Output is correct
2 Correct 208 ms 32108 KB Output is correct
3 Correct 201 ms 31980 KB Output is correct
4 Correct 202 ms 32108 KB Output is correct
5 Correct 202 ms 31980 KB Output is correct
6 Correct 202 ms 31980 KB Output is correct
7 Correct 201 ms 31980 KB Output is correct
8 Correct 205 ms 31980 KB Output is correct
9 Correct 206 ms 31980 KB Output is correct
10 Correct 208 ms 31980 KB Output is correct
11 Correct 205 ms 31980 KB Output is correct
12 Correct 201 ms 31980 KB Output is correct
13 Correct 205 ms 32108 KB Output is correct
14 Correct 209 ms 31980 KB Output is correct
15 Correct 200 ms 32108 KB Output is correct
16 Correct 204 ms 31980 KB Output is correct
17 Correct 201 ms 31980 KB Output is correct
18 Correct 200 ms 32108 KB Output is correct
19 Correct 200 ms 31980 KB Output is correct
20 Correct 207 ms 32000 KB Output is correct
21 Correct 208 ms 32128 KB Output is correct
22 Correct 202 ms 32000 KB Output is correct
23 Correct 210 ms 31980 KB Output is correct
24 Correct 202 ms 31980 KB Output is correct
25 Correct 204 ms 32108 KB Output is correct
26 Correct 204 ms 31980 KB Output is correct
27 Correct 200 ms 31980 KB Output is correct
28 Correct 204 ms 32108 KB Output is correct
29 Correct 205 ms 31980 KB Output is correct
30 Correct 206 ms 31980 KB Output is correct
31 Correct 207 ms 31936 KB Output is correct
32 Correct 206 ms 31980 KB Output is correct
33 Correct 210 ms 31980 KB Output is correct
34 Correct 202 ms 32108 KB Output is correct
35 Correct 212 ms 32108 KB Output is correct
36 Correct 217 ms 31980 KB Output is correct
37 Correct 229 ms 31980 KB Output is correct
38 Correct 239 ms 31980 KB Output is correct
39 Correct 236 ms 32108 KB Output is correct
40 Correct 240 ms 31980 KB Output is correct
41 Correct 241 ms 31980 KB Output is correct
42 Correct 235 ms 32108 KB Output is correct
43 Correct 201 ms 31980 KB Output is correct
44 Correct 215 ms 31980 KB Output is correct
45 Correct 209 ms 32108 KB Output is correct
46 Correct 211 ms 31980 KB Output is correct
47 Correct 213 ms 31980 KB Output is correct
48 Correct 210 ms 31980 KB Output is correct
49 Correct 217 ms 32108 KB Output is correct
50 Correct 210 ms 32108 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 11 ms 364 KB Output is correct
53 Correct 12 ms 492 KB Output is correct
54 Correct 39 ms 364 KB Output is correct
55 Correct 29 ms 364 KB Output is correct
56 Correct 74 ms 492 KB Output is correct
57 Correct 73 ms 492 KB Output is correct
58 Correct 80 ms 620 KB Output is correct
59 Correct 105 ms 596 KB Output is correct
60 Correct 84 ms 492 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 12 ms 364 KB Output is correct
63 Correct 52 ms 492 KB Output is correct
64 Correct 19 ms 364 KB Output is correct
65 Correct 35 ms 492 KB Output is correct
66 Correct 53 ms 492 KB Output is correct
67 Correct 70 ms 684 KB Output is correct
68 Correct 143 ms 620 KB Output is correct
69 Correct 70 ms 492 KB Output is correct