시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 2955 | 664 | 379 | 18.204% |
백준이는 2580번 스도쿠 문제를 풀기 위해 아래와 같은 코드를 작성했다.
#include <iostream> using namespace std; int a[10][10]; bool c[10][10]; bool c2[10][10]; bool c3[10][10]; int n=9; int cnt=0; int square(int x, int y) { return (x/3)*3+(y/3); } bool go(int z) { cnt += 1; if (cnt >= 10000000) { return true; } if (z == 81) { for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { cout << a[i][j] << ' '; } cout << '\n'; } return true; } int x = z/n; int y = z%n; if (a[x][y] != 0) { return go(z+1); } else { for (int i=1; i<=9; i++) { if (c[x][i] == 0 && c2[y][i] == 0 && c3[square(x,y)][i]==0) { c[x][i] = c2[y][i] = c3[square(x,y)][i] = true; a[x][y] = i; if (go(z+1)) { return true; } a[x][y] = 0; c[x][i] = c2[y][i] = c3[square(x,y)][i] = false; } } } return false; } int main() { for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { cin >> a[i][j]; if (a[i][j] != 0) { c[i][a[i][j]] = true; c2[j][a[i][j]] = true; c3[square(i,j)][a[i][j]] = true; } } } go(0); return 0; }
변수 cnt
에 저장된 값이 가장 큰 스도쿠 퍼즐을 출력하는 프로그램을 작성하시오. 문제의 점수는 cnt
에 저장된 값이다.
입력은 없다.
총 9개의 줄에 스도쿠 퍼즐을 출력한다. 빈 칸은 0으로 출력한다. (2580번 문제의 입력을 출력한다)
만약, 풀 수 없는 스도쿠 퍼즐을 출력한 경우에는 틀렸습니다를 받게 된다.
0 3 5 4 6 9 2 7 8 7 8 2 1 0 5 6 0 9 0 6 0 2 7 8 1 3 5 3 2 1 0 4 6 8 9 7 8 0 4 9 1 3 5 0 6 5 9 6 8 2 0 4 1 3 9 1 7 6 5 2 0 8 0 6 0 3 7 0 1 9 5 2 2 5 8 3 9 4 7 6 0