이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using ll = long long;
#define int ll
using namespace std;
#define sz(x) (int)(x).size()
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, l, r) for(int i = l; i >= r; i--)
#define fi first
#define se second
#define mod 998244353
#define db(x) cerr << __LINE__ << " " << #x << " " << x << "\n"
using vi = vector<int>;
using pi = pair<int, int>;
const ll N = 200005;
const ll inf = 1e18;
int n, m, w[N], e[N], vis[N], nxt[N];
vi v;
void solve(){
cin >> n >> m;
foru(i, 1, n){
cin >> w[i] >> e[i];
v.push_back(w[i]);
v.push_back(e[i]);
}
sort(v.begin(), v.end());
foru(i, 0, (n << 1) - 1){
nxt[i] = i + 1;
}
foru(i, 1, n){
w[i] = lower_bound(v.begin(), v.end(), w[i]) - v.begin() + 1;
e[i] = lower_bound(v.begin(), v.end(), e[i]) - v.begin() + 1;
nxt[w[i] - 1] = e[i];
nxt[e[i] - 1] = w[i];
}
nxt[n << 1] = 0;
v.clear();
int res;
foru(i, 0, n << 1){
if(vis[i]) continue;
int cnt = 0;
for(int j = i; !vis[j]; j = nxt[j]){
vis[j] = 1;
cnt++;
}
if(!i) res = cnt;
else v.push_back(cnt);
}
sort(v.begin(), v.end()); res--;
while(m){
if(!sz(v)) break;
else{
res += v.back() + 2;
v.pop_back();
}
m--;
}
cout << res - (m >> 1) + (m << 1);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
while(t--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
teleporters.cpp: In function 'void solve()':
teleporters.cpp:53:31: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | sort(v.begin(), v.end()); res--;
| ~~~^~
# | 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... |
# | 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... |
# | 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... |
# | 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... |