이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int nmax = 1e5+5;
struct abt {
char har;
int h;
char oar;
int o;
};
abt per[nmax];
int main() {
int K,N;
int dist = 0;
int ujkir = INT_MAX;
int ujkan = INT_MIN;
cin >> K >> N;
vector<pair<int,int>>jar;
for(int i=1; i<=N; i++) {
cin >> per[i].har >> per[i].h >> per[i].oar >> per[i].o;
ujkir = min(min(per[i].h, per[i].o), ujkir);
ujkan = max(max(per[i].h, per[i].o), ujkan);
if(per[i].har == per[i].oar) {
dist += abs(per[i].h - per[i].o);
} else {
int sem = abs(per[i].h - per[i].o) + 1;
jar.push_back({sem, i});
}
}
int pojem;
int sums;
int findis = INT_MAX;
for(int i=ujkir; i<=ujkan; i++) {
pojem = i;
//cout << "pojem " << pojem << endl;
sums = 0;
for(int j=0; j<jar.size(); j++) {
//cout << "j " << j << endl;
if(pojem > max(per[jar[j].se].o,per[jar[j].se].h) || pojem < min(per[jar[j].se].o,per[jar[j].se].h)) {
sums += jar[j].fi + (2*(min(abs(pojem - per[jar[j].se].h), abs(pojem - per[jar[j].se].o))));
//cout << "house " << abs(pojem - per[jar[j].se].h) << endl;
//cout << "office " << abs(pojem - per[jar[j].se].o) << endl;
} else {
sums+= jar[j].fi;
}
}
findis = min(findis, sums);
}
dist+=findis;
cout << dist << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j=0; j<jar.size(); j++) {
| ~^~~~~~~~~~~| # | 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... |