Submission #430066

#TimeUsernameProblemLanguageResultExecution timeMemory
430066arayiTeleporters (IOI08_teleporters)C++17
100 / 100
719 ms48328 KiB
//Arayi #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <queue> #include <stack> #include <algorithm> #include <math.h> #include <vector> #include <cstring> #include <ctime> #include <set> #include <bitset> #include <map> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <ctime> #include <climits> #include <cassert> #include <chrono> #include <random> #include <complex> #define fr first #define sc second #define MP make_pair #define ad push_back #define PB push_back #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define lli long long int #define y1 arayikhalatyan #define j1 jigglypuff #define ld long double #define itn int #define pir pair<int, int> #define all(x) (x).begin(), (x).end() #define str string #define enl endl #define en endl #define cd complex<long double> #define vcd vector<cd> #define vii vector<int> #define vlli vector<lli> using namespace std; const int N = 2e6 + 30; int n, m; int ans; int a[N], i1[N]; vector <int> fp, sz; bool col[N]; int dfs(int v) { col[v] = 1; v = i1[a[v]]; if(v < (int)fp.size() - 1) { v = fp[v + 1]; if(!col[v]) return 1 + dfs(v); } return 1; } int main() { fastio; //freopen("input.in", "r", stdin); cin >> n >> m; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; a[l] = r, a[r] = l; fp.ad(l), fp.ad(r); } sort(all(fp)); for (int i = 0; i < (int)fp.size(); i++) i1[fp[i]] = i; for(auto p : fp) { if(!col[p]) { int ret = dfs(p); if(ans) sz.ad(ret); else ans = ret; } } //cout << ans << endl; //for(auto p : sz) cout << p << " "; //cout << endl; if(m <= (int)sz.size()) { sort(sz.begin(), sz.end()); reverse(sz.begin(), sz.end()); for (int i = 0; i < m; i++) ans += 2 + sz[i]; } else { m -= (int)sz.size(); for(auto p : sz) ans += p + 2; for (int i = 0; i < m; i++) { if(i%2) ans += 3; else ans++; } } cout << ans << endl; return 0; } /* __ *(><)* \/ / ||/ --|| || /\ / \ / \ */
#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...