Submission #56597

#TimeUsernameProblemLanguageResultExecution timeMemory
56597leejseoPalembang Bridges (APIO15_bridge)C++98
31 / 100
2062 ms1892 KiB
#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 = (long long) 1e17; for (int i=0; i<2*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 (stderr)

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);
  ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...