제출 #937365

#제출 시각아이디문제언어결과실행 시간메모리
937365VinhLuuPalembang Bridges (APIO15_bridge)C++17
31 / 100
37 ms8320 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #define int long long #define ll long long #define fi first #define se second #define pb push_back #define all(lmao) lmao.begin(), lmao.end() using namespace std; typedef pair<int,int> pii; typedef tuple<int,int,int> tp; const int N = 2e5 + 5; const int oo = 1e16; const int mod = 1e9 + 7; const int K = 1e5 + 5; char P[N], Q[N]; int S[N], T[N], k, n, ans, s[N]; vector<int> vr; vector<pii> h; int cnt = 0; namespace sub1{ void solve(){ int ret = oo; for(int i = 1; i <= cnt << 1; i ++){ for(int j = i + 1; j <= cnt << 1; j ++){ int kq = 0; for(auto [l, r] : h){ if(l <= vr[i - 1] && vr[i - 1] <= r) kq += 1 + vr[i - 1] - l + r - vr[i - 1]; else if(l <= vr[j - 1] && vr[j - 1] <= r) kq += 1 + vr[j - 1] - l + r - vr[j - 1]; else if(vr[i - 1] <= l && r <= vr[j - 1]) kq += 1 + min(l - vr[i - 1] + r - vr[i - 1], vr[j - 1] - l + vr[j - 1] - r); else if(r <= vr[i - 1]) kq += 1 + vr[i - 1] - l + vr[i - 1] - r; else kq += 1 + l - vr[j - 1] + r - vr[j - 1]; } ret = min(ret, kq + ans); } } ans = ret; } } namespace sub2{ int cal(int i,int j){ int kq = 0; for(auto [l, r] : h){ if(l <= i && i <= r) kq += 1 + i - l + r - i; else if(l <= j && j <= r) kq += 1 + j - l + r - j; else if(i <= l && r <= j) kq += 1 + min(l - i + r - i, j - l + j - r); else if(r <= i) kq += 1 + i - l + i - r; else kq += 1 + l - j + r - j; } } void solve(){ int ret = oo; for(int i = 1; i <= cnt << 1; i ++){ int l = vr[i - 1] + 1, r = min((int)1e9, vr[cnt * 2 - 1]), mid, pos; while(l < r){ mid = (l + r) >> 1; int u = cal(vr[i - 1], mid); int v = cal(vr[i - 1], mid + 1); if(u > v) l = mid + 1; else r = mid; ret = min({ret, u, v}); } } ans = ret + ans; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> k >> n; for(int i = 1; i <= n; i ++){ cin >> P[i] >> S[i] >> Q[i] >> T[i]; if(P[i] == Q[i]){ ans += abs(S[i] - T[i]); continue; } vr.pb(S[i]); vr.pb(T[i]); cnt++; if(S[i] > T[i]) swap(S[i], T[i]); h.pb({S[i], T[i]}); } if(!vr.empty()){ sort(vr.begin(), vr.end()); int mx = 0; for(int i = 1; i <= cnt * 2; i ++) mx = max(mx, vr[i - 1]), s[i] = s[i - 1] + vr[i - 1]; if(k == 1){ int kq = oo; int lim = vr[cnt - 1]; for(int j = max(vr[0], lim - (int)1e5); j <= min(vr[2 * cnt - 1], lim + (int)1e5); j ++){ int i = lower_bound(all(vr), j) - vr.begin(); if(i < 2 * cnt){ i++;} kq = min(kq, cnt + j * (i - 1) - j * (2 * cnt - i + 1) - s[i - 1] + s[cnt * 2] - s[i - 1]); } ans = ans + kq; }else{ if(n <= 100) sub1 :: solve(); else sub2 :: solve(); } } cout << ans; }

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

bridge.cpp: In function 'long long int sub2::cal(long long int, long long int)':
bridge.cpp:59:5: warning: no return statement in function returning non-void [-Wreturn-type]
   59 |     }
      |     ^
bridge.cpp: In function 'void sub2::solve()':
bridge.cpp:63:77: warning: unused variable 'pos' [-Wunused-variable]
   63 |             int l = vr[i - 1] + 1, r = min((int)1e9, vr[cnt * 2 - 1]), mid, pos;
      |                                                                             ^~~
bridge.cpp: In function 'int main()':
bridge.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(task ".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...