이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define forr(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
using namespace std;
const int base = 31;
const ll mod = 1e9 + 7;
const ll oo = 1e18;
const int N = 1e6 + 5;
const int M = 1e6;
ll s[N], cnt[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int K, n;
cin >> K >> n;
ll res = 0;
vector<int> xx;
forr(i, 1, n){
char b1, b2;
int x1, x2;
cin >> b1 >> x1 >> b2 >> x2;
if (b1 == b2){
res += abs(x1 - x2);
}
else {
res++;
cnt[x1]++;
cnt[x2]++;
xx.pb(x1);
xx.pb(x2);
}
}
sort(all(xx));
ll cost1 = 0;
if (xx.size() >= 1) {
ll med = xx[(xx.size() - 1) >> 1];
forr(i, 0, xx.size() - 1) cost1 += abs(med - xx[i]);
}
cout << res + cost1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:2:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
2 | #define forr(i, a, b) for (int i = (a); i <= (b); i++)
| ^
bridge.cpp:59:9: note: in expansion of macro 'forr'
59 | forr(i, 0, xx.size() - 1) cost1 += abs(med - xx[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... |