답안 #293729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293729 2020-09-08T10:55:51 Z Hemimor Teleporters (IOI08_teleporters) C++14
35 / 100
468 ms 24824 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=2000000;
int n,m,a[M];
bool b[M];

int f(int x){
	x++;
	while(x<M&&!b[x]&&a[x]==-1) x++;
	if(x<M) x=a[x];
	return x;
}

int main(){
	fill(a,a+M,-1);
	scanf("%d",&n);
	scanf("%d",&m);
	int v=inf;
	for(int i=0;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--,y--;
		a[x]=y;
		a[y]=x;
		v=min({v,x,y});
	}
	int res=0;
	while(1){
		b[v]=true;
		v=f(a[v]);
		res++;
		if(v==M) break;
	}
	vi c;
	for(int i=0;i<M;i++) if(a[i]>=0&&!b[i]){
		v=i;
		int tmp=0;
		while(1){
			b[v]=true;
			v=f(a[v]);
			tmp++;
			if(b[v]) break;
		}
		c.push_back(tmp);
	}
	sort(c.rbegin(),c.rend());
	int I=0;
	while(m&&I<c.size()){
		res+=2+c[I++];
		m--;
	}
	res+=2*m-m%2;
	printf("%d\n",res);
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:83:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  while(m&&I<c.size()){
      |           ~^~~~~~~~~
teleporters.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
teleporters.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |  scanf("%d",&m);
      |  ~~~~~^~~~~~~~~
teleporters.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |   scanf("%d%d",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 8192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 8192 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 8192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8192 KB Output is correct
2 Incorrect 19 ms 8448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 8320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 8704 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 10372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 12408 KB Output is correct
2 Correct 243 ms 16636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 304 ms 19192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 439 ms 23040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 468 ms 24824 KB Output is correct
2 Incorrect 465 ms 24720 KB Output isn't correct
3 Halted 0 ms 0 KB -