提出 #103216
ソースコード 拡げる
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
int W, H, N;
int R[512][512], D[512][512];
int xs, ys, xe, ye;
char P[1024], S[1024];
int dist[512][512];
struct state {
int x, y, s;
state(int x, int y, int s) : x(x), y(y), s(s) { }
};
bool operator < (const state& a, const state& b) {
return a.s > b.s;
}
inline int cost(int x1, int y1, int x2, int y2)
{
if (x1 != x2) {
return R[min(x1, x2)][y1];
} else {
return D[x1][min(y1, y2)];
}
}
int main()
{
scanf("%d%d%d", &W, &H, &N);
scanf("%d%d%d%d", &xs, &ys, &xe, &ye);
for (int i = 0; i < N; ++i) {
int x, y, T = 0;
scanf("%d%d ", &x, &y);
gets(P);
for (int j = 0; '0' <= P[j] && P[j] <= '9'; ++j) {
T = T * 10 + P[j] - '0';
}
int L = 0;
for (int j = 0; P[j]; ++j) {
if (P[j] == 'R' || P[j] == 'U' || P[j] == 'D' || P[j] == 'L') {
S[L++] = P[j];
}
}
for (int j = 0; j < T; ++j) {
for (int k = 0; k < L; ++k) {
int xx = x, yy = y;
switch (S[k]) {
case 'R': ++xx; break;
case 'L': --xx; break;
case 'D': ++yy; break;
case 'U': --yy; break;
}
if (xx >= W) --xx; if (xx < 0) ++xx;
if (yy >= H) --yy; if (yy < 0) ++yy;
if (x != xx) {
int x1 = min(x, xx), x2 = max(x, xx);
D[x2][y]++;
}
if (y != yy) {
int y1 = min(y, yy), y2 = max(y, yy);
R[x][y2]++;
}
x = xx; y = yy;
}
}
}
for (int i = 0; i < 512; ++i) {
for (int j = 0; j < 512; ++j) {
dist[i][j] = 1001001001;
}
}
priority_queue<state> Q;
dist[xs][ys] = 0;
Q.push(state(xs, ys, 0));
static int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
while (!Q.empty()) {
state s = Q.top(); Q.pop();
for (int d = 0; d < 4; ++d) {
int xx = s.x + dx[d], yy = s.y + dy[d];
if (xx < 0 || yy < 0 || xx > W || yy > H) continue;
int ss = s.s + cost(s.x, s.y, xx, yy);
if (dist[xx][yy] > ss) {
dist[xx][yy] = ss;
Q.push(state(xx, yy, ss));
}
}
}
printf("%d\n", dist[xe][ye]);
return 0;
}
提出情報
提出日時
2013-09-23 11:51:40+0900
問題
B - Trodden Cable
ユーザ
Operasan
言語
C++ (GCC 4.4.7)
得点
100
コード長
2099 Byte
結果
AC
実行時間
1038 ms
メモリ
6924 KiB
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:38: warning: ignoring return value of ‘char* gets(char*)’, declared with attribute warn_unused_result
ジャッジ結果
セット名
all
得点 / 配点
100 / 100
結果
セット名
テストケース
all
00_sample00, 00_sample01, 00_sample02, 00_sample03, 01_minimal00, 02_tateyoko00, 03_equal00, 10_random_00, 10_random_01, 10_random_02, 10_random_03, 10_random_04, 10_random_05, 10_random_06, 10_random_07, 10_random_08, 10_random_09, 10_random_10, 10_random_11, 10_random_12, 10_random_13, 10_random_14, 10_random_15, 10_random_16, 10_random_17, 10_random_18, 10_random_19, 10_random_20, 10_random_21, 10_random_22, 10_random_23, 10_random_24, 10_random_25, 10_random_26, 10_random_27, 10_random_28, 10_random_29, 20_max_value_00, 21_max_lattice_00, 22_max_lattice_variant_00, 23_max_spiral_00
ケース名
結果
実行時間
メモリ
00_sample00
AC
23 ms
1944 KiB
00_sample01
AC
23 ms
1948 KiB
00_sample02
AC
23 ms
1776 KiB
00_sample03
AC
21 ms
1952 KiB
01_minimal00
AC
23 ms
1704 KiB
02_tateyoko00
AC
21 ms
1952 KiB
03_equal00
AC
23 ms
1952 KiB
10_random_00
AC
341 ms
1884 KiB
10_random_01
AC
269 ms
2224 KiB
10_random_02
AC
475 ms
3356 KiB
10_random_03
AC
420 ms
3368 KiB
10_random_04
AC
364 ms
2140 KiB
10_random_05
AC
484 ms
3496 KiB
10_random_06
AC
269 ms
3308 KiB
10_random_07
AC
159 ms
3224 KiB
10_random_08
AC
424 ms
2400 KiB
10_random_09
AC
397 ms
2724 KiB
10_random_10
AC
232 ms
2092 KiB
10_random_11
AC
90 ms
3236 KiB
10_random_12
AC
300 ms
3364 KiB
10_random_13
AC
279 ms
2600 KiB
10_random_14
AC
412 ms
1896 KiB
10_random_15
AC
46 ms
2964 KiB
10_random_16
AC
445 ms
2144 KiB
10_random_17
AC
334 ms
3112 KiB
10_random_18
AC
87 ms
2980 KiB
10_random_19
AC
478 ms
3160 KiB
10_random_20
AC
151 ms
2676 KiB
10_random_21
AC
214 ms
1784 KiB
10_random_22
AC
29 ms
3356 KiB
10_random_23
AC
328 ms
2160 KiB
10_random_24
AC
101 ms
2852 KiB
10_random_25
AC
338 ms
3748 KiB
10_random_26
AC
34 ms
2920 KiB
10_random_27
AC
395 ms
2596 KiB
10_random_28
AC
456 ms
3368 KiB
10_random_29
AC
79 ms
3232 KiB
20_max_value_00
AC
917 ms
3484 KiB
21_max_lattice_00
AC
1038 ms
3808 KiB
22_max_lattice_variant_00
AC
1035 ms
3872 KiB
23_max_spiral_00
AC
616 ms
6924 KiB