제출 #1029580

#제출 시각아이디문제언어결과실행 시간메모리
1029580kunzaZa183Teleporters (IOI08_teleporters)C++17
95 / 100
519 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<pair<int, int>> vpii; { 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; } sort(vi.begin(), vi.end()); vpii.emplace_back(0, vi[0]); for (int i = 0; i < vi.size() - 1; i++) { vpii.emplace_back(vi[i], vi[i + 1]); } vpii.emplace_back(vi.back(), 3e6); } // for (auto a : vpii) cout << a.first << " " << a.second << "\n"; vector<int> cyc; int special; for (int i = 0; i < vpii.size(); i++) if (!vb[i]) { // cout << "I = " << i << '\n'; int cy = 0; function<void(int)> dfs; dfs = [&](int cur) { // cout << cur << "\n"; if (vb[cur]) { cyc.push_back(cy); return; } vb[cur] = 1; cy++; if (vpii[cur].second == 3e6) { special = cy - 1; return; } dfs(lower_bound(vpii.begin(), vpii.end(), make_pair(tp[vpii[cur].second], -1)) - vpii.begin()); }; 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"; }

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

teleporters.cpp: In function 'int main()':
teleporters.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < vi.size() - 1; i++) {
      |                     ~~^~~~~~~~~~~~~~~
teleporters.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int i = 0; i < vpii.size(); i++)
      |                   ~~^~~~~~~~~~~~~
teleporters.cpp:55:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   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...