Submission #402590

# Submission time Handle Problem Language Result Execution time Memory
402590 2021-05-12T02:35:45 Z wnsduds1 대표 선수 (KOI11_player) C
0 / 20
46 ms 8140 KB
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.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[1001] = { 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] < m)
		{
			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:32:11: warning: passing argument 1 of 'init' from incompatible pointer type [-Wincompatible-pointer-types]
   32 |  max=init(arr,que, n);
      |           ^~~
      |           |
      |           list (*)[1001]
player.c:11:16: note: expected 'list (*)[101]' but argument is of type 'list (*)[1001]'
   11 | list init(list arr[][101],list que[], int n);
      |           ~~~~~^~~~~~~~~~
player.c:17:15: warning: unused variable 'j' [-Wunused-variable]
   17 |  int n, m, i, j, k;
      |               ^
player.c:21:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d %d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~~
player.c:26:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |    scanf("%d", &value.value);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -