結果

問題 No.340 雪の足跡
ユーザー simansiman
提出日時 2016-03-30 01:01:12
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,680 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 86,056 KB
実行使用メモリ 73,808 KB
最終ジャッジ日時 2024-04-10 00:18:16
合計ジャッジ時間 13,510 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
26,708 KB
testcase_01 AC 8 ms
26,832 KB
testcase_02 AC 8 ms
26,832 KB
testcase_03 AC 7 ms
26,956 KB
testcase_04 AC 7 ms
26,832 KB
testcase_05 AC 10 ms
26,960 KB
testcase_06 AC 8 ms
26,832 KB
testcase_07 AC 8 ms
26,832 KB
testcase_08 AC 8 ms
26,832 KB
testcase_09 AC 8 ms
26,832 KB
testcase_10 AC 8 ms
26,960 KB
testcase_11 AC 10 ms
26,960 KB
testcase_12 AC 9 ms
26,956 KB
testcase_13 AC 11 ms
26,960 KB
testcase_14 AC 62 ms
30,292 KB
testcase_15 AC 69 ms
30,412 KB
testcase_16 AC 42 ms
28,496 KB
testcase_17 AC 89 ms
31,052 KB
testcase_18 AC 84 ms
30,928 KB
testcase_19 AC 82 ms
31,052 KB
testcase_20 AC 414 ms
36,044 KB
testcase_21 AC 196 ms
26,828 KB
testcase_22 AC 15 ms
26,832 KB
testcase_23 AC 650 ms
73,808 KB
testcase_24 AC 289 ms
27,220 KB
testcase_25 AC 361 ms
32,080 KB
testcase_26 AC 57 ms
27,340 KB
testcase_27 AC 17 ms
26,832 KB
testcase_28 AC 69 ms
28,880 KB
testcase_29 AC 760 ms
54,092 KB
testcase_30 AC 540 ms
47,696 KB
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

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;
  }
};

int field[MAX_H][MAX_W][2];
int walking[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){
    field[fromY][fromX][0]++;
    field[toY][toX][0]--;
  }else if(fromX < toX){
    field[fromY][fromX][1]++;
    field[toY][toX][1]--;
  }else if(fromY > toY){
    field[fromY][fromX][0]--;
    field[toY][toX][0]++;
  }else{
    field[fromY][fromX][1]--;
    field[toY][toX][1]++;
  }
}

void cleanField(){
  int values[w];
  memset(values, 0, sizeof(values));

  for(int y = 0; y < h; y++){
    for(int x = 0; x < w; x++){
      if(y > 0 && values[x] > 0){
        walking[y-1][x][3] = true;
        walking[y][x][0] = true;
      }

      values[x] += field[y][x][0];
    }
  }

  memset(values, 0, sizeof(values));

  for(int x = 0; x < w; x++){
    for(int y = 0; y < h; y++){
      if(x > 0 && values[y] > 0){
        walking[y][x-1][2] = true;
        walking[y][x][1] = true;
      }

      values[y] += field[y][x][1];
    }
  }
}

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

  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);
      }
    }
  }

  cleanField();

  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(walking[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