답안 #766772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766772 2023-06-26T07:11:37 Z ivopav Bali Sculptures (APIO15_sculpture) C++17
100 / 100
286 ms 556 KB
#include <bits/stdc++.h>
using namespace std;

bool dp(long long int ind,long long int kol,const vector<long long int>& lis,vector<vector<long long int>>& mem,long long int sad,long long int a,long long int b){
   // cout << sad << " " << ind << " " << kol << " " << zbr << "\n";
    if (ind==lis.size()){
        if (kol<a){
            return false;
        }
        return true;
    }
    if (mem[ind][kol]!=-1){
        return mem[ind][kol];
    }
    if (kol==b){
        return false;
    }
    //long long int najm=dp(ind+1ll,kol,zbr+lis[ind],lis,mem,sad,a,b);
    long long int zbr=0ll;
    bool najm=false;
    for (long long int i=ind;i<lis.size();i++){
        zbr+=lis[i];
        if ((zbr|sad)==sad){
            najm=najm||dp(i+1ll,kol+1ll,lis,mem,sad,a,b);
        }
    }
    mem[ind][kol]=najm;
    return najm;
}

long long int dp2(long long int ind,long long int najb,const vector<long long int>& lis,vector<long long int>& mem,long long int sad,long long int a,long long int b){
   // cout << sad << " " << ind << " " << najb << "\n";
    if (ind==lis.size()){
        return najb;
    }
    if (mem[ind]!=-1){
        return mem[ind]+najb;
    }
    //long long int najm=dp(ind+1ll,kol,zbr+lis[ind],lis,mem,sad,a,b);
    long long int zbr=0ll;
    long long int najm=numeric_limits<long long int>::max()/5;
    for (long long int i=ind;i<lis.size();i++){
        zbr+=lis[i];
       // cout << ind << " "  << i << " " << zbr << " " << sad << "a\n";
        if ((zbr|sad)==sad){
     //       cout << "a\n";
            najm=min(najm,dp2(i+1ll,najb+1ll,lis,mem,sad,a,b));
        }
    }
    mem[ind]=najm-najb;
   // cout << najm << "\n";
    return najm; 
}

int main(){
    
    long long int n;
    long long int a;
    long long int b;
    cin >> n >> a >> b; 
    vector<long long int> lis={};
    for (long long int i=0ll;i<n;i++){
        long long int unos;
        cin >> unos;
        lis.push_back(unos);                 
    }
    if (a>1){

        long long int sad=numeric_limits<long long int>::max();
        long long int sadznam=1ll;
        for (long long int i=0ll;i<62ll;i++){
            sadznam*=2ll;
        }
        while (sadznam>0){
            vector <vector<long long int>> mem=vector<vector<long long int>>(n+5ll,vector<long long int>(b+5ll,-1));
            if (dp(0ll,0ll,lis,mem,sad-sadznam,a,b)){
                sad-=sadznam;
            }
            sadznam/=2ll;
        }
        cout << sad << "\n";
    }
    else {
        long long int sad=numeric_limits<long long int>::max();
        long long int sadznam=1ll;
        for (long long int i=0ll;i<62ll;i++){
            sadznam*=2ll;
        }
        while (sadznam>0){
            vector<long long int> mem=vector<long long int>(n+5ll,-1);
            if (dp2(0ll,0ll,lis,mem,sad-sadznam,a,b)<=b){
                sad-=sadznam;
            }
            sadznam/=2ll;
        }
        cout << sad << "\n";
    }
}

Compilation message

sculpture.cpp: In function 'bool dp(long long int, long long int, const std::vector<long long int>&, std::vector<std::vector<long long int> >&, long long int, long long int, long long int)':
sculpture.cpp:6:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     if (ind==lis.size()){
      |         ~~~^~~~~~~~~~~~
sculpture.cpp:21:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (long long int i=ind;i<lis.size();i++){
      |                              ~^~~~~~~~~~~
sculpture.cpp: In function 'long long int dp2(long long int, long long int, const std::vector<long long int>&, std::vector<long long int>&, long long int, long long int, long long int)':
sculpture.cpp:33:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if (ind==lis.size()){
      |         ~~~^~~~~~~~~~~~
sculpture.cpp:42:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (long long int i=ind;i<lis.size();i++){
      |                              ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 252 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 2 ms 212 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
29 Correct 2 ms 212 KB Output is correct
30 Correct 2 ms 212 KB Output is correct
31 Correct 2 ms 212 KB Output is correct
32 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 2 ms 212 KB Output is correct
51 Correct 2 ms 212 KB Output is correct
52 Correct 2 ms 212 KB Output is correct
53 Correct 2 ms 212 KB Output is correct
54 Correct 2 ms 212 KB Output is correct
55 Correct 2 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 212 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 2 ms 212 KB Output is correct
38 Correct 2 ms 212 KB Output is correct
39 Correct 2 ms 212 KB Output is correct
40 Correct 2 ms 212 KB Output is correct
41 Correct 2 ms 212 KB Output is correct
42 Correct 2 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 24 ms 372 KB Output is correct
53 Correct 36 ms 340 KB Output is correct
54 Correct 75 ms 340 KB Output is correct
55 Correct 69 ms 408 KB Output is correct
56 Correct 245 ms 532 KB Output is correct
57 Correct 247 ms 536 KB Output is correct
58 Correct 247 ms 468 KB Output is correct
59 Correct 257 ms 532 KB Output is correct
60 Correct 259 ms 536 KB Output is correct
61 Correct 1 ms 212 KB Output is correct
62 Correct 36 ms 340 KB Output is correct
63 Correct 75 ms 400 KB Output is correct
64 Correct 64 ms 400 KB Output is correct
65 Correct 122 ms 468 KB Output is correct
66 Correct 192 ms 512 KB Output is correct
67 Correct 243 ms 468 KB Output is correct
68 Correct 286 ms 536 KB Output is correct
69 Correct 241 ms 556 KB Output is correct