Submission #56596

#TimeUsernameProblemLanguageResultExecution timeMemory
56596leejseoPalembang Bridges (APIO15_bridge)C++11
22 / 100
72 ms1840 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> 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{ 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 = (int) 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 (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:85: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...