0%

ABC-398-D - Bonfire

思路讲解

赛时AC,记录一下

这个东西说难也不难,就是要抓住不变的东西,其实就是生成的烟雾相对于最初的烟雾其实相对位置是不变的

所以我们把所有烟雾相对于最初烟雾的偏离存在一个set里,接着我们得到目标块与最初烟雾的相对位置,在set里一找,然后就知道有没有烟雾了。

AC代码

https://atcoder.jp/contests/abc398/submissions/64075308

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Problem: D - Bonfire
// Contest: AtCoder - UNIQUE VISION Programming Contest 2025 Spring (AtCoder Beginner Contest 398)
// URL: https://atcoder.jp/contests/abc398/tasks/abc398_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// by znzryb
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int) a.size())

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef double DB;
typedef pair<DB,DB> pdd;
typedef pair<ll,bool> plb;
constexpr ll MAXN=static_cast<ll>(1e6)+10,INF=static_cast<ll>(5e18)+3;

ll N,R,C,T,A[MAXN];
char S[MAXN];

inline void solve(){
cin>>N>>R>>C;
R=-R;
FOR(i,1,N){
cin>>S[i];
}
ll x=0,y=0;
set<pll> smoke;
smoke.insert((pll){0,0});
FOR(i,1,N){
// if(R==0 && C==0){
// cout<<1;
// continue;
// }
if(S[i]=='N'){
y+=1;
smoke.insert((pll){0-y,0-x});
if(smoke.find((pll){R-y,C-x})==smoke.end()){
cout<<0;
}else{
cout<<1;
}
}else if(S[i]=='S'){
y-=1;
smoke.insert((pll){0-y,0-x});
if(smoke.find((pll){R-y,C-x})==smoke.end()){
cout<<0;
}else{
cout<<1;
}
}else if(S[i]=='E'){
x+=1;
smoke.insert((pll){0-y,0-x});
if(smoke.find((pll){R-y,C-x})==smoke.end()){
cout<<0;
}else{
cout<<1;
}
}else{
x-=1;
smoke.insert((pll){0-y,0-x});
if(smoke.find((pll){R-y,C-x})==smoke.end()){
cout<<0;
}else{
cout<<1;
}

}

}
cout<<"\n";
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// cin>>T;
// while(T--){
// solve();
// }
solve();
return 0;
}
/*
AC
https://atcoder.jp/contests/abc398/submissions/64075308
*/

心路历程(WA,TLE,MLE……)