Submission #1008453

#TimeUsernameProblemLanguageResultExecution timeMemory
1008453WhisperBali Sculptures (APIO15_sculpture)C++17
100 / 100
78 ms600 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPD(i, n) for (int i = (n) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX 2005 int nArr, l, r; int A[MAX]; void init(void){ cin >> nArr >> l >> r; for (int i = 1; i <= nArr; ++i) cin >> A[i]; } void process(void){ if (nArr <= 100){ int ans = 0, cur = 0; REPD(j, 51){ cur |= MASK(j); vector<vector<int>> dp(nArr + 5, vector<int>(r + 5, 0)); dp[0][0] = 1; for (int i = 1; i <= nArr; ++i){ int sm = 0; for (int k = i; k >= 1; --k){ sm += A[k]; int v = (sm & cur); // we only consider the bits that have passed if ((v & ans) == v){ for (int gr = 1; gr <= r; ++gr) dp[i][gr] |= dp[k - 1][gr - 1]; } } } bool has = 0; for (int i = l; i <= r; ++i) has |= dp[nArr][i]; if (has == 0) ans |= MASK(j); } cout << ans; } else{ int ans = 0, cur = 0; REPD(j, 51){ cur |= MASK(j); vector<int> dp(nArr + 5, INF); dp[0] = 0; for (int i = 1; i <= nArr; ++i){ int sm = 0; for (int k = i; k >= 1; --k){ sm += A[k]; int v = (sm & cur); if ((v & ans) == v){ minimize(dp[i], dp[k - 1] + 1); } } } if (dp[nArr] > r) ans |= MASK(j); } cout << ans; } } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); init(); process(); }
#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...