Submission #243295

#TimeUsernameProblemLanguageResultExecution timeMemory
243295Leonardo_PaesPalembang Bridges (APIO15_bridge)C++17
0 / 100
12 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e18+10; int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int k, n; cin >> k >> n; int ans1 = 0, ans2 = inf; vector<int> a, b; for(int i=1; i<=n; i++){ int s, t; char p, q; cin >> p >> s >> q >> t; if(p == q) ans1 += abs(s - t); else{ if(p == 'B') swap(s, t); a.push_back(s); b.push_back(t); } } sort(a.begin(), a.end()); sort(b.begin(), b.end()); for(int i=0; i<a.size(); i++){ int tot = 0; for(int j=0; j<i; j++) tot += abs(a[i] - a[j]); for(int j=i+1; j<a.size(); j++) tot += abs(a[i] - a[j]); for(int j=0; j<b.size(); j++) tot += abs(a[i] - b[j]); ans2 = min(ans2, tot); } for(int i=0; i<b.size(); i++){ int tot = 0; for(int j=0; j<i; j++) tot += abs(b[i] - b[j]); for(int j=i+1; j<b.size(); j++) tot += (b[i] - b[j]); for(int j=0; j<a.size(); j++) tot += abs(a[i] - b[j]); ans2 = min(ans2, tot); } if(ans2 == inf) ans2 = 0; cout << ans1 + ans2 + (int)a.size() << "\n"; return 0; }

Compilation message (stderr)

bridge.cpp: In function 'int32_t main()':
bridge.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<a.size(); i++){
                  ~^~~~~~~~~
bridge.cpp:27:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=i+1; j<a.size(); j++) tot += abs(a[i] - a[j]);
                        ~^~~~~~~~~
bridge.cpp:28:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<b.size(); j++) tot += abs(a[i] - b[j]);
                      ~^~~~~~~~~
bridge.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<b.size(); i++){
                  ~^~~~~~~~~
bridge.cpp:34:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=i+1; j<b.size(); j++) tot += (b[i] - b[j]);
                        ~^~~~~~~~~
bridge.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<a.size(); j++) tot += abs(a[i] - b[j]);
                      ~^~~~~~~~~
#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...