제출 #583303

#제출 시각아이디문제언어결과실행 시간메모리
583303hibikiTeleporters (IOI08_teleporters)C++11
100 / 100
418 ms23580 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define f first #define s second #define all(x) x.begin(),x.end() int n,m; pair<int,int> go[2000005]; bool pass[2000005]; int main() { scanf("%d %d",&n,&m); for(int i = 0; i < 2000005; i++) go[i] = {i + 1, 0}; for(int i = 0; i < n; i++) { int a,b; scanf("%d %d",&a,&b); go[a] = {b + 1, 1}; go[b] = {a + 1, 1}; } int ans = 0; priority_queue<int> pq; pass[2000005 - 1] = true; for(int i = 0; i < 2000005; i++) { if(pass[i]) continue; int cnt = 0, nw = i; while(!pass[nw]) { pass[nw] = true; cnt += go[nw].s; nw = go[nw].f; } if(i == 0) ans += cnt; else { // printf("%d %d\n",i,cnt); pq.push(cnt); } } while(m > 0 && !pq.empty()) { ans += pq.top() + 2; pq.pop(); m--; } ans += (m / 2) * 4 + (m % 2); printf("%d\n",ans); return 0; }

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

teleporters.cpp: In function 'int main()':
teleporters.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
teleporters.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         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...