541 - Error Correction

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

mido
Learning poster
Posts: 78
Joined: Sun Jun 16, 2002 9:48 pm
Location: Cairo,Egypt

541 - Error Correction

Post by mido »

Is there something I can't see here...here's my code:
[cpp]
#include <iostream.h>

void main()
{
int list[100][100];
int row[100];
int col[100];
int dim;
int i,j,badrow_count,badrow_index,badcol_count,badcol_index;
while (cin>>dim && dim>0)
{
badrow_count=0;
badcol_count=0;
for (i=0;i<dim;i++)
row=col=0;
for (i=0;i<dim && badrow_count<2;i++)
{
for (j=0;j<dim;j++)
{
cin>>list[j];
row+=list[j];
col[j]+=list[j];
}
if (row%2==1)
{
badrow_count++;
badrow_index=i;
}
}
for (j=0;j<dim && badcol_count<2 && badrow_count<2;j++)
{
if (col[j]%2==1)
{
badcol_count++;
badcol_index=j;
}
}
if (badrow_count>=2 || badcol_count>=2 || badrow_count!=badcol_count)
cout<<"Corrupt\n";
else if (badrow_count==badcol_count && badrow_count==1)
cout<<"Change bit ("<<badrow_index+1<<","<<badcol_index+1<<")\n";
else if (badrow_count==badcol_count && badrow_count==0)
cout<<"OK\n";
cout.flush();
}
}[/cpp]
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

For each test-case, ... read the input thoroughly. Eventhough you detect bad stuff way before you read the whole array ... you still need to read all the array-elements.

-turuthok-
turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

One suggestion to improve speed and save some memory:

You don't really need to allocate list[][], do you ??? A simple int should be sufficient.

-turuthok-
mido
Learning poster
Posts: 78
Joined: Sun Jun 16, 2002 9:48 pm
Location: Cairo,Egypt

Post by mido »

I did just that...major thanks!!!!
Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

541 - Error Correction - I am getting a little confused

Post by Almost Human »

why is it P.E ? any suggestion will be appreciated

Code: Select all

#include <stdio.h>

char array[100][100] , count[2][100] ;
int MaxArr ;

char isfutile ( void ) ;

int main ( )
{
  int i , j , note ;
  char flag ;

/*  freopen ( "541.in" , "r" , stdin ) ;
  freopen ( "541.out" , "w" , stdout ) ;*/

  while ( 1 )
  {
	 scanf ( "%i" , &MaxArr ) ;

	 if ( MaxArr < 1 ) break ;

	 for ( i = 0 ; i < MaxArr ; i ++ )
		for ( j = 0 ; j < MaxArr ; j ++ )
		  scanf ( "%i" , &array[i][j] ) ;

	 flag = 0 ;

	 for ( i = 0 ; i < MaxArr ; i ++ )
	 {
		for ( count[0][i] = count[1][i] = 0 , j = 0 ; j < MaxArr ; j ++ )
		  count[0][i] += array[i][j] , count[1][i] += array[j][i] ;
		if ( count[0][i] % 2 || count[1][i] % 2 ) flag = 1 ;
	 }

	 if ( !flag )
	 {
		printf ( "OK\n" ) ;
		continue ;
	 }

	 if ( isfutile ( ) )
		printf ( "Corrupt\n" ) ;
	 else
	 {
		for ( i = 0 ; count[1][i] % 2 == 0 ; i ++ ) ;
		for ( j = 0 ; count[0][j] % 2 == 0 ; j ++ ) ;

		printf ( "Change bit ( %i , %i )\n" , j + 1 , i + 1 ) ;
	 }
  }

  return 0 ;
}

char isfutile ( void )
{
  char flag ;
  int i ;

  for ( flag = 0 , i = 0 ; i < MaxArr ; i ++ )
	 if ( count[0][i] % 2 ) flag ++ ;

  if ( flag > 1 ) return 1 ;

  for ( i = 0 , flag = 0 ; i < MaxArr ; i ++ )
	 if ( count[1][i] % 2 ) flag ++ ;

  if ( flag > 1 ) return 1 ;

  return 0 ;
}
Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

Post by Eric »

printf ( "Change bit ( %i , %i )\n" , j + 1 , i + 1 ) ;
There is no space between the numbers.
Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

Post by Almost Human »

allright !!! it is accepted ..

many many thanks
kuloch2
New poster
Posts: 1
Joined: Tue Sep 30, 2003 5:41 am

541

Post by kuloch2 »

Hey, I'm pretty new here. I've had trouble getting the memory usage low enough with problem 541. A couple C++ solutions I've seen used a char[100][100], so I can't imagine how my solution would be in excess when those wouldn't...

Anyway, here's the code. I'd appreciate any suggestions.

[java]
import java.io.*;
import java.util.*;

class Main {

public static void main(String args[]) {

while (true) {

byte n = Byte.parseByte(ReadLn(5));
if (n == 0)
System.exit(0);

String input;
byte[] sumRow = new byte[n], sumCol = new byte[n];

for (int i=0; i<n; i++) {
input = ReadLn(255);
for (int j=0; j<n; j++) {
byte tmp = (byte)(input.charAt(j*2) - '0');
sumRow += tmp;
sumCol[j] += tmp;
}
}

byte row = 0, numR = 0, col = 0, numC = 0;
for (int i=0; i<n; i++) {
if (sumRow % 2 != 0) {
row = (byte)(i + 1);
numR++;
}
if (sumCol % 2 != 0) {
col = (byte)(i + 1);
numC++;
}
}

if (numR == 0 && numC == 0) {
System.out.println("OK");
} else if (numR == 1 && numC == 1) {
System.out.println("Change bit ("+ row +","+ col +")");
} else {
System.out.println("Corrupt");
}
}
}

static String ReadLn(int maxLg) {
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;
String line = "";
try {
while (lg < maxLg) {
car = System.in.read();
if ((car < 0) || (car == '\n'))
break;
lin[lg++] += car;
}
} catch (IOException e) {
return (null);
}
if ((car < 0) && (lg == 0))
return (null); // eof
return (new String(lin, 0, lg));
}
}
[/java]
Kuloch
New poster
Posts: 1
Joined: Tue Sep 30, 2003 4:01 am

Post by Kuloch »

I finally realized (haven't looked at it for a couple weeks) that I was needlessly creating a byte[][] array (since you never look at each cell but once). But not only is it still giving me a "Too much memory" error, but the Judge says I'm using the exact same 135152 Kbytes as before. There's no way that removing a byte[][] array had no effect on memory usage.

Please someone help me here... I'm utterly clueless about what to do.
problem
New poster
Posts: 27
Joined: Mon Nov 10, 2003 12:40 am

541 wa help me

Post by problem »

here is my source code.i dont find any kind of problem.help me about this problem.judge reply wa.





/* @JUDGE_ID: xxxxxx 541 C++ */


#include<stdio.h>
#include<string.h>
main()

{
freopen("c:\\error.in","r",stdin);
// freopen("d:\\on","w",stdout);
int i;

while(scanf("%d",&i)==1)
{
if(i==0)break;
int p=0,li1=0,li2=0,sto=0,sto1=0,pot=0;
// scanf("%d",&i);
int a[10][10];
for(int j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
scanf("%d",&a[j][k]) ;
}
}
int check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[j][k];
}
if(p%2)
{ check=0;
li1++;
pot=0;
pot=li1;
//pot=0
} //check=1;
if(pot==1&&check!=1)
{
sto=j;
pot++;
check=1;
}
p=0;

}
check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[k][j];
}
if(p%2)
{
check=0;
li2++;
int pot2=li2;
if(pot2==1&&check!=1)
{
sto1=j;
pot2++;
check=1;
}
}
p=0;
}
if(sto==0&&sto1==0)
printf("OK\n");
if(li1==1&&li2==1)
printf("Change bit (%d,%d)\n",sto+1,sto1+1);
if(li1>1||li2>1)
printf("Courupt\n");

}
fclose(stdin);
}
problem
New poster
Posts: 27
Joined: Mon Nov 10, 2003 12:40 am

541 wa help me plz

Post by problem »

error correction i m frustrated.wa.plz help me.
[cpp]
/* @JUDGE_ID: xxxxxx 541 C++ */


#include<stdio.h>
#include<string.h>
main()

{
//freopen("c:\\error.in","r",stdin);
// freopen("d:\\on","w",stdout);
int i;

while(scanf("%d",&i)==1)
{
if(i==0)break;
int p=0,li1=0,li2=0,sto=0,sto1=0,pot=0;
// scanf("%d",&i);
int a[10][10];
for(int j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
scanf("%d",&a[j][k]) ;
}
}
int check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[j][k];
}
if(p%2)
{ check=0;
li1++;
pot=0;
pot=li1;
//pot=0
} //check=1;
if(pot==1&&check!=1)
{
sto=j;
pot++;
check=1;
}
p=0;

}
check=0;
for(j=0;j<i;j++)
{
for(int k=0;k<i;k++)
{
p=p+a[k][j];
}
if(p%2)
{
check=0;
li2++;
int pot2=li2;
if(pot2==1&&check!=1)
{
sto1=j;
pot2++;
check=1;
}
}
p=0;
}
if(sto==0&&sto1==0)
printf("OK\n");
if(li1==1&&li2==1)
printf("Change bit (%d,%d)\n",sto+1,sto1+1);
if(li1>1||li2>1)
printf("Courupt\n");

}
fclose(stdin);
}
[\cpp]
Kamanashish
New poster
Posts: 10
Joined: Wed Dec 17, 2003 3:12 pm
Location: Dhaka
Contact:

541 Why WA?

Post by Kamanashish »

Cut
Last edited by Kamanashish on Sat Mar 20, 2004 8:44 am, edited 1 time in total.
Work hard.
nahid
New poster
Posts: 18
Joined: Wed Oct 04, 2006 8:59 pm
Location: DHAKA,BANGLADESH
Contact:

541(error crrection)-but i'm in error(WA)

Post by nahid »

Pleas help the little programmer
. I have solved a number of promlem but most of them are wrong by on-line judge. please help me about 541. here is my code
Last edited by nahid on Thu Nov 09, 2006 2:50 am, edited 1 time in total.
Tariq Shahriar
New poster
Posts: 17
Joined: Wed Mar 01, 2006 8:34 pm
Location: 2nd floor

Post by Tariq Shahriar »

the mistake is
int i,j,n,m,er=0,row,col,ec=0;
you need to initialize er,ec for every input set.
so place the initialization here.

Code: Select all

while(scanf("%d",&n)) 
   { 
      if(n==0) 
         break; 
      er=ec=0;
     .........
Be careful about initialization error.
[ Common thing of every man is that, everyone thinks that he is uncommon ]
Rushow
New poster
Posts: 14
Joined: Sat Oct 14, 2006 4:09 pm
Location: Dhaka,Bangladesh

541-error correction --help is wanted

Post by Rushow »

I think it is an easy problem to solve. But I can't understand what is problem with my code, that make me to get WA. Here is my code. Is there anybody to help me?
Last edited by Rushow on Mon Mar 26, 2007 8:49 am, edited 1 time in total.
Post Reply

Return to “Volume 5 (500-599)”