답안 #547058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547058 2022-04-09T10:03:48 Z nonsensenonsense1 Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
564 ms 23272 KB
#include <cstdio>
#include <set>

struct frac {
	int a, b;
	frac(int a_ = 0, int b_ = 0) {
		a = a_;
		b = b_;
	}
};

bool operator<(frac a, frac b) {
	return (long long)a.a * b.b < (long long)b.a * a.b;
}

const int N = 100000;
int h, w, a[N], b[N];
bool rmx[N], rmy[N];
std::set<std::pair<frac, int> > st;
std::set<int> x, y;

int main() {
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; ++i) {
		x.insert(i);
		scanf("%d", a + i);
		if (i) st.insert(std::make_pair(frac(a[i - 1] - a[i], 1), i));
	}
	for (int i = 0; i < w; ++i) {
		y.insert(i);
		scanf("%d", b + i);
		if (i) st.insert(std::make_pair(frac(b[i - 1] - b[i], 1), h + i));
	}
	long long ans = 0;
	while (st.size()) {
		int pos = st.begin()->second;
		st.erase(st.begin());
		if (pos < h) {
			if (!rmx[pos]) {
				rmx[pos] = 1;
				x.erase(pos);
				std::set<int>::iterator it = x.lower_bound(pos);
				if (it == x.end()) ans += (long long)b[*prev(y.end())] * (pos - *prev(it));
				else st.insert(std::make_pair(frac(a[*prev(it)] - a[*it], *it - *prev(it)), *it));
			}
		} else {
			pos -= h;
			if (!rmy[pos]) {
				rmy[pos] = 1;
				y.erase(pos);
				std::set<int>::iterator it = y.lower_bound(pos);
				if (it == y.end()) ans += (long long)a[*prev(x.end())] * (pos - *prev(it));
				else st.insert(std::make_pair(frac(b[*prev(it)] - b[*it], *it - *prev(it)), h + *it));
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d%d", &h, &w);
      |  ~~~~~^~~~~~~~~~~~~~~~
kyoto.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d", a + i);
      |   ~~~~~^~~~~~~~~~~~~
kyoto.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d", b + i);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 160 ms 9744 KB Output is correct
5 Correct 68 ms 8944 KB Output is correct
6 Correct 44 ms 3920 KB Output is correct
7 Correct 530 ms 23160 KB Output is correct
8 Correct 550 ms 23156 KB Output is correct
9 Correct 563 ms 23116 KB Output is correct
10 Correct 533 ms 23144 KB Output is correct
11 Correct 144 ms 23116 KB Output is correct
12 Correct 529 ms 23116 KB Output is correct
13 Correct 525 ms 23252 KB Output is correct
14 Correct 278 ms 23152 KB Output is correct
15 Correct 155 ms 23040 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 160 ms 9744 KB Output is correct
33 Correct 68 ms 8944 KB Output is correct
34 Correct 44 ms 3920 KB Output is correct
35 Correct 530 ms 23160 KB Output is correct
36 Correct 550 ms 23156 KB Output is correct
37 Correct 563 ms 23116 KB Output is correct
38 Correct 533 ms 23144 KB Output is correct
39 Correct 144 ms 23116 KB Output is correct
40 Correct 529 ms 23116 KB Output is correct
41 Correct 525 ms 23252 KB Output is correct
42 Correct 278 ms 23152 KB Output is correct
43 Correct 155 ms 23040 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 173 ms 10352 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 10 ms 1332 KB Output is correct
58 Correct 35 ms 3300 KB Output is correct
59 Correct 560 ms 23220 KB Output is correct
60 Correct 563 ms 23272 KB Output is correct
61 Correct 558 ms 23236 KB Output is correct
62 Correct 554 ms 23180 KB Output is correct
63 Correct 150 ms 23140 KB Output is correct
64 Correct 559 ms 23160 KB Output is correct
65 Correct 564 ms 23092 KB Output is correct
66 Correct 194 ms 23116 KB Output is correct
67 Correct 152 ms 23204 KB Output is correct