Language: C++

#include<stdio.h>
#include<map>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<algorithm>
#include<set>
std::map<unsigned __int64,int> memo2;


const int LIMIT=19;
int xs[16]={3, 0,1,2,3, 0,1,2,3, 0,1,2,3, 0,1,2};
int ys[16]={3, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3};




 
int m(unsigned __int64 e1){
   unsigned __int64 b=15;
   int slide=0;
   int sum=0;
   for(int i=3;i>=0;i--){
       for(int j=3;j>=0;j--){
           unsigned __int64 n=((e1>>slide)&b);
           	if(n>0){
		sum+=abs(i-ys[(int)n])+abs(j-xs[(int)n]);
	}
	slide+=4;
       }
   }
   return sum;
}
 
struct E{
   unsigned __int64 e;
   int no;
   bool operator<(const E& e1)const{
int a=m(e)+no;
int b=m(e1.e)+e1.no;
if(a!=b)return a>b;;
return no>e1.no;
   } 
};

std::set<unsigned __int64> memo[30];
std::map<unsigned __int64,int> memo3;
void move(unsigned __int64 e,std::map<unsigned __int64,int>& m0,std::set<unsigned __int64>& m2)  {
   unsigned __int64 s=15;
   int i,j;
   bool hit=false;
   for(i=3;i>=0;i--){
       for(j=3;j>=0;j--){
           if((s&e)==0){
               hit=true;
               break;
           }
           s=(s<<4);
       }
       if(hit==true)break;
   }
   unsigned __int64 e2;
   unsigned __int64 p1;
   if(i>0){
       p1=((s<<16)&e);
       e2=(e|(p1>>16))^p1;
       if(m0.find(e2)==m0.end()){
           m2.insert(e2);
       }
   }
   if(i<3){
       p1=((s>>16)&e);
       e2=(e|(p1<<16))^p1;
       if(m0.find(e2)==m0.end()){
           m2.insert(e2);
       }
   }
   if(j>0){
       p1=((s<<4)&e);
       e2=(e|(p1>>4))^p1;
       if(m0.find(e2)==m0.end()){
               m2.insert(e2);
       }
   }
   if(j<3){
       p1=((s>>4)&e);
       e2=(e|(p1<<4))^p1;
       if(m0.find(e2)==m0.end()){
           m2.insert(e2);
       }
   }

}
 
int main(){
   unsigned __int64 seed=0,j=4;
   for(unsigned __int64 i=15;i>=1;i--){
       seed=(seed|(i<<j));
       j+=4;
   }
   memo[0].insert(seed);
   memo2[seed]=0;
   std::set<unsigned __int64>::iterator it;
   for(int i=0;i<LIMIT;i++){
       for(it=memo[i].begin();it!=memo[i].end();it++){
           if(i==0){
               move((*it),memo2,memo[1]);
           }else{
               move((*it),memo2,memo[i+1]);
           }
       }

       for(it=memo[i+1].begin();it!=memo[i+1].end();it++){
           memo2[(*it)]=i+1;
       }
if(i>1)memo[i-1].clear();
   }
   int slide=64;
   unsigned __int64 p=0;
   unsigned __int64 n=0;
   for(int i=0;i<16;i++){
       slide-=4;
       std::cin>>n;
       p=(p|(n<<slide));
   }
   std::priority_queue<E> pq;
   E e3;
   e3.e=p;
   e3.no=0;
   pq.push(e3);
   int ans=100;
   while(pq.empty()==false){
       e3=pq.top();
       pq.pop();

       if(memo2.find(e3.e)!=memo2.end()){
           ans=std::min(memo2[e3.e]+e3.no,ans);
	continue;
}
       if(memo3.find(e3.e)!=memo3.end()){
	continue;
}
memo3[e3.e]=e3.no;
if(e3.no+LIMIT>=ans)continue;
if(m(e3.e)+e3.no>=ans)continue;


unsigned __int64 e=e3.e,p1,e2;
       E e4;


       unsigned __int64 s=15;
       int i,j;
       bool hit=false;
       for(i=3;i>=0;i--){
           for(j=3;j>=0;j--){
               if((s&e)==0){
                   hit=true;
                   break;
               }
               s=(s<<4);
           }
           if(hit==true)break;
       }
if(hit==false){
	printf("out");
}
       if(i>0){
           p1=((s<<16)&e);
           e2=(e|(p1>>16))^p1;
           e4.e=e2;
           e4.no=e3.no+1;
	if(memo3.find(e4.e)==memo3.end()){
		pq.push(e4);
           	}
}
       if(i<3){
           p1=((s>>16)&e);
           e2=(e|(p1<<16))^p1;
           e4.e=e2;
           e4.no=e3.no+1;
          
    if(memo3.find(e4.e)==memo3.end()){	
	pq.push(e4);
           }
       }
       if(j>0){
           p1=((s<<4)&e);
           e2=(e|(p1>>4))^p1;
           e4.e=e2;
           e4.no=e3.no+1;
	if(memo3.find(e4.e)==memo3.end()){	
		pq.push(e4);
        	}
       	
       }
       if(j<3){
           p1=((s>>4)&e);
           e2=(e|(p1<<4))^p1;
           e4.e=e2;
           e4.no=e3.no+1;
	if(memo3.find(e4.e)==memo3.end()){
		pq.push(e4);
       	    }
     	}
   }
   printf("%d\n",ans);
   return 0;
} 


Compiler output:
a.cc:8:30: error: wrong number of template arguments (1, should be at least 2)
    8 | std::map<unsigned __int64,int> memo2;
      |                              ^
In file included from /usr/include/c++/14/map:63,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_map.h:102:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:19:24: error: expected ',' or '...' before 'e1'
   19 | int m(unsigned __int64 e1){
      |                        ^~
a.cc: In function 'int m(unsigned int)':
a.cc:20:21: error: expected initializer before 'b'
   20 |    unsigned __int64 b=15;
      |                     ^
a.cc:25:29: error: expected initializer before 'n'
   25 |            unsigned __int64 n=((e1>>slide)&b);
      |                             ^
a.cc:26:20: error: 'n' was not declared in this scope
   26 |                 if(n>0){
      |                    ^
a.cc: At global scope:
a.cc:36:13: error: expected ';' at end of member declaration
   36 |    unsigned __int64 e;
      |             ^~~~~~~
      |                    ;
a.cc:36:21: error: 'e' does not name a type
   36 |    unsigned __int64 e;
      |                     ^
a.cc: In member function 'bool E::operator<(const E&) const':
a.cc:39:9: error: 'e' was not declared in this scope
   39 | int a=m(e)+no;
      |         ^
a.cc:40:12: error: 'const struct E' has no member named 'e'
   40 | int b=m(e1.e)+e1.no;
      |            ^
a.cc: At global scope:
a.cc:46:26: error: template argument 1 is invalid
   46 | std::set<unsigned __int64> memo[30];
      |                          ^
a.cc:46:26: error: template argument 2 is invalid
a.cc:46:26: error: template argument 3 is invalid
a.cc:47:30: error: wrong number of template arguments (1, should be at least 2)
   47 | std::map<unsigned __int64,int> memo3;
      |                              ^
/usr/include/c++/14/bits/stl_map.h:102:11: note: provided for 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:48:28: error: expected ',' or '...' before 'e'
   48 | void move(unsigned __int64 e,std::map<unsigned __int64,int>& m0,std::set<unsigned __int64>& m2)  {
      |                            ^
a.cc: In function 'void move(unsigned int)':
a.cc:49:21: error: expected initializer before 's'
   49 |    unsigned __int64 s=15;
      |                     ^
a.cc:54:16: error: 's' was not declared in this scope
   54 |            if((s&e)==0){
      |                ^
a.cc:54:18: error: 'e' was not declared in this scope
   54 |            if((s&e)==0){
      |                  ^
a.cc:58:12: error: 's' was not declared in this scope
   58 |            s=(s<<4);
      |            ^
a.cc:62:21: error: expected initializer before 'e2'
   62 |    unsigned __int64 e2;
      |                     ^~
a.cc:63:21: error: expected initializer before 'p1'
   63 |    unsigned __int64 p1;
      |                     ^~
a.cc:65:8: error: 'p1' was not declared in this scope
   65 |        p1=((s<<16)&e);
      |        ^~
a.cc:65:13: error: 's' was not declared in this scope
   65 |        p1=((s<<16)&e);
      |             ^
a.cc:65:20: error: 'e' was not declared in this scope
   65 |        p1=((s<<16)&e);
      |                    ^
a.cc:66:8: error: 'e2' was not declared in this scope
   66 |        e2=(e|(p1>>16))^p1;
      |        ^~
a.cc:67:11: error: 'm0' was not declared in this scope; did you mean 'm'?
   67 |        if(m0.find(e2)==m0.end()){
      |           ^~
      |           m
a.cc:68:12: error: 'm2' was not declared in this scope; did you mean 'm'?
   68 |            m2.insert(e2);
      |            ^~
      |            m
a.cc:72:8: error: 'p1' was not declared in this scope
   72 |        p1=((s>>16)&e);
      |        ^~
a.cc:72:13: error: 's' was not declared in this scope
   72 |        p1=((s>>16)&e);
      |             ^
a.cc:72:20: error: 'e' was not declared in this scope
   72 |        p1=((s>>16)&e);
      |                    ^
a.cc:73:8: error: 'e2' was not declared in this scope
   73 |        e2=(e|(p1<<16))^p1;
      |        ^~
a.cc:74:11: error: 'm0' was not declared in this scope; did you mean 'm'?
   74 |        if(m0.find(e2)==m0.end()){
      |           ^~
      |           m
a.cc:75:12: error: 'm2' was not declared in this scope; did you mean 'm'?
   75 |            m2.insert(e2);
      |            ^~
      |            m
a.cc:79:8: error: 'p1' was not declared in this scope
   79 |        p1=((s<<4)&e);
      |        ^~
a.cc:79:13: error: 's' was not declared in this scope
   79 |        p1=((s<<4)&e);
      |             ^
a.cc:79:19: error: 'e' was not declared in this scope
   79 |        p1=((s<<4)&e);
      |                   ^
a.cc:80:8: error: 'e2' was not declared in this scope
   80 |        e2=(e|(p1>>4))^p1;
      |        ^~
a.cc:81:11: error: 'm0' was not declared in this scope; did you mean 'm'?
   81 |        if(m0.find(e2)==m0.end()){
      |           ^~
      |           m
a.cc:82:16: error: 'm2' was not declared in this scope; did you mean 'm'?
   82 |                m2.insert(e2);
      |                ^~
      |                m
a.cc:86:8: error: 'p1' was not declared in this scope
   86 |        p1=((s>>4)&e);
      |        ^~
a.cc:86:13: error: 's' was not declared in this scope
   86 |        p1=((s>>4)&e);
      |             ^
a.cc:86:19: error: 'e' was not declared in this scope
   86 |        p1=((s>>4)&e);
      |                   ^
a.cc:87:8: error: 'e2' was not declared in this scope
   87 |        e2=(e|(p1<<4))^p1;
      |        ^~
a.cc:88:11: error: 'm0' was not declared in this scope; did you mean 'm'?
   88 |        if(m0.find(e2)==m0.end()){
      |           ^~
      |           m
a.cc:89:12: error: 'm2' was not declared in this scope; did you mean 'm'?
   89 |            m2.insert(e2);
      |            ^~
      |            m
a.cc: In function 'int main()':
a.cc:96:21: error: expected initializer before 'seed'
   96 |    unsigned __int64 seed=0,j=4;
      |                     ^~~~
a.cc:97:24: error: expected ';' before 'i'
   97 |    for(unsigned __int64 i=15;i>=1;i--){
      |                        ^~
      |                        ;
a.cc:97:25: error: 'i' was not declared in this scope
   97 |    for(unsigned __int64 i=15;i>=1;i--){
      |                         ^
a.cc:97:34: error: expected ')' before ';' token
   97 |    for(unsigned __int64 i=15;i>=1;i--){
      |       ~                          ^
      |                                  )
a.cc:97:35: error: 'i' was not declared in this scope
   97 |    for(unsigned __int64 i=15;i>=1;i--){
      |                                   ^
a.cc:101:12: error: request for member 'insert' in 'memo[0]', which is of non-class type 'int'
  101 |    memo[0].insert(seed);
      |            ^~~~~~
a.cc:101:19: error: 'seed' was not declared in this scope
  101 |    memo[0].insert(seed);
      |                   ^~~~
a.cc:103:29: error: template argument 1 is invalid
  103 |    std::set<unsigned __int64>::iterator it;
      |                             ^
a.cc:103:29: error: template argument 2 is invalid
a.cc:103:29: error: template argument 3 is invalid
a.cc:103:41: error: qualified-id in declaration before 'it'
  103 |    std::set<unsigned __int64>::iterator it;
      |                                         ^~
a.cc:105:12: error: 'it' was not declared in this scope; did you mean 'i'?
  105 |        for(it=memo[i].begin();it!=memo[i].end();it++){
      |            ^~
      |            i
a.cc:105:23: error: request for member 'begin' in 'memo[i]', which is of non-class type 'int'
  105 |        for(it=memo[i].begin();it!=memo[i].end();it++){
      |                       ^~~~~
a.cc:105:43: error: request for member 'end' in 'memo[i]', which is of non-class type 'int'
  105 |        for(it=memo[i].begin();it!=memo[i].end();it++){
      |                                           ^~~
a.cc:113:12: error: 'it' was not declared in this scope; did you mean 'i'?
  113 |        for(it=memo[i+1].begin();it!=memo[i+1].end();it++){
      |            ^~
      |            i
a.cc:113:25: error: request for member 'begin' in 'memo[(i + 1)]', which is of non-class type 'int'
  113 |        for(it=memo[i+1].begin();it!=memo[i+1].end();it++){
      |                         ^~~~~
a.cc:113:47: error: request for member 'end' in 'memo[(i + 1)]', which is of non-class type 'int'
  113 |        for(it=memo[i+1].begin();it!=memo[i+1].end();it++){
      |                                               ^~~
a.cc:116:18: error: request for member 'clear' in 'memo[(i - 1)]', which is of non-class type 'int'
  116 | if(i>1)memo[i-1].clear();
      |                  ^~~~~
a.cc:119:21: error: expected initializer before 'p'
  119 |    unsigned __int64 p=0;
      |                     ^
a.cc:120:21: error: expected initializer before 'n'
  120 |    unsigned __int64 n=0;
      |                     ^
a.cc:123:18: error: 'n' was not declared in this scope
  123 |        std::cin>>n;
      |                  ^
a.cc:124:8: error: 'p' was not declared in this scope
  124 |        p=(p|(n<<slide));
      |        ^
a.cc:128:7: error: 'struct E' has no member named 'e'
  128 |    e3.e=p;
      |       ^
a.cc:128:9: error: 'p' was not declared in this scope; did you mean 'pq'?
  128 |    e3.e=p;
      |         ^
      |         pq
a.cc:136:17: error: request for member 'find' in 'memo2', which is of non-class type 'int'
  136 |        if(memo2.find(e3.e)!=memo2.end()){
      |                 ^~~~
a.cc:136:25: error: 'struct E' has no member named 'e'
  136 |        if(memo2.find(e3.e)!=memo2.end()){
      |                         ^
a.cc:136:35: error: request for member 'end' in 'memo2', which is of non-class type 'int'
  136 |        if(memo2.find(e3.e)!=memo2.end()){
      |                                   ^~~
a.cc:137:34: error: 'struct E' has no member named 'e'
  137 |            ans=std::min(memo2[e3.e]+e3.no,ans);
      |                                  ^
a.cc:140:17: error: request for member 'find' in 'memo3', which is of non-class type 'int'
  140 |        if(memo3.f