#include using namespace std; int main() { int puzzle[4][4]; int answer[4][4]; int i, j, m, n; bool result = true; int x = 1; //puzzleを初期化 for (int i = 0; i < 4;i++) { for (int j = 0; j < 4;j++) { puzzle[i][j] = x; x++; } } puzzle[3][3] = 0; //目標を入力 for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> answer[i][j]; } } //目標との照合 for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { for (m = 0; m < 4; m++) { for (n = 0; n < 4; n++) { switch (result) { case true: if (puzzle[i][j] == answer[m][n] && puzzle!=0) { if ((abs(i - m) > 1 && abs(j - n) > 1) || (abs(i - m) == 1 && abs(j - n) == 1)) { result = false; } else if(n != 3 && m != 3) { if (answer[m - 1][n - 1] - answer[m][n] == -1) { result = false; } } } break; case false: break; } } } } } if (result == true) cout << "Yes"; if (result == false) cout << "No"; }