Submission #1275890


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

void pro(int n,char cop[10][10]);
void solve();
bool drow(int x,int y,char par[10][10]);

char fid[10][10];
int dx[] = {-1,-1,1,1},dy[] = { 1,-1,1,-1};
int str[10]= {0};
bool O = false;

bool drow(int x,int y,char par[10][10])
{
    for(int i = 0; i < 8; i++)
    {
        if(i != x)
        {
            if(par[i][y] == 'Q')
            {
                return false;
            }
            par[i][y] = '#';
        }
        if(i != y)
        {
            if(par[x][i] == 'Q')
            {
                return false;
            }
            par[x][i] = '#';
        }
    }
    for(int i = 0; i < 4; i++)
    {
        int nowx = x + dx[i],nowy = y + dy[i];
        while(0 <= nowx && nowx < 8 && 0 <= nowy && nowy < 8)
        {
            if(par[nowx][nowy] == 'Q')
            {
                return false;
            }
            par[nowx][nowy] = '#';
            nowx += dx[i],nowy += dy[i];
        }
    }
    return true;
}

void pro(int n,char cop[10][10])
{
    if(n == str[0] || n == str[1] || n == str[2])
    {
        pro(n + 1,cop);
        return;
    }
    if(n == 8 && !O)
    {
        O = true;
        for(int i = 0; i < 8; i++)
        {
            for(int j = 0; j < 8; j++)
            {
                if(cop[i][j] == '#')
                {
                    cop[i][j] = '.';
                }
                printf("%c",cop[i][j]);
            }
            printf("\n");
        }
        return;
    }
    char ncop[10][10];
    bool nstr[8];
    for(int i = 0; i < 8; i++)
    {
        for(int j = 0; j < 8; j++)
        {
            ncop[i][j] = cop[i][j];
        }
    }
    for(int i = 0; i < 8; i++)
    {
        if(ncop[n][i] == '.')
        {
            char nncop[10][10];
            for(int j = 0; j < 8; j++)
            {
                for(int k = 0; k < 8; k++)
                {
                    nncop[j][k] = ncop[j][k];
                }
            }
            nncop[n][i] = 'Q';
            drow(n,i,nncop);
            pro(n + 1,nncop);
            nstr[i] = false;
        }
    }
    return;
}

int main()
{
    int f = 0;
    for(int i = 0; i < 8; i++)
    {
        for(int j = 0; j < 8; j++)
        {
            scanf(" %c",&fid[i][j]);
        }
    }
    for(int i = 0; i < 8; i++)
    {
        for(int j = 0; j < 8; j++)
        {
            if(fid[i][j] == 'Q')
            {
                str[f] = i;
                f++;
                if(!drow(i,j,fid))
                {
                    printf("No Answer\n");
                    return 0;
                }
            }
        }
    }
    pro(0,fid);
    if(!O)
    {
        printf("No Answer\n");
    }
    return 0;
}

Submission Info

Submission Time
Task C - パズルのお手伝い
User unit
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2866 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:111:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c",&fid[i][j]);
                                    ^

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 42
Set Name Test Cases
All 00_sample1.txt, 00_sample2.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 01_rnd_20.txt, 01_rnd_21.txt, 01_rnd_22.txt, 01_rnd_23.txt, 01_rnd_24.txt, 01_rnd_25.txt, 01_rnd_26.txt, 01_rnd_27.txt, 01_rnd_28.txt, 01_rnd_29.txt, 01_rnd_30.txt, 01_rnd_31.txt, 01_rnd_32.txt, 01_rnd_33.txt, 01_rnd_34.txt, 01_rnd_35.txt, 01_rnd_36.txt, 01_rnd_37.txt, 01_rnd_38.txt, 01_rnd_39.txt
Case Name Status Exec Time Memory
00_sample1.txt AC 1 ms 256 KB
00_sample2.txt AC 1 ms 256 KB
01_rnd_00.txt AC 1 ms 256 KB
01_rnd_01.txt AC 1 ms 256 KB
01_rnd_02.txt AC 1 ms 256 KB
01_rnd_03.txt AC 1 ms 256 KB
01_rnd_04.txt AC 1 ms 256 KB
01_rnd_05.txt AC 1 ms 256 KB
01_rnd_06.txt AC 1 ms 256 KB
01_rnd_07.txt AC 1 ms 256 KB
01_rnd_08.txt AC 1 ms 256 KB
01_rnd_09.txt AC 1 ms 256 KB
01_rnd_10.txt AC 1 ms 256 KB
01_rnd_11.txt AC 1 ms 256 KB
01_rnd_12.txt AC 1 ms 256 KB
01_rnd_13.txt AC 1 ms 256 KB
01_rnd_14.txt AC 1 ms 256 KB
01_rnd_15.txt AC 1 ms 256 KB
01_rnd_16.txt AC 1 ms 256 KB
01_rnd_17.txt AC 1 ms 256 KB
01_rnd_18.txt AC 1 ms 256 KB
01_rnd_19.txt AC 1 ms 256 KB
01_rnd_20.txt AC 1 ms 256 KB
01_rnd_21.txt AC 1 ms 256 KB
01_rnd_22.txt AC 1 ms 256 KB
01_rnd_23.txt AC 1 ms 256 KB
01_rnd_24.txt AC 1 ms 256 KB
01_rnd_25.txt AC 1 ms 256 KB
01_rnd_26.txt AC 1 ms 256 KB
01_rnd_27.txt AC 1 ms 256 KB
01_rnd_28.txt AC 1 ms 256 KB
01_rnd_29.txt AC 1 ms 256 KB
01_rnd_30.txt AC 1 ms 256 KB
01_rnd_31.txt AC 1 ms 256 KB
01_rnd_32.txt AC 1 ms 256 KB
01_rnd_33.txt AC 1 ms 256 KB
01_rnd_34.txt AC 1 ms 256 KB
01_rnd_35.txt AC 1 ms 256 KB
01_rnd_36.txt AC 1 ms 256 KB
01_rnd_37.txt AC 1 ms 256 KB
01_rnd_38.txt AC 1 ms 256 KB
01_rnd_39.txt AC 1 ms 256 KB