提出 #18364982


ソースコード 拡げる

#include <cctype>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
typedef std::pair<int, int> pii;
char grids[2010][2010];
int H, W;
const int x[] = {-1, 1, 0, 0}, y[] = {0, 0, -1, 1};
pii S, G, tmp;
std::vector<pii> teleporters[30];
std::queue<pii> Q;
int dist[2010][2010], vis[2010][2010], televis[30];
int main(int argc, char **argv) {
  scanf("%d%d", &H, &W);
  for (int i = 1; i <= H; ++i) {
    scanf("%s", grids[i] + 1);
    for (int j = 1; j <= W; ++j) {
      if (grids[i][j] == 'S')
        S = pii(i, j);
      else if (grids[i][j] == 'G')
        G = pii(i, j);
      else if (isalpha(grids[i][j]))
        teleporters[grids[i][j] - 'a'].insert(
            teleporters[grids[i][j] - 'a'].end(), pii(i, j));
      else if (grids[i][j] == '#')
        grids[i][j] = 0;
    }
  }
  Q.push(S);
  vis[S.first][S.second] = 1;
  dist[S.first][S.second] = 0;
  while (!Q.empty()) {
    tmp = Q.front(), Q.pop();
    if (tmp == G) {
      printf("%d", dist[G.first][G.second]);
      return 0;
    }
    for (int i = 0; i < 4; ++i) {
      if (grids[tmp.first + x[i]][tmp.second + y[i]] &&
          !vis[tmp.first + x[i]][tmp.second + y[i]]) {
        vis[tmp.first + x[i]][tmp.second + y[i]] = 1;
        Q.push(pii(tmp.first + x[i], tmp.second + y[i]));
        dist[tmp.first + x[i]][tmp.second + y[i]] =
            dist[tmp.first][tmp.second] + 1;
      }
    }
    if (islower(grids[tmp.first][tmp.second]) &&
        !televis[grids[tmp.first][tmp.second] - 'a']) {
      for (pii i : teleporters[grids[tmp.first][tmp.second] - 'a']) {
        if (i != tmp) {
          dist[i.first][i.second] = dist[tmp.first][tmp.second] + 1;
          vis[i.first][i.second] = 1;
          Q.push(i);
        }
      }
      televis[grids[tmp.first][tmp.second] - 'a'] = 1;
    }
  }
  printf("-1");
  return 0;
}

提出情報

提出日時
問題 E - Third Avenue
ユーザ Starduster
言語 C++ (GCC 9.2.1)
得点 0
コード長 1916 Byte
結果 WA
実行時間 170 ms
メモリ 42356 KiB

コンパイルエラー

./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:15:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
   15 | int main(int argc, char **argv) {
      |          ~~~~^~~~
./Main.cpp:15:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
   15 | int main(int argc, char **argv) {
      |                    ~~~~~~~^~~~
./Main.cpp:16:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   16 |   scanf("%d%d", &H, &W);
      |   ~~~~~^~~~~~~~~~~~~~~~
./Main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%s", grids[i] + 1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 500
結果
AC × 3
AC × 37
WA × 1
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 9 ms 3240 KiB
random_01.txt AC 2 ms 3140 KiB
random_02.txt AC 1 ms 3244 KiB
random_03.txt AC 2 ms 3364 KiB
random_04.txt AC 2 ms 3176 KiB
random_05.txt AC 3 ms 3304 KiB
random_06.txt AC 2 ms 3076 KiB
random_07.txt AC 2 ms 3348 KiB
random_08.txt AC 2 ms 3220 KiB
random_09.txt AC 2 ms 3184 KiB
random_10.txt AC 1 ms 3144 KiB
random_11.txt AC 2 ms 3260 KiB
random_12.txt AC 2 ms 3356 KiB
random_13.txt AC 2 ms 3400 KiB
random_14.txt AC 2 ms 3396 KiB
random_15.txt AC 4 ms 3364 KiB
random_16.txt AC 18 ms 11996 KiB
random_17.txt AC 78 ms 28952 KiB
random_18.txt AC 31 ms 12860 KiB
random_19.txt AC 15 ms 13432 KiB
random_20.txt AC 52 ms 24272 KiB
random_21.txt AC 6 ms 5436 KiB
random_22.txt AC 11 ms 6832 KiB
random_23.txt WA 48 ms 22980 KiB
random_24.txt AC 36 ms 15032 KiB
random_25.txt AC 23 ms 13720 KiB
random_26.txt AC 6 ms 3924 KiB
random_27.txt AC 33 ms 13072 KiB
random_28.txt AC 7 ms 5620 KiB
random_29.txt AC 2 ms 3508 KiB
random_30.txt AC 38 ms 27288 KiB
random_31.txt AC 139 ms 40856 KiB
random_32.txt AC 170 ms 42356 KiB
random_33.txt AC 148 ms 38556 KiB
random_34.txt AC 73 ms 30852 KiB
sample_01.txt AC 3 ms 3152 KiB
sample_02.txt AC 3 ms 3220 KiB
sample_03.txt AC 2 ms 3296 KiB