提出 #41764729
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int N ,M, H, K;
cin >> N >> M >> H >> K;
string moves;
cin >> moves;
unordered_set<int> items;
for (int i = 0; i < M; i++) {
int x, y;
cin >> x >> y;
items.insert(x * 400001 + y); // 座標をユニークな数値に変換して保存
}
bool isPossible = true;
int currentH = H; // 現在の体力
pair<int, int> currentPosition = make_pair(0, 0); // 現在の位置
for (int i = 0; i < N; i++) {
// i回目の移動
char move = moves[i];
int nextX = currentPosition.first;
int nextY = currentPosition.second;
// 移動先の座標を計算
if (move == 'R') {
nextX++;
} else if (move == 'L') {
nextX--;
} else if (move == 'U') {
nextY++;
} else if (move == 'D') {
nextY--;
}
// 体力を1消費
currentH--;
// 体力が負になった場合、移動をやめる
if (currentH < 0) {
isPossible=false;
}
// 移動先にアイテムがあり、かつ体力がK未満の場合
if (items.count(nextX * 400001 + nextY) && currentH < K) {
currentH = K; // 体力をKに回復
}
// 次の位置を更新
currentPosition = make_pair(nextX, nextY);
//cout<<i<<" "<<currentH<<endl;
}
if (isPossible) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Dash |
| ユーザ | chacoder |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 0 |
| コード長 | 1677 Byte |
| 結果 | WA |
| 実行時間 | 116 ms |
| メモリ | 11468 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 300 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_01.txt | AC | 8 ms | 3440 KiB |
| 00_sample_02.txt | AC | 3 ms | 3408 KiB |
| 01_test_01.txt | AC | 116 ms | 11468 KiB |
| 01_test_02.txt | AC | 76 ms | 7392 KiB |
| 01_test_03.txt | AC | 78 ms | 7496 KiB |
| 01_test_04.txt | AC | 10 ms | 3672 KiB |
| 01_test_05.txt | AC | 12 ms | 3620 KiB |
| 01_test_06.txt | AC | 13 ms | 3688 KiB |
| 01_test_07.txt | AC | 15 ms | 3632 KiB |
| 01_test_08.txt | AC | 13 ms | 3672 KiB |
| 01_test_09.txt | AC | 13 ms | 3720 KiB |
| 01_test_10.txt | AC | 19 ms | 3668 KiB |
| 01_test_11.txt | WA | 14 ms | 3628 KiB |
| 01_test_12.txt | WA | 15 ms | 3720 KiB |
| 01_test_13.txt | AC | 14 ms | 3684 KiB |
| 01_test_14.txt | WA | 12 ms | 3672 KiB |
| 01_test_15.txt | AC | 17 ms | 3600 KiB |
| 01_test_16.txt | AC | 12 ms | 3672 KiB |
| 01_test_17.txt | AC | 15 ms | 3604 KiB |
| 01_test_18.txt | WA | 13 ms | 3628 KiB |