Submission #2554764


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef pair<int,int> pii;

const int h = 19, w = 15;
char mp[20][20];
int n;
int bpos[20];

unordered_map<int,int> dist[1<<20];

int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};

int main(){
  REP(i,h)scanf("%s",mp[i]);
  n = 0;
  int wpos = -1;
  REP(i,h)REP(j,w){
    if(mp[i][j]=='O'){
      wpos = (i<<5) + j;
    }else if(mp[i][j]=='X'){
      bpos[n++] = (i<<5) + j;
    }
  }
  queue<int> Q;
  dist[0][wpos] = 0;
  Q.push((0<<10) + wpos);
  while(!Q.empty()){
    int mask = Q.front() >> 10;
    int pos = Q.front() & 1023;
    Q.pop();
    int wy = pos>>5;
    int wx = pos&31;
    // printf("%d, %d, %d\n", wy, wx, mask);
    int dst = dist[mask][pos];
    // 8 way
    REP(d,8){
      int cy = wy, cx = wx;
      int add = 0;
      while(true){
        int ny = cy + dy[d], nx = cx + dx[d];
        int pp = (ny<<5) + nx;
        if(nx<0 || ny<0 || nx>=w || ny>=h){
          cy = ny;
          cx = nx;
          break;
        }
        // exist check
        bool ok = false;
        REP(i,n)if(bpos[i]==pp && ((mask>>i)&1)==0){
          ok = true;
          add |= (1<<i);
          break;
        }
        cy = ny;
        cx = nx;
        if(!ok)break;
      }
      if(add==0)continue;
      if((cy>h-1) || (cy==h-1 && (0<=cy || cy<w))){
        // goal
        printf("%d\n",dst+1);
        return 0;
      }
      if(cy<0 || cx<0 || cx>=w)continue;
      int nmsk = mask | add;
      int pos = (cy<<5) | cx;
      if(dist[nmsk].count(pos)==0){
        dist[nmsk][pos] = dst+1;
        Q.push((nmsk<<10) + pos);
      }
    }
  }
  puts("-1");
  return 0;
}

Submission Info

Submission Time
Task F - Phutball
User rickytheta
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1767 Byte
Status WA
Exec Time 66 ms
Memory 62848 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   REP(i,h)scanf("%s",mp[i]);
                            ^

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 92
WA × 1
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 27 ms 57600 KB
00-sample2.txt AC 27 ms 57600 KB
00-sample3.txt AC 27 ms 57600 KB
00-sample4.txt AC 27 ms 57600 KB
00-sample5.txt AC 27 ms 57600 KB
00-sample6.txt AC 27 ms 57600 KB
random-000.txt AC 27 ms 57600 KB
random-001.txt AC 27 ms 57600 KB
random-002.txt AC 27 ms 57600 KB
random-003.txt AC 27 ms 57600 KB
random-004.txt AC 27 ms 57600 KB
random-005.txt AC 27 ms 57600 KB
random-006.txt AC 27 ms 57600 KB
random-007.txt AC 27 ms 57600 KB
random-008.txt AC 27 ms 57600 KB
random-009.txt AC 27 ms 57600 KB
random-010.txt AC 27 ms 57600 KB
random-011.txt AC 27 ms 57600 KB
random-012.txt AC 27 ms 57600 KB
random-013.txt AC 27 ms 57600 KB
random-014.txt AC 27 ms 57600 KB
random-015.txt AC 27 ms 57600 KB
random-016.txt AC 27 ms 57600 KB
random-017.txt AC 27 ms 57600 KB
random-018.txt AC 27 ms 57600 KB
random-019.txt AC 27 ms 57600 KB
random-020.txt AC 27 ms 57600 KB
random-021.txt AC 27 ms 57600 KB
random-022.txt AC 27 ms 57600 KB
random-023.txt AC 27 ms 57600 KB
random-024.txt AC 27 ms 57600 KB
random-025.txt AC 27 ms 57600 KB
random-026.txt AC 27 ms 57600 KB
random-027.txt AC 27 ms 57600 KB
random-028.txt AC 27 ms 57600 KB
random-029.txt AC 27 ms 57600 KB
random-030.txt AC 27 ms 57600 KB
random-031.txt AC 27 ms 57600 KB
random-032.txt WA 27 ms 57600 KB
random-033.txt AC 27 ms 57600 KB
random-034.txt AC 27 ms 57600 KB
random-035.txt AC 27 ms 57600 KB
random-036.txt AC 27 ms 57600 KB
random-037.txt AC 27 ms 57600 KB
random-038.txt AC 27 ms 57600 KB
random-039.txt AC 27 ms 57600 KB
random-040.txt AC 27 ms 57600 KB
random-041.txt AC 27 ms 57600 KB
random-042.txt AC 27 ms 57600 KB
random-043.txt AC 27 ms 57600 KB
random-044.txt AC 27 ms 57600 KB
random-045.txt AC 27 ms 57600 KB
random-046.txt AC 27 ms 57600 KB
random-047.txt AC 27 ms 57600 KB
random-048.txt AC 27 ms 57600 KB
random-049.txt AC 27 ms 57600 KB
random-050.txt AC 27 ms 57600 KB
random-051.txt AC 27 ms 57600 KB
random-052.txt AC 27 ms 57600 KB
random-053.txt AC 27 ms 57600 KB
random-054.txt AC 27 ms 57600 KB
random-055.txt AC 27 ms 57600 KB
random-056.txt AC 27 ms 57600 KB
random-057.txt AC 27 ms 57600 KB
random-058.txt AC 27 ms 57600 KB
random-059.txt AC 27 ms 57600 KB
random-060.txt AC 27 ms 57600 KB
random-061.txt AC 27 ms 57600 KB
random-062.txt AC 27 ms 57600 KB
random-063.txt AC 27 ms 57600 KB
random-064.txt AC 27 ms 57600 KB
random-065.txt AC 27 ms 57600 KB
random-066.txt AC 27 ms 57600 KB
random-067.txt AC 27 ms 57600 KB
random-068.txt AC 27 ms 57600 KB
random-069.txt AC 27 ms 57600 KB
random-070.txt AC 27 ms 57600 KB
random-071.txt AC 27 ms 57600 KB
random-072.txt AC 27 ms 57600 KB
random-073.txt AC 27 ms 57600 KB
random-074.txt AC 27 ms 57600 KB
random-075.txt AC 27 ms 57600 KB
random-076.txt AC 27 ms 57600 KB
random-077.txt AC 27 ms 57600 KB
random-078.txt AC 27 ms 57600 KB
random-079.txt AC 27 ms 57600 KB
test01.txt AC 27 ms 57600 KB
test02.txt AC 29 ms 57984 KB
test03.txt AC 32 ms 58240 KB
test04.txt AC 66 ms 62848 KB
test05.txt AC 66 ms 62848 KB
test06.txt AC 27 ms 57600 KB
test07.txt AC 27 ms 57600 KB