fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. template<typename... T>
  4. void see(T&... args) { ((cin >> args), ...);}
  5. template<typename... T>
  6. void put(T&&... args) { ((cout << args << " "), ...);}
  7. template<typename... T>
  8. void putl(T&&... args) { ((cout << args << " "), ...); cout<<'\n';}
  9. #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
  10. void err(istream_iterator<string> it) {}
  11. template<typename T, typename... Args>
  12. void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}
  13. #define int long long
  14. #define pb push_back
  15. #define F first
  16. #define S second
  17. #define ll long long
  18. #define ull unsigned long long
  19. #define ld long double
  20. #define pii pair<int,int>
  21. #define tiii tuple<int,int,int>
  22. #define vi vector<int>
  23. #define vii vector<pii>
  24. #define vc vector
  25. #define L cout<<'\n';
  26. #define E cerr<<'\n';
  27. #define all(x) x.begin(),x.end()
  28. #define rep(i,a,b) for (int i=a; i<b; ++i)
  29. #define rev(i,a,b) for (int i=a; i>b; --i)
  30. #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  31. #define setpr(x) cout<<setprecision(x)<<fixed
  32. #define sz size()
  33. #define seea(a,x,y) for(int i=x;i<y;i++){cin>>a[i];}
  34. #define seev(v,n) for(int i=0;i<n;i++){int x; cin>>x; v.push_back(x);}
  35. #define sees(s,n) for(int i=0;i<n;i++){int x; cin>>x; s.insert(x);}
  36. const ll inf = 1LL<<62;
  37. const ld ep = 0.0000001;
  38. const ld pi = acos(-1.0);
  39. const ll md = 1000000007;
  40.  
  41. const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2};
  42. const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1};
  43.  
  44. int grid[9][9];
  45.  
  46. int deg(int x1, int y1){
  47. int s = 0;
  48. rep(i1,0,8){
  49. int x2 = x1+fx[i1], y2 = y1+fy[i1];
  50. if (x2>=1 && x2<=8 && y2>=1 && y2<=8 && !grid[x2][y2]) s++;
  51. }
  52. return s;
  53. }
  54. bool rec(int mv, int x, int y){
  55. grid[x][y] = mv;
  56. if (mv == 64) return 1;
  57. vc<tiii> v;
  58. rep(i,0,8){
  59. int x1 = x+fx[i], y1 = y+fy[i];
  60. if (x1>=1 && x1<=8 && y1>=1 && y1<=8 && !grid[x1][y1]){
  61. int d = deg(x1,y1);
  62. v.pb({d,x1,y1});
  63. }
  64. }
  65. sort(all(v));
  66. for (auto [d,x1,y1]: v){
  67. if (rec(mv+1,x1,y1)) return 1;
  68. }
  69. grid[x][y]=0;
  70. return 0;
  71. }
  72. void solve(){
  73. int x,y; see(y,x);
  74. rec(1,x,y);
  75. rep(i,1,9){
  76. rep(j,1,9){
  77. printf("%-2d ",grid[i][j]);
  78. }
  79. printf("\n");
  80. }
  81. }
  82. signed main(){
  83. IOS;
  84. #ifdef LOCAL
  85. freopen("input.txt", "r" , stdin);
  86. freopen("output.txt", "w", stdout);
  87. #endif
  88. int t=1;
  89. //cin>>t;
  90. while(t--){
  91. solve();
  92. //cout<<'\n';
  93. }
  94. #ifdef LOCAL
  95. clock_t tStart = clock();
  96. cerr<<fixed<<setprecision(10)<<"\nTime Taken: "<<(double)(clock()- tStart)/CLOCKS_PER_SEC<<endl;
  97. #endif
  98. }
  99.  
Runtime error #stdin #stdout 0.02s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty