답안 #799160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799160 2023-07-31T10:22:03 Z RecursiveCo Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 316 KB
// CF template, version 3.0

#include <bits/stdc++.h>

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

#define int long long int

signed main() {
    improvePerformance;

    get(n);
    get(A);
    get(B);
    getList(n, nums);
    
    // 71 points
    int ans = 0;
    int power = 1ll << 59ll;
    for (int b = 59; b >= 0; b--) {
        int lower = ans;
        int upper = ans + power - 1;
        // DP with O(n2) states and O(n) transition per state.
        // so O(n3) DP
        // should be fine right?
        vector<vector<bool>> dp(n, vector<bool>(n + 1, false));
        int pref = 0;
        forto(n, i) {
            pref += nums[i];
            forto(n + 1, j) {
                if (j == 0) continue;
                if (j == 1) {
                    dp[i][j] = lower <= pref && pref <= upper;
                    continue;
                }
                if (j > i + 1) {
                    dp[i][j] = false;
                    break;
                }
                int sum = 0;
                for (int k = i - 1; k >= 0; k--) {
                    sum += nums[k + 1];
                    if (dp[k][j - 1] && lower <= sum && sum <= upper) {
                        dp[i][j] = true;
                        break;
                    }
                }
            }
        }
        bool can = false;
        for (int i = A; i <= B; i++) {
            if (dp[n - 1][i]) {
                can = true;
                break;
            }
        }
        if (!can) ans += power;

        power /= 2;
    }
    out(ans);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:23:5: note: in expansion of macro 'get'
   23 |     get(n);
      |     ^~~
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'A' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:24:5: note: in expansion of macro 'get'
   24 |     get(A);
      |     ^~~
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'B' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:25:5: note: in expansion of macro 'get'
   25 |     get(B);
      |     ^~~
sculpture.cpp:12:40: warning: unnecessary parentheses in declaration of 'nums' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
sculpture.cpp:26:5: note: in expansion of macro 'getList'
   26 |     getList(n, nums);
      |     ^~~~~~~
sculpture.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
sculpture.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
sculpture.cpp:26:5: note: in expansion of macro 'getList'
   26 |     getList(n, nums);
      |     ^~~~~~~
sculpture.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
sculpture.cpp:39:9: note: in expansion of macro 'forto'
   39 |         forto(n, i) {
      |         ^~~~~
sculpture.cpp:15:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
sculpture.cpp:41:13: note: in expansion of macro 'forto'
   41 |             forto(n + 1, j) {
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -