답안 #40579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40579 2018-02-05T07:16:05 Z Waschbar Palembang Bridges (APIO15_bridge) C++14
100 / 100
494 ms 53800 KB
#include <bits/stdc++.h>
 
using namespace std; 
 
#define mp make_pair
typedef pair<int, int> pii;
 
vector<int> points;
long long easy;
long long ans;
long long lt[110000];
long long rt[110000];
int n, k;
vector< pii > bridge;
 
bool compara(pii a, pii b) {
	return a.first + a.second < b.first + b.second;
}
 
template<class T> 
void calc(T it, T ed, long long *arr) {
	multiset<int> sm;
	multiset<int> bg;
 
	long long ssm = 0;
	long long sbg = 0;
 
	int c = 0;
	arr[c++] = 0;
 
	while (it != ed) {
		sm.insert(it->first);
		ssm += it->first;
		bg.insert(it->second);
		sbg += it->second;
 
		while (*sm.rbegin() > *bg.begin()) {
			sbg += *sm.rbegin() - *bg.begin();
			ssm += *bg.begin() - *sm.rbegin();
			bg.insert(*sm.rbegin());
			sm.insert(*bg.begin());
			bg.erase(bg.begin());
			sm.erase(--sm.end());
		}
 
		arr[c++] = sbg - ssm;
		it++;
	}
}
 
int main() {
	scanf("%d %d", &k, &n);
 
	for (int i = 0; i < n; i++) {
		char t1, t2;
		int x, y;
		scanf(" %c %d %c %d", &t1, &x, &t2, &y);
		if (t1 == t2) easy += abs(y-x);
		else bridge.push_back(mp(x, y));
	}
 
	sort(bridge.begin(), bridge.end(), compara);
 
	calc(bridge.begin(), bridge.end(), lt); // prefixes
	calc(bridge.rbegin(), bridge.rend(), rt); // suffixes
 
	n = bridge.size();
 
	if (k == 1) {
		ans = rt[n];
	}
	else {
		ans = 1000000000000000000LL;
		for (int in_lt = 0; in_lt <= n; in_lt++) {
			ans = min(ans, lt[in_lt] + rt[n - in_lt]);
		}
	}
 
	printf("%lld\n", easy + ans + n);
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:52:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &k, &n);
                        ^
bridge.cpp:57:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c %d %c %d", &t1, &x, &t2, &y);
                                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 4 ms 656 KB Output is correct
6 Correct 3 ms 704 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 752 KB Output is correct
9 Correct 3 ms 836 KB Output is correct
10 Correct 8 ms 988 KB Output is correct
11 Correct 3 ms 988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 988 KB Output is correct
2 Correct 2 ms 988 KB Output is correct
3 Correct 3 ms 988 KB Output is correct
4 Correct 3 ms 1000 KB Output is correct
5 Correct 4 ms 1000 KB Output is correct
6 Correct 2 ms 1064 KB Output is correct
7 Correct 3 ms 1084 KB Output is correct
8 Correct 3 ms 1108 KB Output is correct
9 Correct 3 ms 1128 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1172 KB Output is correct
12 Correct 194 ms 13592 KB Output is correct
13 Correct 439 ms 16012 KB Output is correct
14 Correct 392 ms 16064 KB Output is correct
15 Correct 214 ms 16064 KB Output is correct
16 Correct 180 ms 20048 KB Output is correct
17 Correct 261 ms 22524 KB Output is correct
18 Correct 143 ms 24420 KB Output is correct
19 Correct 264 ms 26956 KB Output is correct
20 Correct 219 ms 28832 KB Output is correct
21 Correct 258 ms 30740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 30740 KB Output is correct
2 Correct 2 ms 30740 KB Output is correct
3 Correct 2 ms 30740 KB Output is correct
4 Correct 3 ms 30740 KB Output is correct
5 Correct 2 ms 30740 KB Output is correct
6 Correct 2 ms 30740 KB Output is correct
7 Correct 2 ms 30740 KB Output is correct
8 Correct 2 ms 30740 KB Output is correct
9 Correct 2 ms 30740 KB Output is correct
10 Correct 2 ms 30740 KB Output is correct
11 Correct 2 ms 30740 KB Output is correct
12 Correct 2 ms 30740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 30740 KB Output is correct
2 Correct 2 ms 30740 KB Output is correct
3 Correct 2 ms 30740 KB Output is correct
4 Correct 2 ms 30740 KB Output is correct
5 Correct 2 ms 30740 KB Output is correct
6 Correct 2 ms 30740 KB Output is correct
7 Correct 2 ms 30740 KB Output is correct
8 Correct 2 ms 30740 KB Output is correct
9 Correct 2 ms 30740 KB Output is correct
10 Correct 2 ms 30740 KB Output is correct
11 Correct 2 ms 30740 KB Output is correct
12 Correct 2 ms 30740 KB Output is correct
13 Correct 3 ms 30740 KB Output is correct
14 Correct 3 ms 30740 KB Output is correct
15 Correct 4 ms 30740 KB Output is correct
16 Correct 2 ms 30740 KB Output is correct
17 Correct 2 ms 30740 KB Output is correct
18 Correct 2 ms 30740 KB Output is correct
19 Correct 3 ms 30740 KB Output is correct
20 Correct 3 ms 30740 KB Output is correct
21 Correct 3 ms 30740 KB Output is correct
22 Correct 3 ms 30740 KB Output is correct
23 Correct 3 ms 30740 KB Output is correct
24 Correct 3 ms 30740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 30740 KB Output is correct
2 Correct 1 ms 30740 KB Output is correct
3 Correct 1 ms 30740 KB Output is correct
4 Correct 2 ms 30740 KB Output is correct
5 Correct 2 ms 30740 KB Output is correct
6 Correct 2 ms 30740 KB Output is correct
7 Correct 2 ms 30740 KB Output is correct
8 Correct 2 ms 30740 KB Output is correct
9 Correct 2 ms 30740 KB Output is correct
10 Correct 2 ms 30740 KB Output is correct
11 Correct 2 ms 30740 KB Output is correct
12 Correct 2 ms 30740 KB Output is correct
13 Correct 2 ms 30740 KB Output is correct
14 Correct 3 ms 30740 KB Output is correct
15 Correct 3 ms 30740 KB Output is correct
16 Correct 2 ms 30740 KB Output is correct
17 Correct 2 ms 30740 KB Output is correct
18 Correct 2 ms 30740 KB Output is correct
19 Correct 3 ms 30740 KB Output is correct
20 Correct 3 ms 30740 KB Output is correct
21 Correct 3 ms 30740 KB Output is correct
22 Correct 3 ms 30740 KB Output is correct
23 Correct 3 ms 30740 KB Output is correct
24 Correct 3 ms 30740 KB Output is correct
25 Correct 194 ms 32172 KB Output is correct
26 Correct 328 ms 33312 KB Output is correct
27 Correct 456 ms 34928 KB Output is correct
28 Correct 491 ms 37216 KB Output is correct
29 Correct 494 ms 39548 KB Output is correct
30 Correct 195 ms 39548 KB Output is correct
31 Correct 177 ms 42328 KB Output is correct
32 Correct 250 ms 44736 KB Output is correct
33 Correct 156 ms 46708 KB Output is correct
34 Correct 255 ms 49092 KB Output is correct
35 Correct 222 ms 50868 KB Output is correct
36 Correct 262 ms 53092 KB Output is correct
37 Correct 162 ms 53800 KB Output is correct