답안 #121298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121298 2019-06-26T09:56:10 Z WhipppedCream Flood (IOI07_flood) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;
const int maxm = 2e5+5;

vector< ii > pts[maxn];
map< ii, int> rev;

int n, m;
int px[maxn], py[maxn];
int wu[maxm], wv[maxm];

int used[2*maxm];

int detdir(int u, int v)
{
	if(px[u] == px[v])
	{
		if(py[u]< py[v]) return 1;
		return 3;
	}
	if(px[u]< px[v]) return 0;
	return 2;
}

int del[maxm];
int used[maxm];

int trav(int u, int from, int dir, int face)
{
	if(u == from) return true;
	ii out[4];
	for(int i = 0; i< 4; i++) out[i] = {-1, -1};
	for(auto kk : pts[u])
	{
		int v = kk.X, id = kk.Y;
		out[(detdir(u, v)+1-dir+4)%4] = kk;
	}
	int st = -1;
	for(int i = 0; i< 4; i++)
	{
		int v = out[i].X, id = out[i].Y;
		if(v == -1) continue;
		if(used[id]) continue;
		st = i;
		break;
	}
	if(st == -1) return false;
	int v = out[st].X, id = out[st].Y;
	used[id] = true;
	if(trav(v, from, detdir(u, v), face))
	{
		del[id] = true;
		return true;
	}
	return false;
}

vector<int> adj[2*maxm];

int dist[2*maxn];

bool cmp(int a, int b)
{
	return px[wu[a]]< px[wu[b]];
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i<= n; i++)
	{
		scanf("%d %d", &px[i], &py[i]);
		rev[ii(px[i], py[i])] = i;
	}
	for(int i = 1; i<= m; i++)
	{
		scanf("%d %d", &wu[i], &wv[i]);
		if(px[wu[i]] == px[wv[i]])
		{
			if(py[wu[i]]> py[wv[i]]) swap(wu[i], wv[i]);
		}
		if(py[wu[i]] == py[wv[i]])
		{
			if(px[wu[i]]> px[wv[i]]) swap(wu[i], wv[i]);
		}
	}
	vector<int> edges;
	for(int i = 1; i<= m; i++)
	{
		pts[wu[i]].pb(ii(wv[i], i));
		edges.pb(i);
	}
	sort(edges.begin(), edges.end(), cmp);
	vector<int> res;
	for(int i : edges)
	{
		if(used[i]) continue;
		int u = wu[i], v = wv[i];
		trav(v, u, detdir(u, v), 1);
	}
	for(int i = 1; i<= m; i++)
	{
		if(!del[i]) res.pb(i);
	}
	printf("%d\n", res.size());
	for(int x : res) printf("%d\n", x);
}

Compilation message

flood.cpp:35:14: error: conflicting declaration 'int used [200005]'
 int used[maxm];
              ^
flood.cpp:21:5: note: previous declaration as 'int used [400010]'
 int used[2*maxm];
     ^~~~
flood.cpp: In function 'int trav(int, int, int, int)':
flood.cpp:44:17: warning: unused variable 'id' [-Wunused-variable]
   int v = kk.X, id = kk.Y;
                 ^~
flood.cpp: In function 'int main()':
flood.cpp:114:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", res.size());
                 ~~~~~~~~~~^
flood.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
flood.cpp:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &px[i], &py[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
flood.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &wu[i], &wv[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~