#include #include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main(){ vector> v(4, vector(4)), g(4, vector(4)), s; vector dx{1, 0, -1, 0}, dy{0, 1, 0, -1}; for (int i = 0; i < 4; i++){ for (int j = 0; j < 4; j++){ cin >> g[i][j]; v[i][j] = i*4 + j + 1; } } v[3][3] = 0; s = v; deque>> dq; deque> pos; pos.push_back({3, 3}); dq.push_back(v); while (!pos.empty()) { vector p_tmp = pos.front(); vector> v_tmp = dq.front(); pos.pop_front(); dq.pop_front(); if (g == v_tmp) { cout << "Yes" << endl; return 0; } for (int i = 0; i < 4; i++){ int nx, ny; nx = p_tmp[1] + dx[i]; ny = p_tmp[0] + dy[i]; vector> v_tmp2 = v_tmp; if (nx >= 0 && nx < 4 && ny >= 0 && ny <4 && v_tmp2[ny][nx] == s[ny][nx]){ swap(v_tmp2[ny][nx], v_tmp2[p_tmp[0]][p_tmp[1]]); dq.push_back(v_tmp2); pos.push_back({ny, nx}); } } } cout << "No" << endl; }