제출 #274625

#제출 시각아이디문제언어결과실행 시간메모리
274625evpipisTeleporters (IOI08_teleporters)C++11
100 / 100
759 ms54376 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back typedef pair<int, int> ii; const int len = 2e6+5; int vis[len], nex[len]; vector<ii> vec; priority_queue<int> pq; int dfs(int u){ vis[u] = 1; int ans = 1; if (!vis[nex[u]]) ans += dfs(nex[u]); return ans; } int main(){ int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++){ int a, b; scanf("%d %d", &a, &b); vec.pb(mp(a, 2*i)); vec.pb(mp(b, 2*i+1)); } sort(vec.begin(), vec.end()); for (int i = 0; i < 2*n-1; i++) nex[vec[i].se] = vec[i+1].se^1; int st = 2*n; nex[st] = vec[0].se^1; nex[vec[2*n-1].se] = st; vis[st] = 1; int ans = dfs(nex[st]); for (int i = 0; i < 2*n; i++) if (!vis[i]) pq.push(dfs(i)); while (m--){ if (pq.empty()) ans++, pq.push(1); else ans += 2+pq.top(), pq.pop(); } printf("%d\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

teleporters.cpp: In function 'int main()':
teleporters.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
teleporters.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...