답안 #1001230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001230 2024-06-18T17:16:30 Z vjudge1 Safety (NOI18_safety) C++17
100 / 100
125 ms 23348 KB
// #pragma optimize ("g",on)
// #pragma GCC optimize("inline")
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC optimize ("03")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define adiyer(); ios_base::sync_with_stdio(0); cin.tie(0);
#define bitcount(n) __builtin_popcountll(n)
#define puts(x) cout << (x ? "YES\n" : "NO\n");
#define ent (i == n ? '\n' : ' ')
#define all(x) x.begin(), x.end()
#define md ((l + r) >> 1)
#define rv(v) ((v << 1) | 1)
#define lv(v) (v << 1)
#define rs(v) rv(v), md + 1, r
#define ls(v) lv(v), l, md
#define len(s) (int) s.size()

#define yes {cout << "YES\n"; return; }
#define no {cout << "no\n"; return; }
#define skip continue
#define pb push_back
#define S second
#define F first

// #define int long long

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef pair < ll, ll > pll;
typedef vector < pair < ll, ll > > vpll;
typedef tree < ll, null_type, less < ll >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = 1e6 + 12;
const int K = 500 + 12;
const int MAX = 2e5;
const int mod = 998244353;
const ll inf = 1e9 + 10;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

ll n, k, res;
ll a[N];

multiset < ll > s1, s2;

void output(){
	cin >> n >> k;
	for(ll i = 1; i <= n; i++) cin >> a[i];
	s1.insert(a[1]), s2.insert(a[1]);
	for(ll i = 2; i <= n; i++){
		ll x = (a[i] + (i - 1) * k), y = (a[i] - (i - 1) * k);
		if(len(s1) && x < *s1.rbegin()){
			s1.insert(x), s1.insert(x);
			s2.insert(*s1.rbegin() - (i - 1) * k * 2);
			res += abs(*s1.rbegin() - x);
			s1.erase(s1.find(*s1.rbegin()));
		}
		else if(len(s2) && a[i] - (i - 1) * k > *s2.begin()){
			s2.insert(y), s2.insert(y);
			s1.insert(*s2.begin() + (i - 1) * k * 2);
			res += abs(*s2.begin() - y);
			s2.erase(s2.find(*s2.begin()));
		}
		else{	
			s1.insert(x), s2.insert(y);;
		}
	}
	cout << res;
}

const bool cases = 0;

signed main(){
//  file("disrupt");
    adiyer();
    int tt = 1;
    if(cases) cin >> tt;
    for(int i = 1; i <= tt; i++){
//      cout << "Case " << i << ":\n";
        output();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 16208 KB Output is correct
2 Correct 107 ms 21908 KB Output is correct
3 Correct 113 ms 22864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 0 ms 472 KB Output is correct
21 Correct 0 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 0 ms 472 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 0 ms 352 KB Output is correct
26 Correct 0 ms 352 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 352 KB Output is correct
18 Correct 0 ms 352 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 0 ms 472 KB Output is correct
21 Correct 0 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 0 ms 472 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 0 ms 352 KB Output is correct
26 Correct 0 ms 352 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 2 ms 856 KB Output is correct
29 Correct 2 ms 864 KB Output is correct
30 Correct 2 ms 780 KB Output is correct
31 Correct 1 ms 864 KB Output is correct
32 Correct 1 ms 864 KB Output is correct
33 Correct 2 ms 860 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 352 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 0 ms 352 KB Output is correct
26 Correct 0 ms 472 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 352 KB Output is correct
29 Correct 0 ms 472 KB Output is correct
30 Correct 0 ms 352 KB Output is correct
31 Correct 0 ms 352 KB Output is correct
32 Correct 0 ms 352 KB Output is correct
33 Correct 0 ms 352 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 2 ms 864 KB Output is correct
36 Correct 2 ms 780 KB Output is correct
37 Correct 1 ms 864 KB Output is correct
38 Correct 1 ms 864 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 2 ms 860 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 78 ms 16208 KB Output is correct
20 Correct 107 ms 21908 KB Output is correct
21 Correct 113 ms 22864 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 352 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 352 KB Output is correct
29 Correct 0 ms 472 KB Output is correct
30 Correct 0 ms 352 KB Output is correct
31 Correct 1 ms 352 KB Output is correct
32 Correct 0 ms 472 KB Output is correct
33 Correct 0 ms 352 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 352 KB Output is correct
36 Correct 0 ms 352 KB Output is correct
37 Correct 2 ms 856 KB Output is correct
38 Correct 2 ms 864 KB Output is correct
39 Correct 2 ms 780 KB Output is correct
40 Correct 1 ms 864 KB Output is correct
41 Correct 1 ms 864 KB Output is correct
42 Correct 2 ms 860 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
47 Correct 2 ms 856 KB Output is correct
48 Correct 2 ms 860 KB Output is correct
49 Correct 1 ms 860 KB Output is correct
50 Correct 125 ms 23348 KB Output is correct
51 Correct 95 ms 19656 KB Output is correct
52 Correct 61 ms 18888 KB Output is correct
53 Correct 66 ms 21760 KB Output is correct
54 Correct 72 ms 22360 KB Output is correct
55 Correct 56 ms 19280 KB Output is correct
56 Correct 65 ms 21060 KB Output is correct
57 Correct 58 ms 19536 KB Output is correct
58 Correct 59 ms 16684 KB Output is correct
59 Correct 60 ms 21328 KB Output is correct