Submission #405469

# Submission time Handle Problem Language Result Execution time Memory
405469 2021-05-16T12:44:21 Z AugustinasJucas Teleporters (IOI08_teleporters) C++14
0 / 100
1000 ms 39684 KB
#include <bits/stdc++.h>
using namespace std;
const int dydis = 2e6 + 10;
int nxt[dydis];
int desn[dydis];
int n, k;
vector<pair<int, int> > mas;
vector<pair<int, int> > vec;
bool vis[dydis] = {};
int main(){
	
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		vec.push_back({a, i*2});
		vec.push_back({b, i*2+1});
	}
	sort(vec.begin(), vec.end());
	for(int i = 0; i < (int)vec.size()-1; i++){
		cout << ((char)('a'+(vec[i].second/2))) << " ";
		desn[vec[i].second] = vec[i+1].second;
	}
	cout << endl;
	desn[vec.back().second] = 2*n;
	
	for(int i = 0; i < 2*n; i++){
		nxt[i] = desn[(i ^ 1)];
	//	cout << "nxt[" << i << "] = " << nxt[i] << endl;
	}
	
	int start = vec[0].second;
	int cur = start;
	int curAns = 0;
	int jauYra = 0;
	while(cur != 2*n){
		vis[cur] = 1;
		cur = nxt[cur];
		curAns++;
		jauYra++;
	}
	vector<int> ciklai;
	for(int i = 0; i < 2*n; i++){
		if(vis[i]) continue;
		int cur = i;
		int kek = 0;
		while(true){
			kek++;
			vis[cur] = 1;
			cur = nxt[cur];
			if(cur == i) break;
		}
		ciklai.push_back(kek);
		//cout << "dedu " << kek << endl;
	}
	
	sort(ciklai.begin(), ciklai.end()); reverse(ciklai.begin(), ciklai.end());
	
	for(int i = 0; i < min((int)ciklai.size(), k); i++){
		curAns += ciklai[i] + 2;
		jauYra += ciklai[i];
	}
	
	k -= min((int)ciklai.size(), k);
	if(k != 0){
		//cout << "k != 0" << endl;
		curAns += ((k/2) * 2) * 2;
		curAns += (k & 1) * 2;
	}
	
	cout << curAns;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 308 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 968 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 7132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 247 ms 11916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 813 ms 36456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1025 ms 36536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1008 ms 39684 KB Time limit exceeded
2 Halted 0 ms 0 KB -