結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,116 KB
testcase_01 AC 6 ms
15,240 KB
testcase_02 AC 6 ms
15,168 KB
testcase_03 AC 6 ms
15,244 KB
testcase_04 AC 6 ms
15,112 KB
testcase_05 AC 6 ms
15,240 KB
testcase_06 AC 6 ms
15,112 KB
testcase_07 AC 5 ms
15,108 KB
testcase_08 AC 5 ms
15,240 KB
testcase_09 AC 6 ms
15,244 KB
testcase_10 AC 6 ms
15,240 KB
testcase_11 AC 7 ms
15,368 KB
testcase_12 AC 7 ms
15,368 KB
testcase_13 AC 9 ms
15,364 KB
testcase_14 AC 58 ms
18,700 KB
testcase_15 AC 62 ms
18,696 KB
testcase_16 AC 32 ms
16,904 KB
testcase_17 AC 74 ms
19,396 KB
testcase_18 AC 70 ms
19,588 KB
testcase_19 AC 73 ms
19,460 KB
testcase_20 AC 248 ms
24,328 KB
testcase_21 AC 103 ms
15,172 KB
testcase_22 AC 8 ms
14,988 KB
testcase_23 AC 461 ms
61,960 KB
testcase_24 AC 124 ms
15,492 KB
testcase_25 AC 184 ms
20,484 KB
testcase_26 AC 33 ms
15,752 KB
testcase_27 AC 10 ms
15,176 KB
testcase_28 AC 50 ms
17,284 KB
testcase_29 AC 619 ms
42,504 KB
testcase_30 AC 452 ms
35,976 KB
testcase_31 AC 961 ms
58,052 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 980 ms
62,216 KB
testcase_36 AC 987 ms
62,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:96:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   96 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
main.cpp:103:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  103 |       scanf("%d", &p);
      |       ~~~~~^~~~~~~~~~

ソースコード

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];
bool 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 valuesW[w];
  int valuesH[h];
  memset(valuesW, 0, sizeof(valuesW));
  memset(valuesH, 0, sizeof(valuesH));

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

      valuesW[x] += field[y][x][0];
      valuesH[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;
    scanf("%d", &m);

    int bp = 0;
    int p = 0;

    for(int j = 0; j < m+1; j++){
      bp = p;
      scanf("%d", &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);
      break;
    }

    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