제출 #109883

#제출 시각아이디문제언어결과실행 시간메모리
109883SaboonBali Sculptures (APIO15_sculpture)C++14
0 / 100
3 ms512 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2000 + 10; const ll inf = 1e18; bool g[maxn][maxn], cp[maxn][maxn]; ll a[maxn], dp[110][110]; int pd[maxn]; int shortest_path(int n){ for (int i = 1; i <= n; i++) pd[i] = n + 1; pd[0] = 0; for (int i = 1; i <= n; i++) for (int j = 0; j < i; j++) if (g[j][i]) pd[i] = min(pd[i], pd[j] + 1); return pd[n]; } int main(){ ios_base::sync_with_stdio(false); int n, A, B; cin >> n >> A >> B; for (int i = 1; i <= n; i++){ cin >> a[i]; a[i] += a[i - 1]; } if (n <= 100){ memset(dp, 63, sizeof dp); dp[0][0] = 0; for (int i = 1; i <= B; i++) for (int j = i; j <= n; j++) for (int k = j - 1; k >= i - 1; k--) dp[i][j] = min(dp[i][j], dp[i - 1][k] | (a[j] - a[k])); ll answer = inf; for (int i = A; i <= B; i++) answer = min(answer, dp[i][n]); cout << answer << endl; return 0; } for (int i = 0; i <= n; i++) for (int j = i + 1; j <= n; j++) g[i][j] = 1; ll untilnow = 0; for (int i = 60; i >= 0; i--){ for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) cp[j][k] = g[j][k]; for (int j = 0; j <= n; j++) for (int k = j + 1; k <= n; k++) if ((a[k] - a[j]) & (1ll << i)) g[j][k] = 0; if (shortest_path(n) > B){ untilnow += (1ll << i); for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) g[j][k] = cp[j][k]; } } cout << untilnow << endl; }
#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...