Submission #402587

# Submission time Handle Problem Language Result Execution time Memory
402587 2021-05-12T02:26:27 Z wnsduds1 대표 선수 (KOI11_player) C
0 / 20
74 ms 19172 KB
#include<stdio.h>
typedef struct list {
	int v;
	int value;
}list;
void insert(list *x, list value);
list del(list *x);
list init(list arr[][101],list que[], int n);
int bottom = 0;
int front[101] = { 0, };
int abs_min = 987654321;
int main() {

	int n, m, i, j, k;
	list arr[1001][1001];
	list que[10001];
	list max, tmp, value;
	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++)
	{
		for (k = 0; k < m; k++)
		{
			scanf("%d", &value.value);
			value.v = i;
			arr[i][k] = value;
		}
	}

	max=init(arr,que, n);
	abs_min = (max.value - que[1].value) > abs_min ? abs_min : (max.value - que[1].value);


	while (1)
	{
		tmp = del(que);
		if (front[tmp.v] < n)
		{
			if (arr[tmp.v][front[tmp.v]].value > max.value)
			{
				insert(que, max);
				max = arr[tmp.v][front[tmp.v]];
				abs_min = (max.value - que[1].value) > abs_min ? abs_min : (max.value - que[1].value);
			}
			else {
				insert(que, arr[tmp.v][front[tmp.v]]);
				abs_min = (max.value - que[1].value) > abs_min ? abs_min : (max.value - que[1].value);
			}
			front[tmp.v] += 1;
		}
		else {
			break;
		}
	}
	printf("%d", abs_min);
	
	





	return 0;
}
list init(list arr[][101], list que[], int n)
{
	list return_value;
	int index;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			return_value = arr[i][front[i]];
			index = arr[i][front[i]].v;
		}
		else {
			if (return_value.value < arr[i][front[i]].value)
			{
				return_value = arr[i][front[i]];
				index = arr[i][front[i]].v;
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (i != index)
		{
			insert(que, arr[i][front[i]]);
		}
		front[i] += 1;
	}

	return return_value;

}
void insert(list *x, list value)
{
	if (bottom == 0)
	{
		bottom++;
		x[bottom] = value;
	}
	else {
		int index;
		list tmp;
		bottom++;
		x[bottom] = value;
		index = bottom;
		while (index != 1 && x[index].value < x[index / 2].value)
		{
			tmp = x[index];
			x[index] = x[index / 2];
			x[index / 2] = tmp;
			index /= 2;
		}
	}

}
list del(list *x)
{
	list return_value;
	int index = 1;
	list tmp;
	return_value = x[index];
	x[index] = x[bottom];
	bottom -= 1;
	while (index * 2 <= bottom && (x[index].value > x[index*2].value || x[index].value > x[index * 2 + 1].value))
	{
		if (x[index * 2].value < x[index * 2 + 1].value)
		{
			tmp = x[index];
			x[index] = x[index * 2];
			x[index * 2] = tmp;
			index = index * 2;
		}
		else {
			tmp = x[index];
			x[index] = x[index * 2+1];
			x[index * 2+1] = tmp;
			index = index * 2+1;
		}
	}
	return return_value;
}

Compilation message

player.c: In function 'main':
player.c:29:11: warning: passing argument 1 of 'init' from incompatible pointer type [-Wincompatible-pointer-types]
   29 |  max=init(arr,que, n);
      |           ^~~
      |           |
      |           list (*)[1001]
player.c:8:16: note: expected 'list (*)[101]' but argument is of type 'list (*)[1001]'
    8 | list init(list arr[][101],list que[], int n);
      |           ~~~~~^~~~~~~~~~
player.c:14:15: warning: unused variable 'j' [-Wunused-variable]
   14 |  int n, m, i, j, k;
      |               ^
player.c:18:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d %d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~~
player.c:23:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |    scanf("%d", &value.value);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 74 ms 19172 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -