답안 #430248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430248 2021-06-16T12:27:56 Z rainboy 장난감 기차 (IOI17_train) C++
16 / 100
26 ms 1740 KB
#include "train.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

const int N = 5000, SMALL = 15, M = 20000;

typedef vector<int> vi;

int *ej[N], eo[N], *fi[N], fo[N];

void append(int **ej, int *eo, int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]); 
	ej[i][o] = j;
}

int cc[N], qu[N], cnt;

void dfs1(int i) {
	int o;

	if (cc[i])
		return;
	cc[i] = -1;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		dfs1(j);
	}
	qu[cnt++] = i;
}

vi rr; char has_[N]; int k, has;

void dfs2(int j, int c) {
	int o;

	if (cc[j] != -1) {
		if (cc[j] != c && has_[cc[j]])
			has_[c] = 1;
		return;
	}
	if (rr[j])
		has = 1;
	cc[j] = c, k++;
	for (o = fo[j]; o--; ) {
		int i = fi[j][o];

		dfs2(i, c);
	}
}

char self[N], right[N];

vi who_wins(vi aa, vi rr_, vi uu, vi vv) {
	int n = aa.size(), m = uu.size(), h, i, j, ka, kb;
	vi ans(n);

	rr = rr_;
	ka = kb = 0;
	for (i = 0; i < n; i++)
		if (aa[i] == 1)
			ka++;
		else
			kb++;
	if (ka == n) {
		for (i = 0; i < n; i++) {
			ej[i] = (int *) malloc(2 * sizeof *ej[i]);
			fi[i] = (int *) malloc(2 * sizeof *fi[i]);
		}
		for (h = 0; h < m; h++) {
			i = vv[h], j = uu[h];
			if (i == j)
				self[i] = 1;
			append(ej, eo, i, j), append(fi, fo, j, i);
		}
		for (i = 0; i < n; i++)
			if (!cc[i])
				dfs1(i);
		while (cnt--) {
			i = qu[cnt];
			if (cc[i] != -1)
				continue;
			k = 0, has = 0, dfs2(i, i);
			if ((k >= 2 || self[i]) && has)
				has_[i] = 1;
		}
		for (i = 0; i < n; i++)
			ans[i] = has_[cc[i]];
	} else {
		memset(self, 0, n * sizeof *self), memset(right, 0, n * sizeof *right);
		for (h = 0; h < m; h++)
			if (vv[h] == uu[h])
				self[uu[h]] = 1;
			else
				right[uu[h]] = 1;
		for (i = 0; i < n; i++) {
			ans[i] = 0;
			for (j = i; j < n; j++)
				if (aa[j]) {
					if (rr[j]) {
						if (self[j]) {
							ans[i] = 1;
							break;
						}
					} else {
						if (!right[j]) {
							ans[i] = 0;
							break;
						}
					}
				} else {
					if (rr[j]) {
						if (!right[j]) {
							ans[i] = 1;
							break;
						}
					} else {
						if (self[j]) {
							ans[i] = 0;
							break;
						}
					}
				}
		}
	}
	return ans;
}

Compilation message

train.cpp: In function 'void append(int**, int*, int, int)':
train.cpp:17:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   17 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 564 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 4 ms 588 KB Output is correct
4 Correct 4 ms 588 KB Output is correct
5 Correct 4 ms 612 KB Output is correct
6 Correct 4 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 6 ms 972 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 4 ms 560 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1736 KB Output is correct
2 Correct 9 ms 1712 KB Output is correct
3 Correct 8 ms 1740 KB Output is correct
4 Correct 9 ms 1608 KB Output is correct
5 Correct 9 ms 1612 KB Output is correct
6 Correct 9 ms 1588 KB Output is correct
7 Correct 12 ms 1484 KB Output is correct
8 Correct 9 ms 1484 KB Output is correct
9 Correct 10 ms 1484 KB Output is correct
10 Correct 11 ms 1420 KB Output is correct
11 Correct 10 ms 1424 KB Output is correct
12 Correct 10 ms 1432 KB Output is correct
13 Correct 10 ms 1740 KB Output is correct
14 Correct 9 ms 1740 KB Output is correct
15 Correct 11 ms 1740 KB Output is correct
16 Correct 10 ms 1672 KB Output is correct
17 Correct 9 ms 1740 KB Output is correct
18 Correct 6 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 716 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 820 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 564 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 4 ms 588 KB Output is correct
4 Correct 4 ms 588 KB Output is correct
5 Correct 4 ms 612 KB Output is correct
6 Correct 4 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 6 ms 972 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 4 ms 560 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Incorrect 1 ms 204 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
13 Halted 0 ms 0 KB -