結果
問題 | No.340 雪の足跡 |
ユーザー | n_knuu |
提出日時 | 2016-02-07 11:28:13 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,855 bytes |
コンパイル時間 | 1,451 ms |
コンパイル使用メモリ | 166,392 KB |
実行使用メモリ | 88,220 KB |
最終ジャッジ日時 | 2024-09-21 21:28:41 |
合計ジャッジ時間 | 7,897 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 12 ms
27,136 KB |
testcase_03 | WA | - |
testcase_04 | AC | 11 ms
26,880 KB |
testcase_05 | AC | 11 ms
27,136 KB |
testcase_06 | WA | - |
testcase_07 | AC | 11 ms
26,880 KB |
testcase_08 | AC | 11 ms
26,880 KB |
testcase_09 | WA | - |
testcase_10 | AC | 11 ms
26,752 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 23 ms
34,688 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 212 ms
49,664 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:86:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 86 | scanf("%d%d%d", &W, &H, &N); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:89:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 89 | int M, prev; scanf("%d%d", &M, &prev); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:91:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 91 | int b; scanf("%d", &b); | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<int> Vi; //typedef tuple<int, int, int> T; #define FOR(i,s,x) for(int i=s;i<(int)(x);i++) #define REP(i,x) FOR(i,0,x) #define ALL(c) c.begin(), c.end() #define DUMP( x ) cerr << #x << " = " << ( x ) << endl const int dr[4] = {-1, 0, 1, 0}; const int dc[4] = {0, 1, 0, -1}; #define INF 1000010 // graph by adjacency list struct Edge { int dst, weight; Edge(int dst, int weight) : dst(dst), weight(weight) { } bool operator < (const Edge &e) const { return weight > e.weight; } }; vector<Edge> E[1000010]; struct Graph { int V; Graph(int V) : V(V) { } void add_edge(int src, int dst, int weight) { E[src].push_back(Edge(dst, weight)); } }; struct Node { int v, dist; Node(int v, int dist) : v(v), dist(dist) { }; bool operator < (const Node &n) const { return dist > n.dist; // reverse } }; int dist[1000010]; struct ShortestPath { const Graph g; int start; ShortestPath(const Graph g, int start) : g(g), start(start) { } void dijkstra(int goal) { std::priority_queue<Node> que; dist[start] = 0; que.push(Node(start, 0)); while (!que.empty()) { Node n = que.top(); que.pop(); int v = n.v, cost = n.dist; if (v == goal) return ; if (dist[v] < cost) continue; for (Edge e : E[v]) { if ((v and not dist[v]) or dist[v] + e.weight < dist[e.dst]) { dist[e.dst] = dist[v] + e.weight; if (e.dst == goal) return ; que.push(Node(e.dst, dist[e.dst])); } } } } }; int imos_w[1000010], imos_h[1000010]; int main() { int W, H, N; scanf("%d%d%d", &W, &H, &N); REP(i, N) { int M, prev; scanf("%d%d", &M, &prev); REP(i, M) { int b; scanf("%d", &b); int p1 = prev, p2 = b; if (p1 > p2) swap(p1, p2); int r1 = p1 / W, c1 = p1 % W, r2 = p2 / W, c2 = p2 % W; //cout << '(' << r1 << ',' << c1 << ')' << ' ' << '(' << r2 << ',' << c2 << ')' << endl; if (r1 == r2) { imos_w[p1]++, imos_w[p2]--; } else if (c1 == c2) { imos_h[c1 * H + r1]++, imos_h[c2 * H + r2]--; } prev = b; } } REP(i, W*H-1) imos_h[i+1] += imos_h[i], imos_w[i+1] += imos_w[i]; Graph g(H*W); REP(i, H*W) { if (imos_w[i]) g.add_edge(i, i+1, 1), g.add_edge(i+1, i, 1); if (imos_h[i]) { int p1 = (i%H)*W+i/H, p2 = p1 + W; g.add_edge(p1, p2, 1), g.add_edge(p2, p1, 1); } } /*REP(i, W*H) { cout << i << ':'; for (auto v : g.E[i]) cout << v.dst << ' '; cout << endl; }*/ ShortestPath sp(g, 0); sp.dijkstra(W*H-1); if (W*H-1 and not dist[W*H-1]) { printf("Odekakedekinai..\n"); } else { printf("%d\n", dist[W*H-1]); } //REP(i, g.V) cout << sp.dist[i] << (i == g.V-1 ? '\n' : ' '); return 0; }