Submission #244400

#TimeUsernameProblemLanguageResultExecution timeMemory
244400WhaleVomitPalembang Bridges (APIO15_bridge)C++14
22 / 100
391 ms41872 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define MOO(i, a, b) for(int i=a; i<b; i++) #define M00(i, a) for(int i=0; i<a; i++) #define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--) #define M00d(i,a) for(int i = (a)-1; i>=0; i--) #define FAST ios::sync_with_stdio(0); cin.tie(0); #define finish(x) return cout << x << '\n', 0; #define dbg(x) cerr << ">>> " << #x << " = " << x << "\n"; #define _ << " _ " << typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int,int> pi; typedef pair<ld,ld> pd; typedef complex<ld> cd; const int MAX_N = 100100; int k, n; vector<pi> arr; map<int,vector<pi>> startsAt; map<int,vector<pi>> endsAt; vi points; ll getMinDis1() { ll cur = 0; ll numBefore = 0; ll numAfter = 0; for(pi p: arr) if(p.f > points[0]) { numAfter++; cur += p.f - points[0]; } ll ans = cur; MOO(i, 1, sz(points)) { cur -= numAfter*(points[i] - points[i-1]); for(pi p: startsAt[points[i]]) { numAfter--; } for(pi p: endsAt[points[i-1]]) { numBefore++; } cur += numBefore*(points[i] - points[i-1]); ans = min(ans, cur); } return ans; } ll getMinDis2() { return 0; } int main() { FAST cin >> k >> n; int cnt = 0; ll ans = 0; M00(i, n) { string s1, s2; int i1, i2; cin >> s1 >> i1 >> s2 >> i2; if(i1 > i2) swap(i1, i2); if(s1 == s2) { ans += (i2-i1); } else { cnt++; ans += (i2-i1); arr.pb(mp(i1,i2)); if(!startsAt.count(i1)) startsAt[i1].clear(); startsAt[i1].pb(mp(i1,i2)); if(!endsAt.count(i2)) endsAt[i2].clear(); endsAt[i2].pb(mp(i1,i2)); points.pb(i1); points.pb(i2); } } sort(all(points)); points.erase(unique(all(points)), points.end()); if(k == 1) { ans += getMinDis1()*2LL + cnt; } else { ans += getMinDis2()*2LL + cnt; } finish(ans); }

Compilation message (stderr)

bridge.cpp: In function 'll getMinDis1()':
bridge.cpp:46:16: warning: variable 'p' set but not used [-Wunused-but-set-variable]
         for(pi p: startsAt[points[i]]) {
                ^
bridge.cpp:49:16: warning: variable 'p' set but not used [-Wunused-but-set-variable]
         for(pi p: endsAt[points[i-1]]) {
                ^
#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...