제출 #585453

#제출 시각아이디문제언어결과실행 시간메모리
585453Tien_NoobPalembang Bridges (APIO15_bridge)C++17
22 / 100
218 ms14388 KiB
//Make CSP great again //Vengeance #include <bits/stdc++.h> #define TASK "TESTCODE" #define Log2(x) 31 - __builtin_clz(x) using namespace std; const int N = 1e5; int k, n; long long add, res = 1e18; set<int> pos; multiset<pair<int, int> > L, mid, R; int cnt[2]; long long sum[3]; void read() { cin >> k >> n; if (k > 1) { exit(0); } while(n--) { char P, Q; int s, t; cin >> P >> s >> Q >> t; if (P == Q) { add += abs(s - t); continue; } pos.insert(s); pos.insert(t); if (s > t) { swap(s, t); } L.insert({s, t}); //R.insert({t, s}); ++cnt[1]; sum[1] += s + t; ++add; } } void solve() { if (pos.empty()) { cout << add; return ; } for (int x : pos) { while(!L.empty() && L.begin()->first <= x) { sum[2] += L.begin()->second - L.begin()->first; --cnt[1]; sum[1] -= L.begin()->first + L.begin()->second; mid.insert({L.begin()->second, L.begin()->first}); L.erase(L.begin()); } while(!mid.empty() && mid.begin()->first <= x) { ++cnt[0]; sum[0] += mid.begin()->first + mid.begin()->second; sum[2] -= mid.begin()->first - mid.begin()->second; mid.erase(mid.begin()); } res = min(res, 2LL * x * cnt[0] - sum[0] + sum[1] - 2LL * cnt[1] * x + sum[2]); } cout << res + add; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); //freopen(TASK".OUT", "w", stdout); } int t = 1; bool typetest = false; if (typetest) { cin >> t; } for (int __ = 1; __ <= t; ++ __) { //cout << "Case " << __ << ": "; read(); solve(); } }

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

bridge.cpp: In function 'int main()':
bridge.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...