Submission #58258

#TimeUsernameProblemLanguageResultExecution timeMemory
58258memikakizakiTeleporters (IOI08_teleporters)C++14
65 / 100
1085 ms39276 KiB
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 1e6+1, INF = 1e9; int n, m, lf[N], rg[N], nxt[N << 1]; vector<int> vals, cycles; bitset<N> mark; long ans; int main() { scanf("%d %d", &n, &m); vals.reserve(2*n+1); for(int i = 0; i < n; i++) { scanf("%d %d", &lf[i], &rg[i]); vals.push_back(lf[i]); vals.push_back(rg[i]); } vals.push_back(INF); stable_sort(vals.begin(), vals.end()); for(int i = 0; i < n; i++) { lf[i] = lower_bound(vals.begin(), vals.end(), lf[i]) - vals.begin(); rg[i] = lower_bound(vals.begin(), vals.end(), rg[i]) - vals.begin(); nxt[lf[i]] = rg[i]+1; nxt[rg[i]] = lf[i]+1; } nxt[vals.size()-1] = INF; for(int i = 0; i < vals.size(); i++) if(!mark[i]) { int curr = i, sz = 0; bool cycle = false; while(curr != INF) { if(mark[curr]) { cycle = true; break; } ++sz; mark[curr] = true; curr = nxt[curr]; } if(cycle) cycles.push_back(sz); else ans = sz-1; } sort(cycles.begin(), cycles.end(), greater<int>()); for(int i = 0; i < min((int) cycles.size(), m); i++) ans += cycles[i] + 2; if(m > cycles.size()) { m -= cycles.size(); ans += (m - (m & 1)) << 1 + (m & 1); } printf("%lld", ans); }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < vals.size(); i++) if(!mark[i]) {
                 ~~^~~~~~~~~~~~~
teleporters.cpp:44:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(m > cycles.size()) {
     ~~^~~~~~~~~~~~~~~
teleporters.cpp:46:29: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   ans += (m - (m & 1)) << 1 + (m & 1);
                           ~~^~~~~~~~~
teleporters.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
teleporters.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &lf[i], &rg[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...