Блог пользователя petar.vukmirovic2

Автор petar.vukmirovic2, 13 лет назад, По-английски

On contest that has recently been held there was a problem with code 389B — Fox and Cross. When i submitted my solution for this problem I got WA on test example that is listed here:

4
....
.#..
....
....

My program gave output YES since we can construct cross this way:

.#..
###.
.#..
....

but answer is NO.

Can somebody tell me if and if I did where did I get the problem statement wrong?

Thanks in advance, Petar :)

Полный текст и комментарии »

  • Проголосовать: нравится
  • -19
  • Проголосовать: не нравится

Автор petar.vukmirovic2, 13 лет назад, По-английски

Is it possible to see the whole test example (not just the first few lines) that our program is failing on?

Kindest regards, Petar Vukmirovic.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

Автор petar.vukmirovic2, 14 лет назад, По-английски

Hi,

Today I submitted my solution to 7B - Memory Manager, and it seemed to be working fine on my home PC, but when I tested it on Codechef judge it gave wrong answer as soon as on test two. I am running Linux Ubuntu if that may be helpful. Here is the code:

#include <stdio.h>
#include <string.h>

#define MAX_M 100
#define MAX_COMMAND 15

char memory[MAX_M], id,m;

/*void print_memory()
{
  int i;
  for(i=0;i<m;i++)
    printf("%d ",memory[i]);
}*/

int allocate(int size)
{
  int i,j,tmp_j;
  
 /* if (size==m)
    return 0;*/
  
  for(i=0; i<m-size; i++)
  {
    for(j=i; (j<i+size) && (memory[j] == 0); j++)
      ;
    if (j==i+size)
    {
      id++;
      memset(memory+i,id,size*sizeof(char));
      return id;
    }
  }
  return 0;
}

char erase(int tmp_id)
{
  char found = 0;
  int i;
  
  for(i=0; i<m; i++)
    if(memory[i] == tmp_id)
      {
	found = 1;
	memory[i] = 0;
      }
      
  return found;
}


void defragment()
{
  int i,j;
  for(i=0; i<m; i++)
  {
    if (memory[i] == 0)
    {
      for(j=i+1; j<m; j++)
	if (memory[j] != 0)
	  break;
      
      int tmp_j =j, count = 0;
	
      for(;memory[j];j++,i++)
      {
	count++;
	memory[i] = memory[j];	
      }
      
      for(j=tmp_j;count;j++,count--)
	memory[j] = 0;
    }
  }
}
int main()
{
  char t,command[MAX_COMMAND];
  int number, tmp_id,i,j;
  scanf("%d%d",&t,&m); getchar();
  for(i=0;i<t;i++)
  {
    gets(command);
    if (command[0] == 'a')
    {
      number = atoi(command+5);
      tmp_id = allocate(number);
      
      if (tmp_id == 0)
	puts("NULL");
      else
	printf("%d\n",tmp_id);
    }
    else if (command[0] == 'e')
    {
      number = atoi(command+5);
      if (erase(number) == 0)
	puts("ILLEGAL_ERASE_ARGUMENT");
    }
    else
      defragment();  
   //printf("\nDebug: "); print_memory(); putchar('\n');
  }
}

And here is the test example:

INPUT

6 1 defragment alloc 10 alloc 1 erase -1 erase 1 erase 1

OUTPUT

NULL NULL ILLEGAL_ERASE_ARGUMENT ILLEGAL_ERASE_ARGUMENT ILLEGAL_ERASE_ARGUMENT

Can someone give me some advice here?

Thanks Petar Vukmirovic.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор petar.vukmirovic2, 14 лет назад, По-английски

Hi,

I've been trying to solve problem Plug-in, and I used linked lists to do so. I managed to solve it for most test examples that I came up with, but on one particular test example I get Runtime error.

Can you please tell me what might be the problem?

Here is the code:



#include <stdio.h> #include <stdlib.h> #define WORD_MAX 200010 typedef struct node_ { char letter; struct node_ *next; } node; void add_to_end(node** start, node** end, char c) { node* new = malloc(sizeof(node)); new->next = NULL; new->letter = c; if (*start == NULL) { *start = new; *end = new; return; } (*end)->next = new; *end = new; } int remove_same(node** start) { node* temp = *start, *temp_2; if (temp == NULL || temp->next == NULL) return 0; if (temp->letter == temp->next->letter) { *start = temp->next->next; return 1; } while (temp != NULL && temp->next != NULL) { if (temp->next->next == NULL) return 0; if (temp->next->letter == temp->next->next->letter) { temp_2 = temp->next->next->next; free(temp->next); free(temp->next->next); temp->next = temp_2; return 1; } temp = temp->next; } return 0; } int main() { char word[WORD_MAX]; gets(word); unsigned i; node* list_start = NULL, *list_end = NULL; for(i=0; word[i]; i++) add_to_end(&list_start, &list_end, word[i]); while(remove_same(&list_start)) ; if (list_start == NULL) return 0; while(list_start) { putchar(list_start->letter); list_start=list_start->next; } return 0; }

81A - Plug-in

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится