답안 #15863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15863 2015-07-31T16:28:17 Z myungwoo Palembang Bridges (APIO15_bridge) C++14
63 / 100
2000 ms 4936 KB
#include <bits/stdc++.h>
using namespace std;

#define MAXN 100005
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef long long lld;

int K, N, M;

struct Z{
	int a, b;
} A[MAXN];

lld proc(vector <int> &arr)
{
	if (arr.empty()) return 0;
	lld ret = 0;
	sort(all(arr));
	int x = arr[sz(arr)/2];
	for (int t: arr) ret += abs(t - x);
	return ret;
}

int main()
{
	scanf("%d%d", &K, &M);
	vector <int> arr;
	lld def = 0;
	while (M--){
		char p, q; int a, b;
		scanf(" %c%d %c%d", &p, &a, &q, &b);
		if (p == q){
			def += abs(a-b);
			continue;
		}
		def++;
		if (a > b) swap(a, b);
		A[++N] = {a, b};
	}
	sort(A+1, A+N+1, [](const Z &a, const Z &b){
		return a.a+a.b < b.a+b.b;
	});
	lld ans = 1e18;
	for (int i=0;i<=N;i++){
		vector <int> arr1, arr2;
		for (int j=1;j<=N;j++)
			if (j <= i)
				arr1.pb(A[j].a), arr1.pb(A[j].b);
			else
				arr2.pb(A[j].a), arr2.pb(A[j].b);
		lld val = def + proc(arr1) + proc(arr2);
		ans = min(ans, val);
		if (K == 1) break;
	}
	printf("%lld\n", ans);
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:28:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &K, &M);
                       ^
bridge.cpp:33:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c%d %c%d", &p, &a, &q, &b);
                                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2804 KB Output is correct
2 Correct 0 ms 2804 KB Output is correct
3 Correct 0 ms 2804 KB Output is correct
4 Correct 0 ms 2804 KB Output is correct
5 Correct 0 ms 2804 KB Output is correct
6 Correct 0 ms 2804 KB Output is correct
7 Correct 0 ms 2804 KB Output is correct
8 Correct 0 ms 2804 KB Output is correct
9 Correct 0 ms 2804 KB Output is correct
10 Correct 0 ms 2804 KB Output is correct
11 Correct 0 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2804 KB Output is correct
2 Correct 0 ms 2804 KB Output is correct
3 Correct 0 ms 2804 KB Output is correct
4 Correct 0 ms 2804 KB Output is correct
5 Correct 0 ms 2804 KB Output is correct
6 Correct 0 ms 2804 KB Output is correct
7 Correct 0 ms 2804 KB Output is correct
8 Correct 0 ms 2804 KB Output is correct
9 Correct 0 ms 2804 KB Output is correct
10 Correct 0 ms 2804 KB Output is correct
11 Correct 0 ms 2804 KB Output is correct
12 Correct 33 ms 4424 KB Output is correct
13 Correct 106 ms 4424 KB Output is correct
14 Correct 53 ms 4424 KB Output is correct
15 Correct 43 ms 3656 KB Output is correct
16 Correct 36 ms 4424 KB Output is correct
17 Correct 53 ms 4424 KB Output is correct
18 Correct 46 ms 4424 KB Output is correct
19 Correct 53 ms 4424 KB Output is correct
20 Correct 43 ms 4424 KB Output is correct
21 Correct 43 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2804 KB Output is correct
2 Correct 0 ms 2804 KB Output is correct
3 Correct 0 ms 2804 KB Output is correct
4 Correct 0 ms 2804 KB Output is correct
5 Correct 0 ms 2804 KB Output is correct
6 Correct 0 ms 2804 KB Output is correct
7 Correct 0 ms 2804 KB Output is correct
8 Correct 0 ms 2804 KB Output is correct
9 Correct 0 ms 2804 KB Output is correct
10 Correct 0 ms 2804 KB Output is correct
11 Correct 0 ms 2804 KB Output is correct
12 Correct 0 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2804 KB Output is correct
2 Correct 0 ms 2804 KB Output is correct
3 Correct 0 ms 2804 KB Output is correct
4 Correct 0 ms 2804 KB Output is correct
5 Correct 0 ms 2804 KB Output is correct
6 Correct 0 ms 2804 KB Output is correct
7 Correct 0 ms 2804 KB Output is correct
8 Correct 0 ms 2804 KB Output is correct
9 Correct 0 ms 2804 KB Output is correct
10 Correct 0 ms 2804 KB Output is correct
11 Correct 0 ms 2804 KB Output is correct
12 Correct 0 ms 2804 KB Output is correct
13 Correct 26 ms 2804 KB Output is correct
14 Correct 93 ms 2804 KB Output is correct
15 Correct 106 ms 2804 KB Output is correct
16 Correct 3 ms 2804 KB Output is correct
17 Correct 33 ms 2804 KB Output is correct
18 Correct 13 ms 2804 KB Output is correct
19 Correct 29 ms 2804 KB Output is correct
20 Correct 29 ms 2804 KB Output is correct
21 Correct 76 ms 2804 KB Output is correct
22 Correct 49 ms 2804 KB Output is correct
23 Correct 33 ms 2804 KB Output is correct
24 Correct 29 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2804 KB Output is correct
2 Correct 0 ms 2804 KB Output is correct
3 Correct 0 ms 2804 KB Output is correct
4 Correct 0 ms 2804 KB Output is correct
5 Correct 0 ms 2804 KB Output is correct
6 Correct 0 ms 2804 KB Output is correct
7 Correct 0 ms 2804 KB Output is correct
8 Correct 0 ms 2804 KB Output is correct
9 Correct 0 ms 2804 KB Output is correct
10 Correct 0 ms 2804 KB Output is correct
11 Correct 0 ms 2804 KB Output is correct
12 Correct 0 ms 2804 KB Output is correct
13 Correct 29 ms 2804 KB Output is correct
14 Correct 89 ms 2804 KB Output is correct
15 Correct 103 ms 2804 KB Output is correct
16 Correct 3 ms 2804 KB Output is correct
17 Correct 33 ms 2804 KB Output is correct
18 Correct 13 ms 2804 KB Output is correct
19 Correct 36 ms 2804 KB Output is correct
20 Correct 29 ms 2804 KB Output is correct
21 Correct 69 ms 2804 KB Output is correct
22 Correct 29 ms 2804 KB Output is correct
23 Correct 39 ms 2804 KB Output is correct
24 Correct 29 ms 2804 KB Output is correct
25 Execution timed out 2000 ms 4936 KB Execution timed out
26 Halted 0 ms 0 KB -