提出 #60995592
ソースコード 拡げる
// Problem: D - Santa Claus 2
// Contest: AtCoder - UNIQUE VISION Programming Contest 2024 Christmas (AtCoder Beginner Contest 385)
// URL: https://atcoder.jp/contests/abc385/tasks/abc385_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define AC return 0
const ll mod = 1; // Be careful, 998244353 or 998244853.
const ll dx[] = {0, 1, 0, -1};
const ll dy[] = {1, 0, -1, 0};
mt19937 rnd(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
void ts() {
cerr << "The code is running!\n";
}
ll read() {
char c;
bool isf = 0;
while (!isdigit(c = getchar())) isf = (c == '-');
ll res = (c ^ 48);
while (isdigit(c = getchar())) res = (res << 3) + (res << 1) + (c ^ 48);
return isf ? -res : res;
}
void write(ll x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
write(x / 10);
putchar('0' + x % 10);
}
void updmin(ll& x, ll y) {
x = min(x, y);
}
void updmax(ll& x, ll y) {
x = max(x, y);
}
ll qpow(ll x, ll y) {
if (y == 0) {
return 1;
}
ll res = qpow(x, y / 2);
res *= res;
res %= mod;
if (y % 2) {
res *= x;
res %= mod;
}
return res;
}
ll randint(ll l, ll r) {
return rnd() % (r - l + 1) + l;
}
void openf(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
ll tc = 1, n, m, x, y, ans, px[214514], py[214514];
set<ll> xx, yy;
map<ll, ll> tox, toy;
set<ll> sx[214514], sy[214514];
const ll inf = 1e18;
void init() {
;
}
void solve() {
init();
cin >> n >> m >> x >> y;
for (ll i = 1; i <= n; i++) {
cin >> px[i] >> py[i];
xx.insert(px[i]);
yy.insert(py[i]);
sx[i].insert(-inf);
sx[i].insert(inf);
sy[i].insert(-inf);
sy[i].insert(inf);
}
ll tot = 0;
for (ll kk : xx) {
tot++;
tox[kk] = tot;
}
tot = 0;
for (ll kk : yy) {
tot++;
toy[kk] = tot;
}
for (ll i = 1; i <= n; i++) {
sx[tox[px[i]]].insert(py[i]);
sy[toy[py[i]]].insert(px[i]);
px[i] = tox[px[i]];
py[i] = toy[py[i]];
}
for (ll i = 1; i <= m; i++) {
char c;
cin >> c;
ll d;
cin >> d;
ll nx = x, ny = y;
if (c == 'U') {
ny += d;
} else if (c == 'D') {
ny -= d;
} else if (c == 'L') {
nx -= d;
} else {
nx += d;
}
vector<ll> bin;
if (nx == x) {
if (tox.find(x) != tox.end()) {
ll tx = tox[x];
auto it1 = sx[tx].lower_bound(min(ny, y));
auto it2 = sx[tx].upper_bound(max(ny, y));
for (auto it = it1; it != it2 && it != sx[tx].end(); it++) {
if (*it == inf || *it == -inf) {
continue;
}
ans++;
bin.push_back(*it);
}
for (ll num : bin) {
sx[tx].erase(num);
sy[toy[num]].erase(x);
}
}
} else if (ny == y) {
if (toy.find(y) != toy.end()) {
ll ty = toy[y];
auto it1 = sy[ty].lower_bound(min(nx, x));
auto it2 = sy[ty].upper_bound(max(nx, x));
for (auto it = it1; it != it2 && it != sy[ty].end(); it++) {
if (*it == inf || *it == -inf) {
continue;
}
ans++;
bin.push_back(*it);
}
for (ll num : bin) {
sy[ty].erase(num);
sx[tox[num]].erase(y);
}
}
}
x = nx;
y = ny;
}
cout << x << " " << y << " " << ans;
}
int main() {
// openf("data");
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
// tc = read();
while (tc--) {
solve();
putchar("\n "[(!tc)]);
}
// printf("Time: %.6lf\n", (double)clock() / CLOCKS_PER_SEC);
AC;
}
/*
Things to check:
1. When testing multiple sets of data, remember to clear the array.
2. When clearing, pay attention to clearing the area, starting from 0 or 1. If time permits, use memset.
3. Delete the debugged code.
4. Do you need to enable file input/output.
5. Use faster input and output methods.
6. INT or long long.
7. Pay attention to time complexity and space complexity, and control constants.
8. Think twice before acting.
9. Talk is cheap, show me the code.
10. The most important one, zxq's brain.
*/
/*
_|_|_|_|_| _| _| _|_| _| _| _|_| _| _|_| _| _|
_| _| _| _| _| _| _| _| _| _| _| _| _| _| _|
_| _| _| _|_| _| _| _| _| _| _|_|_|_|
_| _| _| _| _| _| _| _| _| _| _| _|
_|_|_|_|_| _| _| _|_| _| _| _| _|_|_|_| _| _|_|_|_| _|
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
.......RRRRRRRRRRRRRRRRRRRR...................PPPPPPPPPPPPPPPPPPPP...............................................
.......RRRRRRRRRRRRRRRRRRRRRR.................PPPPPPPPPPPPPPPPPPPPPP.............................................
.......RRRRRRRRRRRRRRRRRRRRRRR................PPPPPPPPPPPPPPPPPPPPPPPP...........................................
.......RRRR.................RRRRR.............PPPP...............PPPPP...........................................
.......RRRR.................RRRRR.............PPPP................PPPPP..........................................
.......RRRR.................RRRRR.............PPPP................PPPPP..........................................
.......RRRR...............RRRRR...............PPPP...............PPPPP...........................................
.......RRRR............RRRRRR.................PPPP.............PPPPPP............................................
.......RRRR............RRRRRR.................PPPP............PPPPPP.............................................
.......RRRR........RRRRRR.....................PPPP........PPPPPPP................................................
.......RRRRRRRRRRRRRRRRRR.....................PPPPPPPPPPPPPPPPPP.................................................
.......RRRRRRRRRRRRRRRRRR.....................PPPPPPPPPPPPPPPP...................................................
.......RRRR..........RRRR.....................PPPPP.................................+++................+++.......
.......RRRR...........RRRR....................PPPPP.................................+++................+++.......
.......RRRR.............RRRR..................PPPPP.................................+++................+++.......
.......RRRR..............RRRR.................PPPPP...........................+++++++++++++++....+++++++++++++++.
.......RRRR...............RRRR................PPPPP...........................+++++++++++++++....+++++++++++++++.
.......RRRR................RRRR...............PPPPP.................................+++................+++.......
.......RRRR.................RRRR..............PPPPP.................................+++................+++.......
.......RRRR...................RRRR............PPPPP.................................+++................+++.......
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
.................................................................................................................
*/
提出情報
| 提出日時 |
|
| 問題 |
D - Santa Claus 2 |
| ユーザ |
joe_zxq |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
425 |
| コード長 |
8514 Byte |
| 結果 |
AC |
| 実行時間 |
728 ms |
| メモリ |
117484 KiB |
コンパイルエラー
Main.cpp: In function ‘void openf(std::string)’:
Main.cpp:68:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
68 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:69:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
69 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
425 / 425 |
| 結果 |
|
|
| セット名 |
テストケース |
| 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 |
| ケース名 |
結果 |
実行時間 |
メモリ |
| hand.txt |
AC |
8 ms |
23764 KiB |
| random_01.txt |
AC |
21 ms |
23716 KiB |
| random_02.txt |
AC |
24 ms |
23696 KiB |
| random_03.txt |
AC |
23 ms |
23656 KiB |
| random_04.txt |
AC |
603 ms |
105176 KiB |
| random_05.txt |
AC |
504 ms |
105576 KiB |
| random_06.txt |
AC |
113 ms |
45656 KiB |
| random_07.txt |
AC |
293 ms |
76516 KiB |
| random_08.txt |
AC |
675 ms |
104064 KiB |
| random_09.txt |
AC |
728 ms |
117484 KiB |
| random_10.txt |
AC |
97 ms |
41664 KiB |
| random_11.txt |
AC |
389 ms |
83296 KiB |
| random_12.txt |
AC |
428 ms |
83296 KiB |
| random_13.txt |
AC |
302 ms |
83252 KiB |
| random_14.txt |
AC |
326 ms |
83304 KiB |
| random_15.txt |
AC |
341 ms |
83320 KiB |
| random_16.txt |
AC |
430 ms |
83304 KiB |
| random_17.txt |
AC |
414 ms |
83288 KiB |
| random_18.txt |
AC |
401 ms |
83364 KiB |
| random_19.txt |
AC |
342 ms |
83304 KiB |
| random_20.txt |
AC |
320 ms |
83312 KiB |
| random_21.txt |
AC |
407 ms |
83304 KiB |
| random_22.txt |
AC |
413 ms |
83180 KiB |
| sample_01.txt |
AC |
10 ms |
23700 KiB |
| sample_02.txt |
AC |
9 ms |
23644 KiB |