Submission #1158808

#TimeUsernameProblemLanguageResultExecution timeMemory
1158808sunflower휴가 (IOI14_holiday)C++17
30 / 100
32 ms1096 KiB
#ifndef SUN #include "holiday.h" #endif // SUN #include <bits/stdc++.h> using namespace std; #define ll long long #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define SZ(x) ((int) (x).size()) #define ALL(a) (a).begin(), (a).end() #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) #define debug(x) cerr << "[" << #x << " = " << (x) << "]" << endl #define left __left #define right __right #define prev __prev #define fi first #define se second template <class X, class Y> bool maximize(X &x, Y y) { if (x < y) return x = y, true; else return false; } template <class X, class Y> bool minimize(X &x, Y y) { if (x > y) return x = y, true; else return false; } int numPlace, start, days; #define MAX_N 100'100 int a[MAX_N + 2]; namespace subtask1 { bool check() { return (numPlace <= 20); } ll solve() { ll ans = 0; FOR(mask, 0, MASK(numPlace) - 1) { if (BIT(mask, start) == 0) continue; int minBit = -1, maxBit = -1; /// position; int numBit = 0; ll res = 0; FOR(i, 0, numPlace - 1) { if (BIT(mask, i)) { ++numBit; maxBit = i; if (minBit == -1) minBit = i; res += a[i]; } } if (numBit + maxBit - minBit + min(maxBit - start, start - minBit) <= days) { maximize(ans, res); } /// case2: don't visit at start; numBit--; res -= a[start]; if (numBit + maxBit - minBit + min(maxBit - start, start - minBit) <= days) { maximize(ans, res); } } return ans; } } namespace subtask2 { bool check() { return (start == 0 && *max_element(a, a + numPlace) <= 100); } int cnt[102]; ll solve() { /// move from 0 .. i with i < numPlace: cost = i; /// thi luc do la days -= i; roi tim sum_element of day; ll ans = 0; FOR(i, 0, numPlace - 1) { assert(a[i] <= 100); cnt[a[i]]++; int tmp_d = days - i; if (tmp_d <= 0) break; ll res = 0; FORD(val, 100, 1) { if (cnt[val] >= tmp_d) { res += tmp_d * val; break; } else { res += cnt[val] * val; tmp_d -= cnt[val]; } } maximize(ans, res); } return ans; } } long long int findMaxAttraction(int __n, int __start, int __d, int attraction[]) { numPlace = __n; start = __start; days = __d; FOR(i, 0, numPlace - 1) a[i] = attraction[i]; if (subtask1 :: check()) return subtask1 :: solve(); if (subtask2 :: check()) return subtask2 :: solve(); } #ifdef SUN int main() { ios_base::sync_with_stdio(false);cin.tie(nullptr); freopen("test.inp","r",stdin); freopen("test.out","w",stdout); cin >> numPlace >> start >> days; FOR(i, 0, numPlace - 1) cin >> a[i]; cout << findMaxAttraction(numPlace, start, days, a); return 0; } #endif // SUN /* Discipline - Calm */

Compilation message (stderr)

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:124:1: warning: control reaches end of non-void function [-Wreturn-type]
  124 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...