답안 #963035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963035 2024-04-14T11:39:40 Z PenguinsAreCute Candies (JOI18_candies) C++17
100 / 100
79 ms 13004 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
#pragma optimize("PLEASE_GIVE_ACCEPTED")
#define int long long
using ll = long long;
using ii = pair<int,int>;
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define pu emplace
#define pf emplace_front
#define sz(v) (int)(v.size())
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=a-1;i>=b;i--)
#define all(v) v.begin(),v.end()
#define lb lower_bound
#define ub upper_bound
#define dieded(k) do {cout<<k; return 0;} while(0)
// Ordered set
// https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// Modular Arithmetic
template<int MOD> struct mint {
	explicit operator ll() const {return v;}
	mint(ll _v) {v=int32_t(_v%MOD); if(v<0) v+=MOD;}
	mint() {v=0;}
	mint& operator += (mint y) {v+=y.v; if(v>=MOD) v-=MOD; return *this;}
	mint& operator -= (mint y) {v-=y.v; if(v<0) v+=MOD; return *this;}
	mint& operator *= (mint y) {v=int32_t((1LL*v*y.v)%MOD); return *this;}
	friend mint operator + (mint x, mint y) {return x+=y;}
	friend mint operator - (mint x, mint y) {return x-=y;}
	friend mint operator * (mint x, mint y) {return x*=y;}
	friend mint pow (mint base, int expo) {
		expo %= (MOD-1);
		if(expo<0) expo+=(MOD-1);
		return internal_pow(base, expo);
	}
	private:
		int32_t v;
		friend mint internal_pow(mint base, int expo) {
			if(expo==0) return 1;
			return internal_pow(base * base, expo >> 1) * (expo & 1 ? base : 1);
		}
};
using mt1 = mint<998244353>;
using mt2 = mint<1000000007>;
#ifdef DEBUG
	#define debug if(1)
	#define RTEfind cout<<"RTE check (line "<<__LINE__<<")\n"
	#define state(...) do {cout<<"Line "<<__LINE__<<": "; printf(__VA_ARGS__);} while(0)
#else
	#define debug if(0)
	#define RTEfind 42
	#define state(...) 69
#endif
inline int readInt() {
    int x; cin >> x;
    return x;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int32_t main() {
	#ifdef DEBUG
		auto programstarttime=high_resolution_clock::now();
	#else
		ios_base::sync_with_stdio(0);
		cin.tie(0);
	#endif
	int n = readInt();
	priority_queue<ii> pq;
	bool bad[n+1];
	REP(i,1,n+1) bad[i]=0;
	int a[n+2], nxt[n+2], prv[n+2];
	nxt[0]=prv[0]=nxt[n+1]=prv[n+1]=0;
	int ans=0;
	a[0]=a[n+1]=-1210201012102010;
	REP(i,1,n+1) pq.pu(a[i]=readInt(),i), nxt[i]=i+1, prv[i]=i-1;
	REP(i,0,((n+1)>>1)) {
		while(bad[pq.top().se]) pq.pop();
		ii x = pq.top(); pq.pop();
		cout<<(ans+=x.fi)<<"\n";
		pq.pu(a[x.se]=a[prv[x.se]]+a[nxt[x.se]]-a[x.se],x.se);
		bad[prv[x.se]]=bad[nxt[x.se]]=1;
		prv[nxt[x.se]=nxt[nxt[x.se]]]=x.se; nxt[prv[x.se]=prv[prv[x.se]]]=x.se;
	}
	#ifdef DEBUG
		auto programendtime=high_resolution_clock::now();
		duration<long double, milli> programdur=programendtime-programstarttime;
		cout<<"\nProgram took "<<programdur.count()<<" milliseconds";
	#endif
}

Compilation message

candies.cpp:6: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    6 | #pragma optimize("PLEASE_GIVE_ACCEPTED")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 356 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 70 ms 11976 KB Output is correct
22 Correct 79 ms 11784 KB Output is correct
23 Correct 77 ms 12752 KB Output is correct
24 Correct 59 ms 12240 KB Output is correct
25 Correct 59 ms 11640 KB Output is correct
26 Correct 61 ms 12500 KB Output is correct
27 Correct 76 ms 11976 KB Output is correct
28 Correct 65 ms 11964 KB Output is correct
29 Correct 72 ms 13004 KB Output is correct
30 Correct 66 ms 11968 KB Output is correct
31 Correct 67 ms 12772 KB Output is correct
32 Correct 66 ms 11980 KB Output is correct
33 Correct 72 ms 12496 KB Output is correct
34 Correct 67 ms 11824 KB Output is correct
35 Correct 68 ms 11708 KB Output is correct
36 Correct 74 ms 11972 KB Output is correct
37 Correct 73 ms 11988 KB Output is correct
38 Correct 72 ms 11860 KB Output is correct
39 Correct 63 ms 11720 KB Output is correct
40 Correct 73 ms 11988 KB Output is correct
41 Correct 61 ms 12568 KB Output is correct
42 Correct 68 ms 11960 KB Output is correct
43 Correct 65 ms 11876 KB Output is correct
44 Correct 75 ms 11992 KB Output is correct
45 Correct 66 ms 11868 KB Output is correct
46 Correct 64 ms 11988 KB Output is correct
47 Correct 67 ms 12296 KB Output is correct
48 Correct 67 ms 11984 KB Output is correct
49 Correct 67 ms 11988 KB Output is correct
50 Correct 68 ms 12072 KB Output is correct