ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1033. Labyrinth

I GET WA1!!!!!
Posted by Marian Darius 2 Nov 2012 16:05
PLEASE TELL ME WHAT IS WRONG! I TRIED EVERYTHING!!!

#include<stdio.h>
#include<queue>
using namespace std;
struct Coord {int x,y;};
int a[40][40];
inline int number(int x,int y)
{
    int nr=0;
    if(a[x+1][y]==-1) nr++;
    if(a[x-1][y]==-1) nr++;
    if(a[x][y+1]==-1) nr++;
    if(a[x][y-1]==-1) nr++;
    return nr;
}
Coord make(int a,int b)
{
    Coord x;
    x.x=a;x.y=b;
    return x;
}
void lee(Coord s)
{
    int x,y;
    queue<Coord> q;
    q.push(s);
    a[s.x][s.y]=1;
    while(!q.empty())
    {
        x=q.front().x;y=q.front().y;
        if(a[x+1][y]==0) {a[x+1][y]=1;q.push(make(x+1,y));}
        if(a[x-1][y]==0) {a[x-1][y]=1;q.push(make(x-1,y));}
        if(a[x][y+1]==0) {a[x][y+1]=1;q.push(make(x,y+1));}
        if(a[x][y-1]==0) {a[x][y-1]=1;q.push(make(x,y-1));}
        q.pop();
    }
}
int main()
{
    int n,i,j;char ch;
    scanf("%d\n",&n);
    for(i=1;i<=n;i++,scanf("%c",&ch))
        for(j=1;j<=n;j++)
        {
            scanf("%c",&ch);
            if(ch=='.') a[i][j]= 0;
            else        a[i][j]=-1;
        }
    for(i=2;i<=n+1;i++)
        a[i][0]=a[0][i]=-1;
    for(i=0;i<n;i++)
        a[i][n+1]=a[n+1][i]=-1;
    lee(make(1,1));
    lee(make(n,n));
    int nr=0;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            if(a[i][j]==1)
                nr+=number(i,j);
    printf("%d\n",9*nr);
    return 0;
}
Re: I GET WA1!!!!!
Posted by gautamvs 11 Sep 2013 15:23
Is sample test case working for this program ?
Re: I GET WA1!!!!!
Posted by Hristo Nikolaev (B&W) 24 Dec 2022 16:32
WA1 usually means the new lines ( \n ) or ( \r\n ) are not handled correctly.