이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}
vector<pll> v;
vector<int> cc;
ll cal(int mid) {
ll ret= 0;
for (pll i : v) {
if (i.first <= mid && mid <= i.second) continue;
ret += min(abs(i.first-mid), abs(i.second-mid));
}
return ret*2;
}
int main() {
int k, n;
scanf("%d %d", &k, &n);
ll sum = 0;
for (int i = 0; i < n; i++) {
char a,c;
int b,d;
scanf(" %c %d %c %d", &a, &b ,&c, &d);
sum += abs(b-d);
if (a!=c) {
if (b>d) swap(b,d);
sum++;
v.push_back({b, d});
}
}
if (k==1) {
for (pll i : v) cc.push_back(i.first), cc.push_back(i.second);
sort(all(cc));
printf("%lld", cal(cc[(sz(cc)-1)/2])+sum);
return 0;
}
// 이제 k=2인 경우,
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &k, &n);
~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c %d %c %d", &a, &b ,&c, &d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |