Submission #1265036

#TimeUsernameProblemLanguageResultExecution timeMemory
1265036icebearCandies (JOI18_candies)C++20
100 / 100
62 ms8332 KiB
// ~~ icebear ~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; template<class T> bool minimize(T &a, const T &b) { if (a > b) return a = b, true; return false; } template<class T> bool maximize(T &a, const T &b) { if (a < b) return a = b, true; return false; } #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define FORR(i,a,b) for(int i=(a); i>=(b); --i) #define REP(i, n) for(int i=0; i<(n); ++i) #define RED(i, n) for(int i=(n)-1; i>=0; --i) #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() #define task "icebear" const int MOD = 1e9 + 7; const int inf = 1e9 + 27092008; const ll INF = 1e18 + 27092008; const int N = 2e5 + 5; int n, l[N], r[N]; priority_queue<pair<ll, int>> Q; ll a[N]; void init(void) { cin >> n; a[0] = a[n + 1] = -INF; FOR(i, 1, n) { cin >> a[i]; l[i] = i - 1; r[i] = i + 1; Q.push(mp(a[i], i)); } } void process(void) { ll ans = 0; vector<bool> choose(n + 5, false); FOR(j, 1, (n + 1) / 2) { while(!Q.empty() && choose[Q.top().se]) Q.pop(); int i = Q.top().se; Q.pop(); ans += a[i]; cout << ans << '\n'; a[i] = a[l[i]] + a[r[i]] - a[i]; choose[l[i]] = choose[r[i]] = true; Q.push(mp(a[i], i)); l[i] = l[l[i]]; r[l[i]] = i; r[i] = r[r[i]]; l[r[i]] = i; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int tc = 1; // cin >> tc; while(tc--) { init(); process(); } return 0; }

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...