Submission #60957837
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <tuple>
using namespace std;
using ll = long long;
// 座標を一意に表現するためのヘルパー
struct Coordinate {
ll x, y;
bool operator<(const Coordinate& other) const {
return tie(x, y) < tie(other.x, other.y);
}
};
int main() {
ll N, M, Sx, Sy;
cin >> N >> M >> Sx >> Sy;
// 家の座標を読み込む
set<Coordinate> houses;
for (ll i = 0; i < N; ++i) {
ll x, y;
cin >> x >> y;
houses.insert({x, y});
}
// 移動の指示を読み込む
vector<pair<char, ll>> moves(M);
for (ll i = 0; i < M; ++i) {
char d;
ll c;
cin >> d >> c;
moves[i] = {d, c};
}
// 現在の位置
ll x = Sx, y = Sy;
// 訪問した家の座標を記録
set<Coordinate> visited;
for (const auto& [dir, dist] : moves) {
ll nx = x, ny = y;
// 移動後の座標を計算
if (dir == 'U') ny += dist;
else if (dir == 'D') ny -= dist;
else if (dir == 'L') nx -= dist;
else if (dir == 'R') nx += dist;
// 移動範囲の線分を生成し、家を探索
if (dir == 'U' || dir == 'D') {
ll start = min(y, ny), end = max(y, ny);
for (auto it = houses.lower_bound({x, start}); it != houses.end() && it->y <= end; ++it) {
if (it->x == x) visited.insert(*it);
}
} else {
ll start = min(x, nx), end = max(x, nx);
for (auto it = houses.lower_bound({start, y}); it != houses.end() && it->x <= end; ++it) {
if (it->y == y) visited.insert(*it);
}
}
// 現在位置を更新
x = nx;
y = ny;
}
// 出力
cout << x << " " << y << " " << visited.size() << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Santa Claus 2 |
User |
VIP1109 |
Language |
C++ 20 (gcc 12.2) |
Score |
0 |
Code Size |
1991 Byte |
Status |
TLE |
Exec Time |
2208 ms |
Memory |
24016 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 425 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt |
Case Name |
Status |
Exec Time |
Memory |
hand.txt |
AC |
1 ms |
3484 KiB |
random_01.txt |
AC |
63 ms |
6244 KiB |
random_02.txt |
AC |
64 ms |
6256 KiB |
random_03.txt |
AC |
63 ms |
6316 KiB |
random_04.txt |
AC |
191 ms |
17744 KiB |
random_05.txt |
AC |
207 ms |
24016 KiB |
random_06.txt |
AC |
1397 ms |
11852 KiB |
random_07.txt |
AC |
1050 ms |
17660 KiB |
random_08.txt |
TLE |
2208 ms |
14548 KiB |
random_09.txt |
TLE |
2208 ms |
16528 KiB |
random_10.txt |
AC |
1004 ms |
7816 KiB |
random_11.txt |
TLE |
2208 ms |
20428 KiB |
random_12.txt |
TLE |
2208 ms |
21880 KiB |
random_13.txt |
TLE |
2208 ms |
19868 KiB |
random_14.txt |
TLE |
2208 ms |
21648 KiB |
random_15.txt |
TLE |
2208 ms |
21604 KiB |
random_16.txt |
TLE |
2208 ms |
22960 KiB |
random_17.txt |
TLE |
2208 ms |
21744 KiB |
random_18.txt |
TLE |
2208 ms |
21420 KiB |
random_19.txt |
TLE |
2208 ms |
22200 KiB |
random_20.txt |
TLE |
2208 ms |
19972 KiB |
random_21.txt |
TLE |
2208 ms |
21320 KiB |
random_22.txt |
TLE |
2208 ms |
22756 KiB |
sample_01.txt |
AC |
1 ms |
3620 KiB |
sample_02.txt |
AC |
1 ms |
3488 KiB |