제출 #45781

#제출 시각아이디문제언어결과실행 시간메모리
45781TalantPalembang Bridges (APIO15_bridge)C++17
0 / 100
3 ms620 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define OK puts("OK"); #define pb push_back #define mk make_pair #define int long long using namespace std; const int inf = (int)1e9 + 7; const int N = (int)2e5 + 7; int k,n; int x,y; int suma,sumb; int pos,pos1; int ca,cb; int ans = inf,cur; char ch,ch1; vector <int> a,b; int f (int x) { suma = 0,sumb = 0; for (int i = 0; i < (int)a.size(); i ++) suma += abs(a[i] - x),sumb += abs(b[i] - x); return (suma + sumb + cur + (int)a.size()); } int fa (int x) { int sum = 0; for (int i = 0; i < a.size(); i ++) sum += abs(x - a[i]); return sum; } int fb (int x) { int sum = 0; for (int i = 0; i < b.size(); i ++) sum += abs(x - b[i]); return sum; } main () { cin >> k >> n; for (int i = 1; i <= n; i ++) { cin >> ch >> x >> ch1 >> y; if (ch == ch1) { cur += abs(x - y); } else { if (ch == 'A') a.pb(x),b.pb(y); else b.pb(x),a.pb(y); } } if (k == 1) { int l = 0,r = 1e9; while (r - l >= 3) { int m = l + (r - l) / 3; int m1 = r - (r - l) / 3; if (fa(m) < fa(m1)) r = m1; else l = m; } for (int i = l; i <= r; i ++) ans = min(ans,f(i)); l = 0,r = 1e9; while (r - l >= 3) { int m = l + (r - l) / 3; int m1 = r - (r - l) / 3; if (fb(m) < fb(m1)) r = m1; else l = m; } for (int i = l; i <= r; i ++) ans = min(ans,f(i)); cout << ans << endl; } } /** Sample 1 1 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 Sample 2 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 **/

컴파일 시 표준 에러 (stderr) 메시지

bridge.cpp: In function 'long long int fa(long long int)':
bridge.cpp:34:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < a.size(); i ++)
                       ~~^~~~~~~~~~
bridge.cpp: In function 'long long int fb(long long int)':
bridge.cpp:40:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < b.size(); i ++)
                       ~~^~~~~~~~~~
bridge.cpp: At global scope:
bridge.cpp:44:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  main () {
        ^
#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...