結果
問題 |
No.2928 Gridpath
|
ユーザー |
![]() |
提出日時 | 2024-10-14 15:20:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,354 bytes |
コンパイル時間 | 652 ms |
コンパイル使用メモリ | 57,224 KB |
最終ジャッジ日時 | 2025-02-24 19:31:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d%d%d%d%d%d", &h, &w, &sy, &sx, &gy, &gx); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2928.cc: No.2928 Gridpath - yukicoder */ #include<cstdio> #include<vector> #include<algorithm> using namespace std; /* constant */ const int MAX_H = 6; const int MAX_W = 6; const int MAX_N = MAX_H * MAX_W; /* typedef */ using vi = vector<int>; /* global variables */ vi nbrs[MAX_N]; int ps[MAX_N], cis[MAX_N], cs[MAX_N]; bool used[MAX_N]; /* subroutines */ /* main */ int main() { int h, w, sy, sx, gy, gx; scanf("%d%d%d%d%d%d", &h, &w, &sy, &sx, &gy, &gx); sy--, sx--, gy--, gx--; int hw = h * w, st = sy * w + sx, gl = gy * w + gx; for (int y = 0, u = 0; y < h; y++) for (int x = 0; x < w; x++, u++) { if (y + 1 < h) nbrs[u].push_back(u + w), nbrs[u + w].push_back(u); if (x + 1 < w) nbrs[u].push_back(u + 1), nbrs[u + 1].push_back(u); } ps[st] = -1; used[st] = true; for (auto v: nbrs[st]) cs[v]++; int cnt = 0; for (int u = st; u >= 0;) { auto &nbru = nbrs[u]; int up = ps[u]; if (u != gl && cis[u] < nbru.size()) { int v = nbru[cis[u]++]; if (! used[v] && cs[v] <= 1) { ps[v] = u; used[v] = true; for (auto w: nbrs[v]) cs[w]++; u = v; } } else { if (u == gl) cnt++; cis[u] = 0; used[u] = false; for (auto v: nbrs[u]) cs[v]--; u = up; } } printf("%d\n", cnt); return 0; }