답안 #56563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56563 2018-07-11T17:32:42 Z leejseo Palembang Bridges (APIO15_bridge) C++
22 / 100
81 ms 1880 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> L(0);
	vector<int> X(0);
	vector<int> Y(0);
	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);
			X.push_back(u);
			Y.push_back(v);
		}
	}
	int M = X.size();
	if (M == 0){
		printf("%lld\n", ans);
		return;
	}
	long long cross = (int) 1e17;
	for (int i=0; i<M; i++){
		for (int j=0; j<i; j++){
			long long b1 = L[i];
			long long b2 = L[j];
			long long temp = 0;
			for (int k=0; k<M; k++){
				temp += (long long) min(abs(X[k]-b1) + 1 + abs(Y[k]-b1), abs(X[k]-b2) + 1 + abs(Y[k]-b2));
			}
			cross = min(cross, temp);
		}
	}	
	X.clear();
	Y.clear();
	L.clear();
	ans += cross;
	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:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d\n", &K, &N);
  ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 484 KB Output is correct
7 Correct 3 ms 608 KB Output is correct
8 Correct 3 ms 608 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 3 ms 608 KB Output is correct
11 Correct 3 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 608 KB Output is correct
2 Correct 2 ms 608 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 3 ms 608 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 4 ms 608 KB Output is correct
8 Correct 3 ms 608 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 3 ms 608 KB Output is correct
11 Correct 2 ms 612 KB Output is correct
12 Correct 36 ms 1876 KB Output is correct
13 Correct 72 ms 1876 KB Output is correct
14 Correct 50 ms 1876 KB Output is correct
15 Correct 41 ms 1876 KB Output is correct
16 Correct 41 ms 1876 KB Output is correct
17 Correct 69 ms 1876 KB Output is correct
18 Correct 56 ms 1876 KB Output is correct
19 Correct 81 ms 1880 KB Output is correct
20 Correct 44 ms 1880 KB Output is correct
21 Correct 56 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 2 ms 1880 KB Output is correct
3 Correct 5 ms 1880 KB Output is correct
4 Incorrect 5 ms 1880 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 3 ms 1880 KB Output is correct
3 Correct 3 ms 1880 KB Output is correct
4 Incorrect 5 ms 1880 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 2 ms 1880 KB Output is correct
3 Correct 4 ms 1880 KB Output is correct
4 Incorrect 3 ms 1880 KB Output isn't correct
5 Halted 0 ms 0 KB -