Submission #954545

#TimeUsernameProblemLanguageResultExecution timeMemory
954545hihihihawPalembang Bridges (APIO15_bridge)C++17
22 / 100
33 ms4332 KiB
#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define pii pair<int,int> #define sz(v) (int)v.size() #define fi first #define se second #define INF 1223372036854775807 #define MOD 1000000007 #define cint(x) int x;cin>>x; #define cinarr(a,n) int a[n];for (int i=0;i<n;i++) cin>>a[i]; #define coutarr(a) for (auto d:a) cout<<d<<" "; cout<<endl; #define coutarrD(a) for (auto d:a) cout<<d.fi<<","<<d.se<<" "; cout<<endl; #define AYBERK_SARICA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define endl '\n' #define ld long double int t=1; int usaco=0; vector<pii> v; int f(int x){ int ans=0; for (auto d:v)ans+=abs(x-d.fi)+abs(x-d.se)+1; return ans; } void solve(){ int k,n; cin>>k>>n; int ans=0; while (n--){ char a,b; int x,y; cin>>a>>x>>b>>y; if (a==b) ans+=abs(x-y); else{ v.pb({x,y}); } } int l=0,r=9999999999; while (r>=l){ int m=(l+r)/2; if (f(m)<=f(m+1)) r=m-1; else l=m+1; } cout<<f(l)+ans<<endl; } int32_t main(){ AYBERK_SARICA; if (usaco){ freopen("hayfeast.in", "r", stdin); freopen("hayfeast.out", "w", stdout); } #ifdef Local freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); //freopen("wormsort.out", "w", stdout); #endif if (t==1) solve(); else{ cin>>t; while (t--) solve(); } return 0; }

Compilation message (stderr)

bridge.cpp: In function 'int32_t main()':
bridge.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen("hayfeast.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen("hayfeast.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...