답안 #422909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422909 2021-06-10T13:57:26 Z maomao90 Safety (NOI18_safety) C++17
100 / 100
71 ms 6260 KB
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005

int n, h;
int s[MAXN];
priority_queue<ll> lft;
priority_queue<ll, vll, greater<ll>> rht;
ll c;
ll lazy;

int main() {
	scanf("%d%d", &n, &h);
	REP (i, 0, n) {
		scanf("%d", &s[i]);
	}
	rht.push(s[0]);
	lft.push(s[0]);
	REP (i, 1, n) {
		lazy += h;
		ll lv = lft.top() - lazy, rv = rht.top() + lazy;
		if (s[i] >= lv && s[i] <= rv) {
			lft.push(s[i] + lazy);
			rht.push(s[i] - lazy);
		} else if (s[i] < lv) {
			lft.pop();
			lft.push(s[i] + lazy);
			lft.push(s[i] + lazy);
			c += lv - s[i];
			rht.push(lv - lazy);
		} else {
			rht.pop();
			rht.push(s[i] - lazy);
			rht.push(s[i] - lazy);
			c += s[i] - rv;
			lft.push(rv + lazy);
		}
		//printf(" %lld\n", c);
		//auto tmp = lft;
		//while (!tmp.empty()) {
			//printf("%lld\n", tmp.top() - lazy); tmp.pop();
		//}
		//printf("\n");
		//auto tmpp = rht;
		//while (!tmpp.empty()) {
			//printf("%lld\n", tmpp.top() + lazy); tmpp.pop();
		//}
		//printf("\n");
	}
	printf("%lld\n", c);
	return 0;
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d", &n, &h);
      |  ~~~~~^~~~~~~~~~~~~~~~
safety.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d", &s[i]);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 3956 KB Output is correct
2 Correct 63 ms 5992 KB Output is correct
3 Correct 68 ms 6120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 2 ms 460 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 2 ms 440 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 2 ms 444 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 1 ms 444 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 39 ms 3956 KB Output is correct
20 Correct 63 ms 5992 KB Output is correct
21 Correct 68 ms 6120 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 2 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 2 ms 440 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 444 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 1 ms 444 KB Output is correct
49 Correct 2 ms 460 KB Output is correct
50 Correct 71 ms 6260 KB Output is correct
51 Correct 53 ms 5756 KB Output is correct
52 Correct 37 ms 5644 KB Output is correct
53 Correct 49 ms 6012 KB Output is correct
54 Correct 60 ms 5972 KB Output is correct
55 Correct 37 ms 5820 KB Output is correct
56 Correct 42 ms 5992 KB Output is correct
57 Correct 51 ms 5824 KB Output is correct
58 Correct 37 ms 5032 KB Output is correct
59 Correct 48 ms 6060 KB Output is correct