답안 #676560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676560 2022-12-31T09:13:40 Z Do_you_copy Candies (JOI18_candies) C++17
8 / 100
13 ms 3168 KB
//Then
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 1;
//const int Mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int n;
ll a[maxN];
bool invalid[maxN];
int nxt[maxN];
int pre[maxN];
struct TPQ{
    int i;
    bool operator < (const TPQ &other) const{
        return a[i] < a[other.i];
    }
};

priority_queue <TPQ> PQ;

void Init(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        PQ.push({i});
    }
    for (int i = 0; i <= n + 1; ++i){
        pre[i] = i - 1;
        nxt[i] = i + 1;
    }
    a[0] = a[n + 1] = -inf;
    nxt[n] = 0;
    ll ans = 0;
    int k = (n + 1) / 2;
    for (int _ = 1; _ <= k; ++_){
        while (!PQ.empty() && invalid[PQ.top().i]){
            PQ.pop();
        }
        if (PQ.empty()) break;
        int i = PQ.top().i;
        invalid[i] = 1;
        invalid[nxt[i]] = 1;
        invalid[pre[i]] = 1;
        ans += a[i];
        cout << ans << "\n";
        ++n;
        a[n] = a[nxt[i]] + a[pre[i]] - a[i];
        nxt[n] = nxt[nxt[i]];
        pre[n] = pre[pre[i]];
        nxt[pre[pre[i]]] = n;
        pre[nxt[nxt[i]]] = n;
        PQ.push({n});
    }
}

#define debug
#define taskname "test"
signed main(){
    faster
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
        #ifndef debug
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        #endif // debug
    }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 372 KB Output is correct
5 Correct 1 ms 368 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 368 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 372 KB Output is correct
5 Correct 1 ms 368 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Runtime error 13 ms 3168 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -