Submission #2865857


Source Code Expand

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define getc(i, j) (i-j+N)
#define getd(i, j) (i+j)
#define GG puts("Fuck")
const int N = 8;
bool a[20], b[20], c[20], d[20];
char map[20];
int ans[10][10];
bool print() {
	for(int i = 1; i <= N; i ++ ) {
		for(int j = 1; j <= N; j ++ ) {
			if(ans[i][j]) std :: cout<<'Q';
			else std :: cout<<'.';
		}
		std :: cout << std :: endl;
	}
	exit(0);
}
void Dfs(int pos) {
	// std :: cout << "Pos :: " << pos << std :: endl;
	// puts("*************************");
	// print();
	// puts("*************************");
	if(a[pos]) Dfs(pos+1);
	if(pos == N+1) print();
	for(int j = 1; j <= N; j ++ ) {
		// if(pos == 2 && j == 5) {
		// 	std :: cout << "B :: " << b[j] << " C :: " << c[getc(pos, j)] << " D :: " << d[getd(pos, j)] << std :: endl;
		// }
		if(!a[pos] && !b[j] && !c[getc(pos, j)] && !d[getd(pos, j)]) {
			// if(pos == 3 && j == 7) GG;
			a[pos] = 1;
			b[j] = 1;
			c[getc(pos, j)] = 1;
			d[getd(pos, j)] = 1;
			ans[pos][j] = 1;
			Dfs(pos+1);
			a[pos] = 0;
			b[j] = 0;
			c[getc(pos, j)] = 0;
			d[getd(pos, j)] = 0;
			ans[pos][j] = 0;
		}
	}
}
int main() {
	std :: ios :: sync_with_stdio(false);
	for(int i = 1; i <= N; i ++ ) {
		scanf("%s", map+1);
		for(int j = 1; j <= N; j ++ ) {
			if(map[j] == 'Q') {
				a[i] = 1;
				b[j] = 1;
				c[getc(i, j)] = 1;
				d[getd(i, j)] = 1;
				ans[i][j] = 1;
			}
		}
	}
	// std :: cout << " D[7] :: " << d[7] << std :: endl;
	// for(int i = 1; i <= N; i ++ ) std :: cout << i << " A[i] :: " << a[i] << std :: endl;
	Dfs(1);
	if(!flag) std :: cout << "No Answer" << std :: endl;
}
/*
........
........
.......Q
........
..Q.....
........
.Q......
........
*/

Submission Info

Submission Time
Task C - パズルのお手伝い
User Yirannnn
Language C++ (GCC 5.4.1)
Score 0
Code Size 1790 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:67:6: error: ‘flag’ was not declared in this scope
  if(!flag) std :: cout << "No Answer" << std :: endl;
      ^
./Main.cpp:53:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", map+1);
                     ^