Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fr first
- #define sc second
- #define MAX ((ll)(1e12+100))
- #define ARRS ((ll)(3e5+100))
- ll a[10][10];
- ll pas[1000][1000];
- ll fr[5][5]={
- 1,9,16,-1,10,
- 18,4,22,19,5,
- 24,14,11,8,15,
- 2,20,17,3,21,
- 12,7,23,13,6
- };
- ll gd[5][5]={
- 1,17,24,2,18,
- 22,14,5,21,13,
- 25,8,11,16,7,
- 4,20,23,3,19,
- 10,15,6,9,12
- };
- ll gr[5][5]={
- 1,9,25,2,10,
- 14,17,5,13,16,
- 7,23,20,8,24,
- 4,12,15,3,11,
- 21,18,6,22,19
- };
- ll glh[5][5]={
- 21,18,6,22,19,
- 4,12,15,3,11,
- 7,23,20,8,24,
- 14,17,5,13,16,
- 1,9,25,2,10
- };
- ll gup[5][5]={
- 12,9,6,15,10,
- 19,3,23,20,4,
- 7,16,11,8,25,
- 13,21,5,14,22,
- 18,2,24,17,1
- };
- ll gdl[5][5]={
- 12,9,6,13,10,
- 20,3,16,19,4,
- 7,23,11,8,24,
- 15,18,5,14,17,
- 21,2,25,22,1
- };
- ll gdr[5][5]={
- 21,18,6,22,19,
- 4,12,15,3,11,
- 7,23,20,8,24,
- 14,17,5,13,16,
- 1,9,25,2,10
- };
- ll gdu[5][5]={
- 10,15,6,9,12,
- 4,20,23,3,19,
- 25,8,11,16,7,
- 22,14,5,21,13,
- 1,17,24,2,18,
- };
- ll glf[5][5]={
- 17,25,6,18,15,
- 11,3,21,12,4,
- 23,8,16,24,7,
- 20,13,5,19,14,
- 10,2,22,9,1
- };
- ll ooo[5][10]={
- 43,37,50,42,11,31,24,18,32,23,
- 8,40,45,35,6,46,13,21,4,16,
- 49,28,10,38,29,26,2,30,25,19,
- 44,36,7,41,12,34,5,17,33,22,
- 9,39,48,27,1,47,14,20,3,15
- };
- ll oow[5][10]={
- 15,50,26,16,11,25,17,34,24,44,
- 8,30,13,48,6,32,22,46,4,21,
- 27,39,10,28,40,37,2,43,18,35,
- 14,49,7,31,12,47,5,33,23,45,
- 9,29,41,38,1,42,19,36,3,20
- };
- ll g1[5][5]={
- 18,2,24,17,1,
- 13,21,5,14,22,
- 7,16,11,8,25,
- 19,3,23,20,4,
- 12,9,6,15,10
- };
- ll g2[5][5]={
- 21,2,25,22,1,
- 15,18,5,14,17,
- 7,23,11,8,24,
- 20,3,16,19,4,
- 12,9,6,13,10
- };
- ll g3[5][5]={
- 18,2,24,17,1,
- 13,21,5,14,22,
- 7,16,11,8,25,
- 19,3,23,20,4,
- 12,9,6,15,10
- };
- ll g4[5][5]={
- 19,11,25,18,10,
- 6,3,15,7,4,
- 13,23,20,12,24,
- 16,8,5,17,9,
- 21,2,14,22,1
- };
- ll gfk[5][5]={
- 17,25,6,18,15,
- 11,3,21,12,4,
- 23,8,16,24,7,
- 20,13,5,19,14,
- 10,2,22,9,1
- };
- ll ps5[5][5]={
- 1,9,18,2,10,
- 20,4,24,21,5,
- 17,14,11,8,15,
- 25,22,19,3,23,
- 12,7,16,13,6,
- };
- ll C;
- void put(ll x,ll y,ll a[5][5]){
- for(int i=0; i<5; i++){
- for(int j=0; j<5; j++){
- pas[x+i][y+j]=a[i][j]+C;
- }
- }
- C+=25;
- }
- void put(ll x,ll y,ll a[5][10]){
- for(int i=0; i<5; i++){
- for(int j=0; j<10; j++){
- pas[x+i][y+j]=a[i][j]+C;
- }
- }
- C+=50;
- }
- int main(){
- ll n;
- cin>>n;
- ll m=n/5;
- if(n==5){
- put(0,0,ps5);
- for(int i=0; i<n; i++){
- for(int j=0; j<n; j++){
- cout<<pas[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
- if(n==10){
- ll pas[10][10]={
- 1,52,29,8,51,28,9,50,37,16, 85,95,59,86,94,66,87,93,65,88, 40,19,100,39,18,76,38,17,77,49, 2,53,30,7,58,27,10,89,36,15, 84,96,60,75,99,67,72,92,64,71, 41,20,82,44,23,90,45,24,78,48, 3,54,31,6,57,26,11,68,35,14, 83,97,61,74,98,62,73,91,63,70, 42,21,81,43,22,80,46,25,79,47, 4,55,32,5,56,33,12,69,34,13, };
- for(int i=0; i<n; i++){
- for(int j=0; j<n; j++){
- cout<<pas[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
- C=0;
- for(int i=0; i<5; i++){
- for(int j=0; j<5; j++){
- if(fr[i][j]!=-1)
- pas[i][j]=C+fr[i][j];
- }
- }
- C+=24;
- for(int i=1; i<m-1; i++){
- for(int x=i*5; x<i*5+5; x++){
- for(int y=0; y<5; y++){
- pas[x][y]=gd[x-i*5][y]+C;
- }
- }
- C+=25;
- }
- for(int i=0; i<m-1; i++){
- for(int x=0; x<5; x++){
- for(int y=i*5; y<i*5+5; y++){
- pas[(m-1)*5+x][y]=gr[x][y-i*5]+C;
- }
- }
- C+=25;
- }
- put((m-1)*5,(m-1)*5,gd);
- for(int k=0; k<(m-2)/2; k++){
- put((m-2-k*2)*5,(m-1)*5,glh);
- for(int t=0; t<m-3; t++){
- put((m-2-k*2)*5,(m-2-t)*5,gdl);
- }
- put((m-2-k*2)*5,5,gup);
- put((m-3-k*2)*5,5,gdl);
- for(int t=0; t<m-3; t++){
- put((m-3-k*2)*5,(t+2)*5,gdr);
- }
- put((m-3-k*2)*5,(m-1)*5,gdu);
- }
- if(m%2==0){
- put(0,(m-1)*5,glh);
- for(int t=0; t<m-3; t++){
- put(0,(m-2-t)*5,gdl);
- }
- put(0,5,glf);
- }
- else {
- put(5,(m-1)*5,glh);
- put(5,(m-2)*5,gup);
- if(n==15){
- put(0,(m-2)*5,oow);
- }
- else{
- put(0,(m-2)*5,ooo);
- for(int i=0; i<(m-3-2)/2; i++){
- put(0,(m-3-i*2)*5,g1);
- put(5,(m-3-i*2)*5,g2);
- put(5,(m-4-i*2)*5,g3);
- put(0,(m-4-i*2)*5,g4);
- }
- put(0,10,g1);
- put(5,10,g2);
- put(5,5,g3);
- put(0,5,gfk);
- }
- }
- pas[0][3]=C+1;
- for(int i=0; i<n; i++){
- for(int j=0; j<n; j++){
- cout<<pas[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement