답안 #95315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95315 2019-01-30T05:01:43 Z ics0503 Flood (IOI07_flood) C++17
64 / 100
177 ms 33792 KB
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
struct xy { int x, y, w; }a[121212];
struct xxy { int x; char y; int w; };
bool sort_y(xy a, xy b) { if (a.y != b.y)return a.y < b.y; return a.x < b.x; }
vector<xxy>edge[828282];
vector<int>Q[2];
int ck[121212][4], is_ans[221212], dist[828282], R[121212];
void swap(int &a, int &b) { a ^= b ^= a ^= b; }
void addE(int s, int e, int w, int i) {
	edge[s].push_back({ e, w , i});
	edge[e].push_back({ s, w , i});
}
int main() {
	int P, L, i, j; scanf("%d", &P);
	for (i = 1; i <= P; i++)scanf("%d%d", &a[i].x, &a[i].y), a[i].w = i;
	sort(a + 1, a + P + 1, sort_y);
	for (i = 1; i <= P; i++)R[a[i].w] = i;
	scanf("%d", &L);
	for (int i = 1; i <= L; i++) {
		int s, e; scanf("%d%d", &s, &e);
		s = R[s], e = R[e];
		if (a[s].y == a[e].y) {
			if (a[s].x > a[e].x)swap(s, e);
			ck[s][3] = i; ck[e][1] = i;
			addE(8 * s + 6, 8 * e + 3, 0, 0);
			addE(8 * s + 7, 8 * e + 2, 0, 0);
		}
		else {
			if (a[s].y > a[e].y)swap(s, e);
			ck[s][2] = i; ck[e][0] = i;
			addE(8 * s + 4, 8 * e + 1, 0, 0);
			addE(8 * s + 5, 8 * e + 0, 0, 0);
		}
	}
	int n = (P + 1) * 8 - 1;
	for (int i = 1; i <= P; i++) for (int j = 0; j < 4; j++) {
		addE(i * 8 + 2 * j, i * 8 + 2 * j + 1, !!ck[i][j], ck[i][j]);
		addE(i * 8 + 2 * j + 1, i * 8 + (2 * j + 2) % 8, 0, 0);
	}
	for (int i = 8; i <= n; i++) {
		if (dist[i]) continue;
		int dst; dst = dist[i] = 1; Q[1].push_back(i);
		while (!(Q[0].empty() && Q[1].empty())) {
			if (Q[dst % 2].empty()) {
				dst++;
				continue;
			}
			int now = Q[dst % 2].back(); Q[dst % 2].pop_back();
			if (dist[now] % 2 != dst % 2)continue;
			for (auto E : edge[now]) {
				if (dist[E.x] == 0 || dist[E.x] > dst + E.y) {
					dist[E.x] = dst + E.y;
					Q[(dst + E.y) % 2].push_back(E.x);
				}
			}
		}
	}
	for (int i = 8; i <= n; i++) for (auto E : edge[i]) if (dist[i] == dist[E.x]) is_ans[E.w] = 1; 
	int ansCnt = 0;
	for (int i = 1; i <= L; i++) if (is_ans[i])ansCnt++;
	printf("%d\n", ansCnt);
	for (int i = 1; i <= L; i++) if (is_ans[i])printf("%d\n", i);
	return 0;
}

Compilation message

flood.cpp: In function 'void addE(int, int, int, int)':
flood.cpp:13:31: warning: narrowing conversion of 'w' from 'int' to 'char' inside { } [-Wnarrowing]
  edge[s].push_back({ e, w , i});
                               ^
flood.cpp:14:31: warning: narrowing conversion of 'w' from 'int' to 'char' inside { } [-Wnarrowing]
  edge[e].push_back({ s, w , i});
                               ^
flood.cpp: In function 'int main()':
flood.cpp:17:15: warning: unused variable 'j' [-Wunused-variable]
  int P, L, i, j; scanf("%d", &P);
               ^
flood.cpp:17:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int P, L, i, j; scanf("%d", &P);
                  ~~~~~^~~~~~~~~~
flood.cpp:18:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= P; i++)scanf("%d%d", &a[i].x, &a[i].y), a[i].w = i;
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
flood.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &L);
  ~~~~~^~~~~~~~~~
flood.cpp:23:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int s, e; scanf("%d%d", &s, &e);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19832 KB Output is correct
2 Correct 19 ms 19832 KB Output is correct
3 Correct 18 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19832 KB Output is correct
2 Correct 20 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19836 KB Output is correct
2 Correct 18 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 19960 KB Output is correct
2 Correct 19 ms 20088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19960 KB Output is correct
2 Correct 21 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 30232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 100 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 97 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 177 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 128 ms 33792 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -