제출 #825533

#제출 시각아이디문제언어결과실행 시간메모리
825533TrunktyTeleporters (IOI08_teleporters)C++14
75 / 100
355 ms56452 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll int n,m; int pos[2000005],nex[2000005]; bool check[2000005]; vector<int> v; int cnt,ans; void dfs(int x){ if(check[x]){ return; } check[x] = true; cnt++; dfs(nex[x]); } signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i=1;i<=n;i++){ int a,b; cin >> a >> b; pos[a] = i; pos[b] = i+1e6; } int bef=0; for(int i=1;i<=2e6;i++){ if(pos[i]){ nex[bef] = pos[i]; bef = pos[i]; } } for(int i=1;i<=n;i++){ swap(nex[i],nex[i+1000000]); } dfs(0); ans = cnt-1LL; for(int i=1;i<=n;i++){ if(!check[i]){ cnt = 0; dfs(i); v.push_back(cnt); } if(!check[i+1000000]){ cnt = 0; dfs(i+1000000); v.push_back(cnt); } } sort(v.begin(),v.end(),greater<int>()); for(int i=0;i<=m-1;i++){ if(i<v.size()){ ans += v[i]; } } ans += m*2LL; cout << ans << "\n"; return 0; }

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

teleporters.cpp: In function 'int main()':
teleporters.cpp:57:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         if(i<v.size()){
      |            ~^~~~~~~~~
#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...