結果

問題 No.340 雪の足跡
ユーザー simansiman
提出日時 2016-03-30 00:09:54
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,268 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 85,528 KB
実行使用メモリ 54,216 KB
最終ジャッジ日時 2024-04-10 00:13:06
合計ジャッジ時間 21,460 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
14,460 KB
testcase_01 AC 4 ms
7,196 KB
testcase_02 AC 3 ms
7,200 KB
testcase_03 AC 4 ms
7,232 KB
testcase_04 AC 4 ms
7,424 KB
testcase_05 AC 4 ms
7,284 KB
testcase_06 AC 3 ms
7,280 KB
testcase_07 AC 3 ms
7,228 KB
testcase_08 AC 4 ms
7,084 KB
testcase_09 AC 4 ms
7,204 KB
testcase_10 AC 4 ms
7,312 KB
testcase_11 AC 6 ms
7,280 KB
testcase_12 AC 5 ms
7,476 KB
testcase_13 AC 7 ms
7,504 KB
testcase_14 AC 69 ms
10,756 KB
testcase_15 AC 78 ms
10,856 KB
testcase_16 AC 43 ms
9,088 KB
testcase_17 AC 97 ms
11,360 KB
testcase_18 AC 87 ms
11,380 KB
testcase_19 AC 97 ms
11,632 KB
testcase_20 TLE -
testcase_21 AC 952 ms
7,240 KB
testcase_22 AC 3 ms
7,292 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 995 ms
12,420 KB
testcase_26 AC 70 ms
7,772 KB
testcase_27 AC 13 ms
7,156 KB
testcase_28 AC 84 ms
9,404 KB
testcase_29 TLE -
testcase_30 AC 742 ms
28,084 KB
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>
#include <time.h>
#include <string>
#include <string.h>
#include <sstream>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

const int MAX_H = 1000;
const int MAX_W = 1000;

const int DY[4] = {-1, 0, 0, 1};
const int DX[4] = { 0,-1, 1, 0};

struct Coord {
  int y;
  int x;
  int dist;

  Coord(int y, int x, int dist){
    this->y = y;
    this->x = x;
    this->dist = dist;
  }
};

bool field[MAX_H][MAX_W][4];

int w, h, n;

void walk(int from, int to){
  int fromY = from/w;
  int fromX = from%w;
  int toY = to/w;
  int toX = to%w;

  if(fromY < toY){
    for(int y = fromY+1; y <= toY; y++){
      field[y-1][fromX][3] = true;
      field[y][toX][0] = true;
    }
  }else if(fromX < toX){
    for(int x = fromX+1; x <= toX; x++){
      field[fromY][x-1][2] = true;
      field[toY][x][1] = true;
    }
  }else if(fromY > toY){
    for(int y = toY+1; y <= fromY; y++){
      field[y][fromX][0] = true;
      field[y-1][toX][3] = true;
    }
  }else{
    for(int x = toX+1; x <= fromX; x++){
      field[fromY][x][1] = true;
      field[toY][x-1][2] = true;
    }
  }
}

int main(){
  memset(field, false, sizeof(field));

  cin >> w >> h >> n;

  for(int i = 0; i < n; i++){
    int m;
    cin >> m;

    int bp = 0;
    int p = 0;

    for(int j = 0; j < m+1; j++){
      bp = p;
      cin >> p;

      if(j > 0){
        walk(bp, p);
      }
    }
  }

  queue<Coord> que;
  que.push(Coord(0, 0, 0));

  int minDist = INT_MAX;

  map<int, bool> checkList;

  while(!que.empty()){
    Coord coord = que.front(); que.pop();
    int z = coord.y * w + coord.x;

    if(checkList[z]) continue;
    checkList[z] = true;

    if(h*w-1 == z){
      minDist = min(minDist, coord.dist);
    }

    for(int i = 0; i < 4; i++){
      int ny = coord.y + DY[i];
      int nx = coord.x + DX[i];

      if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
      if(field[coord.y][coord.x][i]){
        que.push(Coord(ny, nx, coord.dist+1));
      }
    }
  }

  if (minDist == INT_MAX){
    cout << "Odekakedekinai.." << endl;
  }else{
    cout << minDist << endl;
  }

  return 0;
}
0