Submission #52705


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
int h, w;
int sy, sx;
int info[64][64];
int collect(int p) {
int ret = 0;
int y = sy, x = sx;
while (true) {
if (info[y][x] == 1) {
if (p == 1) sy = y + 1;
else if (p == 2) sy = y - 1;
else if (p == 3) sx = x - 1;
else sx = x + 1;
return ret;
}
if (p == 1) --y;
else if (p == 2) ++y;
else if (p == 3) ++x;
else --x;
if (info[y][x] == 3) {
++ret;
info[y][x] = 0;
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> h >> w;
rep(i, h) {
rep(j, w) {
cin >> info[i][j];
if (info[i][j] == 4) {
sy = i;
sx = j;
}
}
}
int ans = 0;
int n;
cin >> n;
int p[128];
rep(i, n) {
cin >> p[i];
ans += collect(p[i]);
}
cout << ans << "\n";
return 0;
}

ステータス

項目 データ
問題 0387 - 回れ雛月花 -Easy
ユーザー名 もけ
投稿日時 2019-08-09 23:21:59
言語 C++14
状態 Accepted
得点 3
ソースコード長 1420 Byte
最大実行時間 33 ms
最大メモリ使用量 604 KB

セット

セット 得点 Cases
1 ALL 3 / 3 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
spin_input01 AC 33 ms 604 KB
1
spin_input02 AC 21 ms 420 KB
1
spin_input03 AC 22 ms 500 KB
1
spin_input04 AC 20 ms 580 KB
1
spin_input05 AC 23 ms 524 KB
1