Submission #56598

# Submission time Handle Problem Language Result Execution time Memory
56598 2018-07-12T02:34:48 Z leejseo Palembang Bridges (APIO15_bridge) C++
63 / 100
2000 ms 5212 KB
#include <bits/stdc++.h>
using namespace std;
 
int K, N;
 
void solve1(){
	long long ans = 0;
	vector<int> L;
	int u, v;
	char x, y;
	for(int i=0; i<N; i++){
		scanf("%c %d %c %d\n", &x, &u, &y, &v);		
		if (x == y) ans += abs(u-v);
		else{
			L.push_back(u);
			L.push_back(v);
		}
	}
	sort(L.begin(), L.end());
	int M = L.size();
	if (M == 0){
		printf("%lld\n", ans);
		return;
	}
	long long mid = L[M/2];
	for (int i=0; i<M; i++) ans += abs(L[i] - mid);
	ans += M/2;
	printf("%lld\n", ans);
	L.clear();
	return;
}
 
void solve2(){
	long long ans = 0;
	vector<int> S;
	vector<int> X;
	vector<int> Y;
	int u, v;
	char x, y;
	for(int i=0; i<N; i++){
		scanf("%c %d %c %d\n", &x, &u, &y, &v);		
		if (x == y) ans += abs(u-v);
		else{
			if (u > v) swap(u, v);
			S.push_back(u+v);
			X.push_back(u);
			Y.push_back(v);
		}
	}
	int M = X.size();
	if (M == 0){
		printf("%lld\n", ans);
		return;
	}
	long long cross = (long long) 1e17;
	long long temp;
	sort(S.begin(), S.end());
	for (int i=0; i<M; i++){
		int s = S[i];
		vector<int> lo, hi;
		for (int j=0; j<M; j++){
			if (X[j] + Y[j] < s){
				lo.push_back(X[j]);
				lo.push_back(Y[j]);
			}
			else{
				hi.push_back(X[j]);
				hi.push_back(Y[j]);
			}
		}
		sort(lo.begin(), lo.end());
		sort(hi.begin(), hi.end());
		temp = 0LL;
		for (int j=0; j<M; j++){
			if (X[j] + Y[j] < s) temp += abs(X[j] - lo[lo.size()/2]) + abs(Y[j] - lo[lo.size()/2]);
			else temp += abs(X[j] - hi[hi.size()/2]) + abs(Y[j] - hi[hi.size()/2]);
		}
		cross = min(cross, temp);
	}
	ans += cross;
	ans += M;
	printf("%lld\n", ans);
	return;
}
int main(void){
	scanf("%d%d\n", &K, &N);
	if (K == 1) solve1();
	else solve2();
}

Compilation message

bridge.cpp: In function 'void solve1()':
bridge.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%c %d %c %d\n", &x, &u, &y, &v);  
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp: In function 'void solve2()':
bridge.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%c %d %c %d\n", &x, &u, &y, &v);  
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d\n", &K, &N);
  ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 500 KB Output is correct
4 Correct 3 ms 516 KB Output is correct
5 Correct 3 ms 572 KB Output is correct
6 Correct 3 ms 572 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 3 ms 640 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 2 ms 640 KB Output is correct
12 Correct 36 ms 1764 KB Output is correct
13 Correct 98 ms 1764 KB Output is correct
14 Correct 50 ms 1764 KB Output is correct
15 Correct 44 ms 1764 KB Output is correct
16 Correct 45 ms 1808 KB Output is correct
17 Correct 76 ms 1808 KB Output is correct
18 Correct 51 ms 1808 KB Output is correct
19 Correct 96 ms 1808 KB Output is correct
20 Correct 47 ms 1808 KB Output is correct
21 Correct 92 ms 1808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1808 KB Output is correct
2 Correct 2 ms 1808 KB Output is correct
3 Correct 3 ms 1808 KB Output is correct
4 Correct 3 ms 1808 KB Output is correct
5 Correct 2 ms 1808 KB Output is correct
6 Correct 2 ms 1808 KB Output is correct
7 Correct 3 ms 1808 KB Output is correct
8 Correct 3 ms 1808 KB Output is correct
9 Correct 2 ms 1808 KB Output is correct
10 Correct 4 ms 1808 KB Output is correct
11 Correct 2 ms 1808 KB Output is correct
12 Correct 3 ms 1808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1808 KB Output is correct
2 Correct 2 ms 1808 KB Output is correct
3 Correct 2 ms 1808 KB Output is correct
4 Correct 3 ms 1808 KB Output is correct
5 Correct 2 ms 1808 KB Output is correct
6 Correct 2 ms 1808 KB Output is correct
7 Correct 2 ms 1808 KB Output is correct
8 Correct 2 ms 1808 KB Output is correct
9 Correct 3 ms 1808 KB Output is correct
10 Correct 4 ms 1808 KB Output is correct
11 Correct 3 ms 1808 KB Output is correct
12 Correct 3 ms 1808 KB Output is correct
13 Correct 40 ms 1808 KB Output is correct
14 Correct 108 ms 1808 KB Output is correct
15 Correct 131 ms 1808 KB Output is correct
16 Correct 7 ms 1808 KB Output is correct
17 Correct 31 ms 1808 KB Output is correct
18 Correct 19 ms 1808 KB Output is correct
19 Correct 40 ms 1808 KB Output is correct
20 Correct 42 ms 1808 KB Output is correct
21 Correct 76 ms 1808 KB Output is correct
22 Correct 112 ms 1808 KB Output is correct
23 Correct 58 ms 1808 KB Output is correct
24 Correct 93 ms 1808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1808 KB Output is correct
2 Correct 2 ms 1808 KB Output is correct
3 Correct 2 ms 1808 KB Output is correct
4 Correct 2 ms 1808 KB Output is correct
5 Correct 2 ms 1808 KB Output is correct
6 Correct 2 ms 1808 KB Output is correct
7 Correct 3 ms 1808 KB Output is correct
8 Correct 3 ms 1808 KB Output is correct
9 Correct 3 ms 1808 KB Output is correct
10 Correct 4 ms 1808 KB Output is correct
11 Correct 2 ms 1808 KB Output is correct
12 Correct 4 ms 1808 KB Output is correct
13 Correct 37 ms 1808 KB Output is correct
14 Correct 99 ms 1808 KB Output is correct
15 Correct 128 ms 1808 KB Output is correct
16 Correct 7 ms 1808 KB Output is correct
17 Correct 31 ms 1808 KB Output is correct
18 Correct 19 ms 1808 KB Output is correct
19 Correct 35 ms 1808 KB Output is correct
20 Correct 37 ms 1808 KB Output is correct
21 Correct 55 ms 1808 KB Output is correct
22 Correct 114 ms 1808 KB Output is correct
23 Correct 39 ms 1808 KB Output is correct
24 Correct 84 ms 1808 KB Output is correct
25 Execution timed out 2051 ms 5212 KB Time limit exceeded
26 Halted 0 ms 0 KB -