제출 #1153179

#제출 시각아이디문제언어결과실행 시간메모리
1153179minggaCandies (JOI18_candies)C++20
0 / 100
1 ms576 KiB
#include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define int long long const int mod = 1e9 + 7; const int inf = 2e18; const int N = 2e5 + 7; int n, a[N], l[N], r[N]; bool del[N]; signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; priority_queue<pair<int, int>> q; for(int i = 1; i <= n; i++) { l[i] = i - 1; r[i] = i + 1; q.push({a[i], i}); } int cur = 0; for(int i = 1; i <= (n + 1) / 2;) { auto x = q.top(); q.pop(); int val = x.fi, id = x.se; if(del[id]) continue; cur += val; cout << cur << ln; int lef = l[id], rig = r[id]; del[lef] = 1, del[rig] = 1; int new_val = a[lef] + a[rig] - a[id]; r[id] = r[rig]; l[r[rig]] = id; l[id] = l[lef]; r[l[lef]] = id; a[id] = new_val; q.push({new_val, id}); i++; } cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

컴파일 시 표준 에러 (stderr) 메시지

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