提出 #14369162


ソースコード 拡げる

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int H, W, K, sx, sy, tx, ty;
string c[1010101];
int mi[1010101];
bool vis[1010101];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W >> K >> sx >> sy >> tx >> ty;
	rep(y, 0, H) cin >> c[y];
	sx--; sy--; tx--; ty--;

	queue<int> que;
	rep(i, 0, 1010101) mi[i] = inf;

	que.push(sx * W + sy);
	vis[sx * W + sy] = true;
	mi[sx * W + sy] = 0;

	while (!que.empty()) {
		int q = que.front(); que.pop();

		int x = q / W;
		int y = q % W;

		if (x == tx && y == ty) {
			printf("%d\n", mi[q]);
			return;
		}

		rep(d, 0, 4) {
			int xx = x, yy = y;
			rep(k, 0, K) {
				xx += dx[d];
				yy += dy[d];

				if (xx < 0 || H <= xx || yy < 0 || W <= yy) break;
				if (c[xx][yy] == '@') break;
				
				int id = xx * W + yy;
				if (vis[id] && mi[q] + 1 != mi[id]) break;

				if (!vis[id]) {
					vis[id] = true;
					mi[id] = mi[q] + 1;
					que.push(id);
				}
			}
		}
	}

	printf("-1\n");
}





提出情報

提出日時
問題 F - Pond Skater
ユーザ hamayanhamayan
言語 C++ (GCC 9.2.1)
得点 600
コード長 2363 Byte
結果 AC
実行時間 56 ms
メモリ 41388 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 32
セット名 テストケース
Sample Sample_01.txt, Sample_02.txt, Sample_03.txt
All Sample_01.txt, Sample_02.txt, Sample_03.txt, killer_01.txt, killer_02.txt, killer_03.txt, killer_04.txt, killer_05.txt, ng_large_01.txt, ng_large_02.txt, ng_large_03.txt, ng_small_01.txt, ng_small_02.txt, ng_small_03.txt, path_01.txt, path_02.txt, path_03.txt, path_04.txt, path_05.txt, rand_1000_01.txt, rand_1000_02.txt, rand_1000_03.txt, rand_20_01.txt, rand_20_02.txt, rand_20_03.txt, rand_300_01.txt, rand_300_02.txt, rand_300_03.txt, rand_small_01.txt, rand_small_02.txt, rand_small_03.txt, superkiller_01.txt
ケース名 結果 実行時間 メモリ
Sample_01.txt AC 28 ms 39116 KiB
Sample_02.txt AC 28 ms 39060 KiB
Sample_03.txt AC 27 ms 38996 KiB
killer_01.txt AC 39 ms 41352 KiB
killer_02.txt AC 41 ms 41296 KiB
killer_03.txt AC 34 ms 40964 KiB
killer_04.txt AC 40 ms 41388 KiB
killer_05.txt AC 29 ms 40548 KiB
ng_large_01.txt AC 27 ms 40032 KiB
ng_large_02.txt AC 29 ms 40028 KiB
ng_large_03.txt AC 28 ms 39984 KiB
ng_small_01.txt AC 27 ms 39076 KiB
ng_small_02.txt AC 29 ms 39044 KiB
ng_small_03.txt AC 26 ms 38992 KiB
path_01.txt AC 27 ms 39640 KiB
path_02.txt AC 31 ms 39728 KiB
path_03.txt AC 34 ms 40100 KiB
path_04.txt AC 34 ms 39976 KiB
path_05.txt AC 47 ms 40488 KiB
rand_1000_01.txt AC 42 ms 40760 KiB
rand_1000_02.txt AC 43 ms 40952 KiB
rand_1000_03.txt AC 54 ms 40852 KiB
rand_20_01.txt AC 50 ms 40980 KiB
rand_20_02.txt AC 28 ms 40284 KiB
rand_20_03.txt AC 47 ms 40960 KiB
rand_300_01.txt AC 56 ms 40984 KiB
rand_300_02.txt AC 53 ms 40916 KiB
rand_300_03.txt AC 53 ms 40904 KiB
rand_small_01.txt AC 30 ms 39116 KiB
rand_small_02.txt AC 28 ms 39168 KiB
rand_small_03.txt AC 27 ms 39160 KiB
superkiller_01.txt AC 32 ms 40316 KiB