Submission #721995

#TimeUsernameProblemLanguageResultExecution timeMemory
721995n0sk1llPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0) #define mp make_pair #define xx first #define yy second #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define all(x) x.begin(),x.end() #define ff(i,a,b) for (int i = a; i < b; i++) #define fff(i,a,b) for (int i = a; i <= b; i++) #define bff(i,a,b) for (int i = b-1; i >= a; i--) #define bfff(i,a,b) for (int i = b; i >= a; i--) using namespace std; long double typedef ld; unsigned int typedef ui; long long int typedef li; pair<int,int> typedef pii; pair<li,li> typedef pli; pair<ld,ld> typedef pld; vector<vector<int>> typedef graph; unsigned long long int typedef ull; //const int mod = 998244353; //const int mod = 1000000007; //Note to self: Check for overflow vector<pii> segs; map<int,li> stat; map<int,li> koef; set<int> kords; li solve1() { int n=(int)segs.size(); for (auto [l,r] : segs) { kords.insert(l),kords.insert(r+1); stat[0]+=r,stat[r+1]-=r,koef[0]--,koef[r+1]++; //adduje jednu pravu y=-x + qrac koef[l]++; //adduje drugu pravu y=x + qrac } li k=0,s=0,ans=4e18; for (auto x : kords) { k+=koef[x],s+=stat[x]; ans=min(ans,k*x+s); } return ans; } li solve2() { return 0ll; } int main() { FAST; li neces=0; int k,n; cin>>k>>n; ff(i,0,n) { char _,__; int a,b; cin>>_>>a>>__>>b; if (a>b) swap(a,b); if (_!=__) segs.pb({a,b}); else neces+=b-a; } if (k==1) cout<<neces+solve1()<<"\n"; else cout<<neces+solve2()<<"\n"; } //Note to self: Check for overflow /* 1 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */

Compilation message (stderr)

bridge.cpp: In function 'li solve1()':
bridge.cpp:44:9: warning: unused variable 'n' [-Wunused-variable]
   44 |     int n=(int)segs.size();
      |         ^
#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...