이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |