답안 #440057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440057 2021-07-01T14:27:40 Z gromperen Unija (COCI17_unija) C++14
100 / 100
361 ms 32564 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n; cin >> n;
	vector<pair<ll,ll>> v(n), a;
	ll ans = 0;
	for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	ll prev = 0, prevy = 0;
	for (int i = 0; i < n; ++i) {
		if (v[i].first == prev ) continue;
		if (v[i].second <= prevy) continue;
		a.push_back(v[i]);
		prev = v[i].first;
		prevy = v[i].second;
	}
	for (int i = 0; i < a.size(); ++i) {
		ans += a[i].second * (a[i].first - ((i < a.size() - 1) ? a[i+1].first : 0));
	}
	cout << ans << "\n";


	return 0;
}

Compilation message

unija.cpp: In function 'int main()':
unija.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i = 0; i < a.size(); ++i) {
      |                  ~~^~~~~~~~~~
unija.cpp:26:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   ans += a[i].second * (a[i].first - ((i < a.size() - 1) ? a[i+1].first : 0));
      |                                        ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 32564 KB Output is correct
2 Correct 358 ms 32460 KB Output is correct
3 Correct 357 ms 32464 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
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 716 KB Output is correct
2 Correct 9 ms 1100 KB Output is correct
3 Correct 9 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1868 KB Output is correct
2 Correct 32 ms 3156 KB Output is correct
3 Correct 32 ms 3276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 4940 KB Output is correct
2 Correct 94 ms 9028 KB Output is correct
3 Correct 101 ms 8972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 15948 KB Output is correct
2 Correct 353 ms 31072 KB Output is correct
3 Correct 350 ms 30936 KB Output is correct