Submission #1029584

#TimeUsernameProblemLanguageResultExecution timeMemory
1029584kunzaZa183Teleporters (IOI08_teleporters)C++17
90 / 100
506 ms65536 KiB
#include <bits/stdc++.h> using namespace std; int tp[2000001]; bitset<2000005> vb; 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; function<void(int)> dfs; dfs = [&](int cur) { if(cur==vi.size()) { special = cy - 1; return; } // cout << cur << "\n"; if (vb[cur]) { cyc.push_back(cy); return; } vb[cur] = 1; cy++; dfs(lower_bound(vi.begin(), vi.end(), tp[vi[cur]]) - vi.begin() + 1); }; dfs(i); } // 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: In lambda function:
teleporters.cpp:28:15: 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: In function 'int main()':
teleporters.cpp:49:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   if (m >= cyc.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...