Submission #1187280


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
signed main(){
  string s[19];
  for(int i=0;i<19;i++) cin>>s[i];
 
  int sy,sx;
  vector<int> v;
  for(int i=0;i<19;i++){
    for(int j=0;j<15;j++){
      if(s[i][j]=='O') sy=i,sx=j;
      if(s[i][j]=='X') v.push_back(i*15+j);
    }
  }
   
  int n=v.size();
  int sb=(sy*15+sx)<<n;
   
  map<int,int> m;
  for(int i=0;i<n;i++) m[v[i]]=i;
 
  int ax[]={-1,-1,-1,0,0,1,1,1};
  int ay[]={-1,0,1,-1,1,-1,0,1};
   
  int ans=-1,mask=(1<<n)-1;
  priority_queue<P> q;
  q.push(P(0,sb));
  map<int,int> ms;
  ms[sb]=0;
   
  while(!q.empty()){
    P p=q.top();q.pop();
    int d=-p.first,b=p.second;
    int cy=(b>>n)/15,cx=(b>>n)%15;
    //cout<<(b>>n)<<" "<<cy<<" "<<cx<<" "<<d<<endl;
    if(ms[b]<d) continue;
    for(int k=0;k<8;k++){
      int ny=cy+ay[k],nx=cx+ax[k],nb=b&mask,nd=d+1;
      if(!m.count(ny*15+nx)) continue;
      //cout<<ny<<" "<<nx<<" "<<nb<<" "<<nd<<endl;
      if(nb&(1<<m[ny*15+nx])) continue;
      while(m.count(ny*15+nx)){
    if(nb&(1<<m[ny*15+nx])) break;
    //cout<<n<<":"<<m[ny*15+nx]<<" "<<nb<<" "<<(1<<m[ny*15+nx])<<endl;
    nb+=1<<m[ny*15+nx];
    ny+=ay[k];
    nx+=ax[k];
      }
      //cout<<ny<<" "<<nx<<" "<<ny*15+nx<<" "<<nb<<endl;
      if(ny==18&&0<=nx&&nx<15){
    ans=nd;
    goto END;
      }
      if(ny>18){
    ans=nd;
    goto END;
      }
      if(ny<0||nx<0||nx>=15) continue;
      nb+=(ny*15+nx)<<n;
      //cout<<nb<<" "<<(nb&mask)<<" "<<(nb>>n)<<endl;
      if(ms.count(nb)&&ms[nb]<=nd) continue;
      ms[nb]=nd;
      q.push(P(-nd,nb));
    }
  }
 END:
  cout<<ans<<endl;
  return 0;
}

Submission Info

Submission Time
Task F - Phutball
User beet
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1704 Byte
Status AC
Exec Time 70 ms
Memory 5752 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 93
Set Name Test Cases
All 00-sample1.txt, 00-sample2.txt, 00-sample3.txt, 00-sample4.txt, 00-sample5.txt, 00-sample6.txt, random-000.txt, random-001.txt, random-002.txt, random-003.txt, random-004.txt, random-005.txt, random-006.txt, random-007.txt, random-008.txt, random-009.txt, random-010.txt, random-011.txt, random-012.txt, random-013.txt, random-014.txt, random-015.txt, random-016.txt, random-017.txt, random-018.txt, random-019.txt, random-020.txt, random-021.txt, random-022.txt, random-023.txt, random-024.txt, random-025.txt, random-026.txt, random-027.txt, random-028.txt, random-029.txt, random-030.txt, random-031.txt, random-032.txt, random-033.txt, random-034.txt, random-035.txt, random-036.txt, random-037.txt, random-038.txt, random-039.txt, random-040.txt, random-041.txt, random-042.txt, random-043.txt, random-044.txt, random-045.txt, random-046.txt, random-047.txt, random-048.txt, random-049.txt, random-050.txt, random-051.txt, random-052.txt, random-053.txt, random-054.txt, random-055.txt, random-056.txt, random-057.txt, random-058.txt, random-059.txt, random-060.txt, random-061.txt, random-062.txt, random-063.txt, random-064.txt, random-065.txt, random-066.txt, random-067.txt, random-068.txt, random-069.txt, random-070.txt, random-071.txt, random-072.txt, random-073.txt, random-074.txt, random-075.txt, random-076.txt, random-077.txt, random-078.txt, random-079.txt, test01.txt, test02.txt, test03.txt, test04.txt, test05.txt, test06.txt, test07.txt
Case Name Status Exec Time Memory
00-sample1.txt AC 1 ms 256 KB
00-sample2.txt AC 1 ms 256 KB
00-sample3.txt AC 1 ms 256 KB
00-sample4.txt AC 1 ms 256 KB
00-sample5.txt AC 1 ms 256 KB
00-sample6.txt AC 1 ms 256 KB
random-000.txt AC 1 ms 256 KB
random-001.txt AC 1 ms 256 KB
random-002.txt AC 1 ms 256 KB
random-003.txt AC 1 ms 256 KB
random-004.txt AC 1 ms 256 KB
random-005.txt AC 1 ms 256 KB
random-006.txt AC 1 ms 256 KB
random-007.txt AC 1 ms 256 KB
random-008.txt AC 1 ms 256 KB
random-009.txt AC 1 ms 256 KB
random-010.txt AC 1 ms 256 KB
random-011.txt AC 1 ms 256 KB
random-012.txt AC 1 ms 256 KB
random-013.txt AC 1 ms 256 KB
random-014.txt AC 1 ms 256 KB
random-015.txt AC 1 ms 256 KB
random-016.txt AC 1 ms 256 KB
random-017.txt AC 1 ms 256 KB
random-018.txt AC 1 ms 256 KB
random-019.txt AC 1 ms 256 KB
random-020.txt AC 1 ms 256 KB
random-021.txt AC 1 ms 256 KB
random-022.txt AC 1 ms 256 KB
random-023.txt AC 1 ms 256 KB
random-024.txt AC 1 ms 256 KB
random-025.txt AC 1 ms 256 KB
random-026.txt AC 1 ms 256 KB
random-027.txt AC 1 ms 256 KB
random-028.txt AC 1 ms 256 KB
random-029.txt AC 1 ms 256 KB
random-030.txt AC 1 ms 256 KB
random-031.txt AC 1 ms 256 KB
random-032.txt AC 1 ms 256 KB
random-033.txt AC 1 ms 256 KB
random-034.txt AC 1 ms 256 KB
random-035.txt AC 1 ms 256 KB
random-036.txt AC 1 ms 256 KB
random-037.txt AC 1 ms 256 KB
random-038.txt AC 1 ms 256 KB
random-039.txt AC 1 ms 256 KB
random-040.txt AC 1 ms 256 KB
random-041.txt AC 1 ms 256 KB
random-042.txt AC 1 ms 256 KB
random-043.txt AC 1 ms 256 KB
random-044.txt AC 1 ms 256 KB
random-045.txt AC 1 ms 256 KB
random-046.txt AC 1 ms 256 KB
random-047.txt AC 1 ms 256 KB
random-048.txt AC 1 ms 256 KB
random-049.txt AC 1 ms 256 KB
random-050.txt AC 1 ms 256 KB
random-051.txt AC 1 ms 256 KB
random-052.txt AC 1 ms 256 KB
random-053.txt AC 1 ms 256 KB
random-054.txt AC 1 ms 256 KB
random-055.txt AC 1 ms 256 KB
random-056.txt AC 1 ms 256 KB
random-057.txt AC 1 ms 256 KB
random-058.txt AC 1 ms 256 KB
random-059.txt AC 1 ms 256 KB
random-060.txt AC 1 ms 256 KB
random-061.txt AC 1 ms 256 KB
random-062.txt AC 1 ms 256 KB
random-063.txt AC 1 ms 256 KB
random-064.txt AC 1 ms 256 KB
random-065.txt AC 1 ms 256 KB
random-066.txt AC 1 ms 256 KB
random-067.txt AC 1 ms 256 KB
random-068.txt AC 1 ms 256 KB
random-069.txt AC 1 ms 256 KB
random-070.txt AC 1 ms 256 KB
random-071.txt AC 1 ms 256 KB
random-072.txt AC 1 ms 256 KB
random-073.txt AC 1 ms 256 KB
random-074.txt AC 1 ms 256 KB
random-075.txt AC 1 ms 256 KB
random-076.txt AC 1 ms 256 KB
random-077.txt AC 1 ms 256 KB
random-078.txt AC 1 ms 256 KB
random-079.txt AC 1 ms 256 KB
test01.txt AC 1 ms 256 KB
test02.txt AC 5 ms 640 KB
test03.txt AC 10 ms 1024 KB
test04.txt AC 69 ms 5752 KB
test05.txt AC 70 ms 5752 KB
test06.txt AC 1 ms 256 KB
test07.txt AC 1 ms 256 KB