제출 #297308

#제출 시각아이디문제언어결과실행 시간메모리
297308AaronNaiduPalembang Bridges (APIO15_bridge)C++14
22 / 100
52 ms6388 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll k, n; ll s, t, numLeft, numRight, distFrom0; char p, q; vector<pair<ll, ll> > events; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> k >> n; ll minSum = 0; numLeft = numRight = distFrom0 = 0; for (int i = 0; i < n; i++) { cin >> p >> s >> q >> t; if (p == q) { minSum += abs(t - s); } else { minSum += 1 + abs(t - s); ll b = max(t, s); ll a = min(t, s); events.push_back({a, -1}); events.push_back({b, 1}); numRight++; distFrom0 += a; } } //cout << "Min sum is " << minSum << "\n"; //cout << "Initial dist: " << distFrom0 << "\n"; sort(events.begin(), events.end()); ll prevLocation = 0; ll finAns = 1000000000000000; if (events.size() == 0) { finAns = minSum; } for (int i = 0; i < events.size(); i++) { ll currLocation = events[i].first; distFrom0 -= numRight * (currLocation - prevLocation); distFrom0 += numLeft * (currLocation - prevLocation); if (events[i].second == -1) { numRight--; } else { numLeft++; } finAns = min(finAns, minSum + 2 * distFrom0); //cout << "At location " << currLocation << " dist is " << distFrom0 << '\n'; prevLocation = currLocation; } cout << finAns << "\n"; }

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

bridge.cpp: In function 'int main()':
bridge.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < events.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
#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...