Submission #1017789

#TimeUsernameProblemLanguageResultExecution timeMemory
1017789n3rm1nHoliday (IOI14_holiday)C++17
23 / 100
66 ms65536 KiB
#include <bits/stdc++.h> #include "holiday.h" using namespace std; int maxatr = 0, cnt[105]; const int MAXN = 3003, MAXD = 8006; long long dp_left[MAXN][MAXD], dp_right[MAXN][MAXD ]; long long total_left[MAXD * 4], total_end_left[MAXN * 4]; long long total_right[MAXD * 4], total_end_right[MAXN * 4]; long long int findMaxAttraction(int n, int start, int d, int attraction[]) { for(int i = 0; i < n; ++ i) maxatr = max(maxatr, attraction[i]); if(start == 0 && maxatr <= 100) { long long sum = 0; for (int i = 0; i < n; ++ i) { cnt[attraction[i]] ++; int freeto = d - i; long long curr = 0; for (int j = 100; j >= 0 && freeto; -- j) { curr += min(freeto, cnt[j]) * j; long long taken = min(freeto, cnt[j]); freeto -= taken; } sum = max(sum, curr); } return sum; } for (int i = start; i >= 0; -- i) { dp_left[i][1] = attraction[i]; for (int w = 0; w <= d; ++ w) /// samo za gledane { if(w != 0)dp_left[i][w] = max(dp_left[i][w], dp_left[i][w-1]); if(i != start)dp_left[i][w] = max(dp_left[i][w], dp_left[i+1][w]); /// ne gledame if(i != start && w != 0)dp_left[i][w] = max(dp_left[i][w], dp_left[i+1][w-1] + attraction[i]); // cout << i << " " << w << " " << dp_left[i][w] << endl; } } for (int i = 0; i <= start; ++ i) { for (int w = 0; w <= d; ++ w) { total_left[w + (start - i) * 2] = max(total_left[w + (start - i) * 2], dp_left[i][w]); total_end_left[w + (start - i)] = max(total_end_left[w + (start - i)], dp_left[i][w]); } } for (int i = start+1; i < n; ++ i) { dp_right[i][1] = attraction[i]; for (int w = 0; w <= d; ++ w) /// samo za gledane { if(w != 0)dp_right[i][w] = max(dp_right[i][w], dp_right[i][w-1]); if(i > 0)dp_right[i][w] = max(dp_right[i][w], dp_right[i-1][w]); /// ne gledame if(w != 0 && i > 0)dp_right[i][w] = max(dp_right[i][w], dp_right[i-1][w-1] + attraction[i]); } } for (int i = start+1; i < n; ++ i) { for (int w = 0; w <= d; ++ w) { total_right[w + (i - start) * 2] = max(total_right[w + (i - start) * 2], dp_right[i][w]); total_end_right[w + (i - start)] = max(total_end_left[w + (i - start)], dp_right[i][w]); } } long long ans = 0; for (int fix_left = 0; fix_left <= d; ++ fix_left) { ans = max(ans, total_end_left[fix_left] + total_right[d - fix_left]); ans = max(ans, total_end_right[d - fix_left] + total_left[fix_left]); } return ans; } /*const int MAXN = 21, MAXMASK = (1 << 21) + 10; int dp[MAXN][MAXMASK]; long long sum[MAXMASK]; long long int findMaxAttraction(int n, int start, int d, int attraction[]) { //cout << MAXN << " " << MAXMASK << endl; int inf = 1e9; for (int i = 0; i < n; ++ i) { for (int mask = 0; mask <= (1 << (n-1)); ++ mask) { dp[i][mask] = inf; } } for (int mask = 0; mask <= (1 << (n-1)); ++ mask) { for (int v = 0; v < n; ++ v) { if(((1 << v) & mask))sum[mask] += 1LL * attraction[v]; } } dp[start][0] = 0; long long ans = 0; for (int mask = 0; mask <= (1 << (n-1)); ++ mask) { for (int v = 0; v < n; ++ v) { if(dp[v][mask] == inf)continue; for (int add = 0; add < n; ++ add) if(!(mask & (1 << add)))dp[add][(mask | (1 << add))] = min(dp[add][(mask | (1 << add))], dp[v][mask] + abs(v - add) + 1); if(dp[v][mask] <= d)ans = max(ans, sum[mask]); } } return ans; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...