이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// fest
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define FILENAME ""
#define __ fflush(stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
void FREOPEN() {
#ifdef COMP
freopen(".in", "r", stdin);
freopen("1.out", "w", stdout);
#else
freopen(FILENAME".in", "r", stdin);
freopen(FILENAME".out", "w", stdout);
#endif
}
inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }
const int N = 200500, inf = 1e9, MOD = (int)1e9 + 7;
char CH[N];
const ll INF = 1e18;
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};
vector<pair<int, int> > all;
ll calc(int p1, int p2) {
ll ret = 0;
for (int i = 0; i < SZ(all); i++) {
ret += min(abs(all[i].F - p1) + abs(all[i].S - p1), abs(all[i].F - p2) + abs(all[i].S - p2));
}
return ret;
}
int main() {
#ifndef ONLINE_JUDGE
FREOPEN();
#endif
int k, n;
cin >> k >> n;
ll un = 0;
vector<int> have;
for (int i = 1; i <= n; i++) {
char t1, t2;
int p1, p2;
scanf("\n%c %d %c %d", &t1, &p1, &t2, &p2);
if (t2 == 'A') swap(t1, t2), swap(p1, p2);
if (t1 == t2) {
un += abs(p2 - p1);
continue;
}
all.pb({p1, p2});
have.pb(p1);
have.pb(p2);
have.pb(min(inf, p1 + 1));
have.pb(min(inf, p2 + 1));
have.pb(max(0, p1 - 1));
have.pb(max(0, p2 - 1));
}
sort(All(have));
have.resize(unique(All(have)) - have.begin());
ll mn = INF;
if (k == 2) {
for (auto i : have) {
for (auto j : have) {
mn = min(mn, calc(i, j));
}
}
}
else {
for (auto i : have) mn = min(mn, calc(i, i));
}
un += SZ(all);
cout << mn + un;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'void FREOPEN()':
bridge.cpp:25:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FILENAME".in", "r", stdin);
^
bridge.cpp:26:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FILENAME".out", "w", stdout);
^
bridge.cpp: In function 'int main()':
bridge.cpp:63:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("\n%c %d %c %d", &t1, &p1, &t2, &p2);
^
# | 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... |