Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

why "Wrong answer on test 1"??
Author: SkyCode
ID: 059354
Problem: 325
Contest: 0
Date: 2013-08-30 10:56:57

But it's working on my computer! :( I don't understand, HOW it can be(


#include <stdio.h>
#include <malloc.h>


struct spisok
{
struct spisok *next, *prev;
char c;
};

struct spisok *first=NULL, *last = NULL, *other = NULL, *ui=NULL, *uj=NULL, *uk=NULL, *ul=NULL;
int main()
{
int n = 0, symbol, swap = 0,i,j,k,l;
FILE *f;

f=fopen("input.txt", "r");

while((symbol=fgetc(f)) != EOF)
{
if (first==NULL)
{
first = (struct spisok*)malloc(sizeof(struct spisok));
first->next = NULL;
first->prev = NULL;
first->c = symbol;
last = first;
}
else
{
other = (struct spisok*)malloc(sizeof(struct spisok));
other->next = NULL;
other->prev = last;
last->next = other;
other->c = symbol;
last = other;
}
n++;
}

fclose(f);

for (i=0, j=n-1 , ui = first , uj = last; i<n/2+1, j>n/2-1; j--, i++, ui = ui->next, uj = uj->prev )
if (ui->c!=uj->c)
{
for (k=i+1,uk=ui->next,l=j-1,ul=uj->prev; k<j, l>i; k++,uk=uk->next, l--, ul=ul->prev)
{
if (uk->c==uj->c)
{
uk->prev->next = uk->next;
uk->next->prev = uk->prev;

uk->next = ui;
uk->prev = ui->prev;
if (ui->prev!=NULL) ui->prev->next = uk;
ui->prev = uk;
swap=swap+k-i;

ui=uk;
break;
}
if (ul->c==ui->c)
{
ul->prev->next = ul->next;
ul->next->prev = ul->prev;

ul->next = uj->next;
ul->prev = uj;
if (uj->next!=NULL) uj->next->prev = ul;
uj->next = ul;
swap=swap+j-l;

uj = ul;
break;
}
}
if ((ui->c)!=(uj->c))
{
printf("-1");
return 0;
}
}


printf("%d", swap);


while (first!=NULL)
{
other = first;
first=first->next;
free(other);
}

return 0;
}


see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-09-22 21:03:30Online Contester Team © 2002 - 2016. All rights reserved.