541 - Error Correction
Moderator: Board moderators
541 - Error Correction
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]
[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]
-
- Learning poster
- Posts: 93
- Joined: Sun Jan 12, 2003 3:30 pm
541 - Error Correction - I am getting a little confused
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 ;
}
-
- Learning poster
- Posts: 93
- Joined: Sun Jan 12, 2003 3:30 pm
541
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]
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]
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.
Please someone help me here... I'm utterly clueless about what to do.
541 wa help me
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);
}
/* @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);
}
541 wa help me plz
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]
[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]
-
- New poster
- Posts: 10
- Joined: Wed Dec 17, 2003 3:12 pm
- Location: Dhaka
- Contact:
541 Why WA?
Cut
Last edited by Kamanashish on Sat Mar 20, 2004 8:44 am, edited 1 time in total.
Work hard.
541(error crrection)-but i'm in error(WA)
. 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 codePleas help the little programmer
Last edited by nahid on Thu Nov 09, 2006 2:50 am, edited 1 time in total.
-
- New poster
- Posts: 17
- Joined: Wed Mar 01, 2006 8:34 pm
- Location: 2nd floor
the mistake is
so place the initialization here.
Be careful about initialization error.
you need to initialize er,ec for every input set.int i,j,n,m,er=0,row,col,ec=0;
so place the initialization here.
Code: Select all
while(scanf("%d",&n))
{
if(n==0)
break;
er=ec=0;
.........
[ Common thing of every man is that, everyone thinks that he is uncommon ]
541-error correction --help is wanted
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?
Code: Select all
Last edited by Rushow on Mon Mar 26, 2007 8:49 am, edited 1 time in total.