Submission #1029586

#TimeUsernameProblemLanguageResultExecution timeMemory
1029586kunzaZa183Teleporters (IOI08_teleporters)C++17
100 / 100
444 ms40628 KiB
#include <bits/stdc++.h> using namespace std; int tp[2000001]; bool vb[2000005]; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n, m; cin >> n >> m; vector<int> vi; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; vi.push_back(a), vi.push_back(b); tp[a] = b, tp[b] = a; } vi.push_back(0); sort(vi.begin(), vi.end()); // for (auto a : vpii) cout << a.first << " " << a.second << "\n"; vector<int> cyc; int special; for (int i = 0; i < vi.size(); i++) if (!vb[i]) { // cout << "I = " << i << '\n'; int cy = 0; int cur = i; while (1) { if (cur == vi.size()) { special = cy - 1; break; } // cout << cur << "\n"; if (vb[cur]) { cyc.push_back(cy); break; } vb[cur] = 1; cy++; cur = lower_bound(vi.begin(), vi.end(), tp[vi[cur]]) - vi.begin() + 1; }; } // for (auto a : cyc) cout << a << ' '; // cout << "\n"; sort(cyc.begin(), cyc.end(), greater<int>()); if (m >= cyc.size()) { int x = (m - cyc.size()); int val = x / 2 * 4 + x % 2; cout << special + accumulate(cyc.begin(), cyc.end(), 0) + cyc.size() * 2 + val << "\n"; } else cout << special + accumulate(cyc.begin(), cyc.begin() + m, 0) + 2 * m << "\n"; }

Compilation message (stderr)

teleporters.cpp: In function 'int main()':
teleporters.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for (int i = 0; i < vi.size(); i++)
      |                   ~~^~~~~~~~~~~
teleporters.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if (cur == vi.size()) {
      |             ~~~~^~~~~~~~~~~~
teleporters.cpp:45:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   if (m >= cyc.size()) {
      |       ~~^~~~~~~~~~~~~
teleporters.cpp:48:21: warning: 'special' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     cout << special + accumulate(cyc.begin(), cyc.end(), 0) + cyc.size() * 2 +
      |             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...