Submission #469403

#TimeUsernameProblemLanguageResultExecution timeMemory
469403chienyu_xiongBali Sculptures (APIO15_sculpture)C++17
50 / 100
143 ms460 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define mp make_pair #define int long long #define pii pair<int, int> #define all(_) begin(_), end(_) #define smx(y, x) ((y) = max(x, y)) #define smn(y, x) ((y) = min(x, y)) void setIO() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } const int N = 2e3 + 5; const int M = 1e1 + 2; const int K = 3e5 + 0; const int inf = 9e17; const int mod = 1e9 + 7; int xyz = 1; // test cases int n, t, m; int arr[N]; int nx[N]; int dp[2][N]; bool one(int msk) { nx[0] = 0; for (int i = 1; i <= n; i++) { nx[i] = inf; int sum = 0; for (int j = i; j >= 1; j--) { sum += arr[j]; if ((sum & msk) == sum) smn(nx[i], nx[j - 1] + 1); } } return nx[n] <= m; } bool can(int msk) { dp[0][0] = 1; for (int i = 1; i <= n; i++) dp[0][i] = 0; for (int j = 1; j <= m; j++) { int p = j & 1; int o = p ^ 1; for (int i = 1; i <= n; i++) { int sum = 0; dp[p][i] = false; for (int k = i; k >= 1; k--) sum += arr[k], dp[p][i] |= (sum & msk) == sum && dp[o][k - 1]; } if (j >= t && dp[p][n]) return true; /* for (int i = 1; i <= n; i++) cout << dp[p][i] << " "; cout << endl; */ } return false; } bool chk(int msk) { return t == 1 ? one(msk) : can(msk); } void run() { cin >> n >> t >> m; for (int i = 1; i <= n; i++) cin >> arr[i]; int msk = (1LL << 41) - 1LL; for (int i = 40; i >= 0; i--) { if (chk(msk ^ (1LL << i))) { msk ^= (1LL << i); } } cout << msk << endl; } signed main() { setIO(); while (xyz--) run(); #ifdef LOCAL cin.clear(); cout.flush(); system("pause"); #endif return 0; }
#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...