제출 #411945

#제출 시각아이디문제언어결과실행 시간메모리
411945cpp219Palembang Bridges (APIO15_bridge)C++14
31 / 100
2080 ms10568 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 9; const ll Log2 = 20; const ll inf = 1e16 + 7; typedef pair<ll,ll> LL; vector<ll> v; ll k,n,ans,inc,in[N],out[N]; struct human{ char x,y; ll L,R; }; human a[N]; ll Find(ll x){ return lower_bound(v.begin(),v.end(),x) - v.begin() + 1; } void compress(){ sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin()); //for (ll i = 1;i <= n;i++) a[i].L = Find(a[i].L),a[i].R = Find(a[i].R); } ll bit1[N],bit2[N]; void upd(ll p,ll val,ll bit[]){ for (ll i = p;i < N;i += i & -i) bit[i] += val; } ll Get(ll p,ll bit[]){ ll res = 0; for (ll i = p;i > 0;i -= i & -i) res += bit[i]; return res; } ll cal_opt(ll opt){ ll inc = 0; for (ll i = 1;i <= n;i++){ if (a[i].x == a[i].y) continue; if (a[i].L > opt) inc += 2*(a[i].L - opt); if (a[i].R < opt) inc += 2*(opt - a[i].R); } return inc; } void Sub1(){ for (ll i = 1;i <= n;i++){ if (a[i].x != a[i].y) in[Find(a[i].L)]++,out[Find(a[i].R)]++; } for (ll i = 1;i < N;i++) upd(i,out[i],bit1),upd(i,in[i],bit2); ll opt,inc = inf; for (ll j = 0;j < v.size();j++){ ll i = j + 1; //cout<<Get(2,bit1)<<" "<<out[0]; exit(0); ll l = Get(i - 1,bit1),r = Get(N - 1,bit2) - Get(i,bit2); //cout<<v[j]<<" "<<l<<" x "<<r<<"\n"; if (l >= r){ opt = j; break; } } cout<<ans + min(cal_opt(v[opt]),cal_opt(v[opt - 1])); } ll cal_opt2(ll opt1,ll opt2){ ll inc = 0; for (ll i = 1;i <= n;i++){ if (a[i].x == a[i].y) continue; ll now1 = 0,now2 = 0; if (a[i].L > opt1) now1 = 2*(a[i].L - opt1); if (a[i].R < opt1) now1 = 2*(opt1 - a[i].R); if (a[i].L > opt2) now2 = 2*(a[i].L - opt2); if (a[i].R < opt2) now2 = 2*(opt2 - a[i].R); inc += min(now1,now2); } return inc; } void Sub2(){ ll inc = inf; for (ll i = 0;i < v.size();i++){ for (ll j = i + 1;j < v.size();j++) inc = min(inc,cal_opt2(v[i],v[j])); } cout<<ans + inc; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "test" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin>>k>>n; for (ll i = 1;i <= n;i++){ cin>>a[i].x>>a[i].L>>a[i].y>>a[i].R; if (a[i].L > a[i].R) swap(a[i].L,a[i].R); ans += a[i].R - a[i].L; v.push_back(a[i].L); v.push_back(a[i].R); if (a[i].x != a[i].y) ans++; } compress(); if (k == 1) Sub1(); else Sub2(); }

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

bridge.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
bridge.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
bridge.cpp: In function 'void Sub1()':
bridge.cpp:59:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (ll j = 0;j < v.size();j++){
      |                   ~~^~~~~~~~~~
bridge.cpp:58:12: warning: unused variable 'inc' [-Wunused-variable]
   58 |     ll opt,inc = inf;
      |            ^~~
bridge.cpp: In function 'void Sub2()':
bridge.cpp:87:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for (ll i = 0;i < v.size();i++){
      |                   ~~^~~~~~~~~~
bridge.cpp:88:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for (ll j = i + 1;j < v.size();j++) inc = min(inc,cal_opt2(v[i],v[j]));
      |                           ~~^~~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp: In function 'void Sub1()':
bridge.cpp:67:34: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |     cout<<ans + min(cal_opt(v[opt]),cal_opt(v[opt - 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...