제출 #705486

#제출 시각아이디문제언어결과실행 시간메모리
705486Alihan_8Bali Sculptures (APIO15_sculpture)C++17
50 / 100
249 ms444 KiB
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, A, B; cin >> n >> A >> B;
    vector <int> p(n), pref(n+1);
    for ( auto &i: p ) cin >> i;
    for ( int i = 1; i <= n; i++ ){
        pref[i] = pref[i-1]+p[i-1];
    }
    auto ok = [&](int K, int f, int bit){
        return (f >> bit | K) == K;
    };
    if ( A == 1 ){
        int ans = 0;
        for ( int bit = 63; bit >= 0; bit-- ){
            vector <int> dp(n+1, n+1);
            dp[0] = 0;
            for ( int i = 1; i <= n; i++ ){
                for ( int j = 0; j < i; j++ ){
                    if ( !ok(ans, pref[i]-pref[j], bit) ) continue;
                    dp[i] = min(dp[i], dp[j]+1);
                }
            }
            ans |= dp.back() > B;
            ans <<= 1;
        }
        cout << ans/2 << ln;
        return 0;
    }
    int ans = 0;
    for ( int bit = 63; bit >= 0; bit-- ){
        vector <vector<int>> dp(n+1, vector <int> (n+1));
        dp[0][0] = true;
        for ( int k = 1; k <= n; k++ ){
            for ( int i = 1; i <= n; i++ ){
                for ( int j = 0; j < n; j++ ){
                    if ( !ok(ans, pref[i]-pref[j], bit) ) continue;
                    dp[i][k] |= dp[j][k-1];
                }
            }
        }
        bool flag = false;
        for ( int i = A; i <= B; i++ ){
            flag |= dp[n][i];
        }
        ans += !flag;
        ans <<= 1;
    }
    cout << ans/2;

    cout << '\n';
}
/*
6 1 3
8 1 2 1 5 4
*/

컴파일 시 표준 에러 (stderr) 메시지

sculpture.cpp: In function 'void IO(std::string)':
sculpture.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...