제출 #1265366

#제출 시각아이디문제언어결과실행 시간메모리
1265366son2008Candies (JOI18_candies)C++20
0 / 100
1 ms576 KiB
#include <bits/stdc++.h> using namespace std; #define ii pair<int, int> #define fi first #define se second #define int long long #define ll long long #define ld double #define mp make_pair #define lg2 30 #define iii pair<int, ii> #define iiii pair<ii, ii> #define base 29 #define eps 1e-8 #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) int dx[] = {0LL, 0LL, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0LL, 0LL, 1, -1, 1, -1}; const int maxn = 2e5 + 1; const int mod = 1e9 + 7; int n, a[maxn], l[maxn], r[maxn], choose[maxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "task" if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } cin >> n; priority_queue<ii> pq; for (int i = 1; i <= n; i++) { cin >> a[i]; pq.push({a[i], i}); l[i] = i - 1; r[i] = i + 1; } int ans = 0; for (int j = 1; j <= (n + 1) / 2; j++) { while (choose[pq.top().se]) pq.pop(); int i = pq.top().se; pq.pop(); ans += a[i]; a[i] = a[l[i]] + a[r[i]] - a[i]; choose[l[i]] = 1; choose[r[i]] = 1; pq.push({a[i], i}); l[i] = l[l[i]]; r[i] = r[r[i]]; r[l[i]] = i; l[r[i]] = i; cout << ans << '\n'; } cerr << endl << "TIME : " << clock() * 0.001 << "s" << endl; }

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

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