Submission #538146

# Submission time Handle Problem Language Result Execution time Memory
538146 2022-03-16T06:19:47 Z Pherokung Teleporters (IOI08_teleporters) C++17
5 / 100
1000 ms 43240 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,a[2000005],b[2000005],tp[2000005],ty[2000005],num[2000005],pos,ans,cnt; 
priority_queue<int> pq;
queue<int> q;
vector<int> v;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		tp[a[i]] = b[i];
		tp[b[i]] = a[i];
		ty[a[i]] = i;
		ty[b[i]] = i;
	}
	
	ans = 0;
	pos = 1;
	while(pos <= 2000001){
		if(tp[pos] != 0){
			num[ty[pos]]++;
			pos = tp[pos] + 1;
		}
		else pos += 1;
	}
	
	for(int i=1;i<=n;i++){
		ans += num[i];
		if(num[i] == 1){
			q.push(i);
		}
	}
	
	while(!q.empty()){
		int ind = q.front();
		q.pop();
		
		pos = a[ind] + 1;
		v.clear();
		while(pos <= b[ind] - 1){
			if(tp[pos] != 0){
				v.push_back(ty[pos]);
				num[ty[pos]]++;
				pos = tp[pos] + 1;
			}
		}
		
		pq.push(v.size() + 3);
		
		for(auto x : v) if(num[x] == 1) q.push(x);	
	}
	
	while(!pq.empty() && m > 0){
		ans += pq.top();
		pq.pop();
		m--;
	}
	
	ans += 4 * (m/2) + m % 2;
	printf("%d",ans);
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
teleporters.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |   scanf("%d%d",&a[i],&b[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 7356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 15308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1059 ms 32280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1020 ms 39244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1034 ms 43240 KB Time limit exceeded
2 Halted 0 ms 0 KB -