dwz到此二游
update 2025.3.25 14:26:50 紫题=100。
update 2025.4.1 一天写了3篇题解,全部一次性通过。
update 2025.4.28 P3863暂居rank1(问题是没故意卡)。
update 2025.4.29 第一篇黑题题解(ABC402G)。
update 2025.5.1 16:50:31 蓝题=200。
update 2025.5.22 19:04:07 紫题=200。
update 2025.7.10 17:16:54 在 https://www.luogu.com.cn/record/223496581 中,时限=#9用时=2s。
update 2025.7.13 12:08:25 通过1000整!
update 2025.7.17 10:26:10 黑题=20。
update 2025.7.20 19:04:20 P8916在无意间最优解(莫名其妙)。
update 2025.7.30 23:31:40 P7118最优解。
update 2025.8.5 16:42:26 P2416最优解。
update 2025.8.9 14:36:10 P8578最优解。
update 2025.9.24 18:14:39 P5354最优解。
update 2025.9.27 15:16:48 P7597(交互题)在没有尝试样例的情况下一次性通过。
update 2025.10.13 22:25:48 P3536最优解
update 2025.10.27 11:33:58 P9129 最优解
update 2026.9.16 20:03:44 P12921 最优解
Just Remember:
1.DSU启发式合并的时候,Merge函数要判 x==y 的情况。
2.如果没有 #define int long long,那么注意应为 int read()。
3.区分 。
4.BIT.ADD(int i,int x) 的时候, 不能等于 。
5. 的空间开两倍。
6.若以 为根树剖,则需将 初始化为 。
7.注意离散化前后值的变化
8.记得初始化
9.用 的时候,一定要加 里面的数,不要加负数!
待学:
长链剖分
#include<bits/stdc++.h>
#define int long long
using namespace std;
bool Beginning;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define se second
#define fi first
using PII=pair<int,int>;
using PIB=pair<int,bool>;
using PBI=pair<bool,int>;
using PBB=pair<bool,bool>;
using PDI=pair<double,int>;
using PID=pair<int,double>;
namespace Memory_Love{
int read(){ int x=0; bool flag=1; char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-') flag=0; ch=getchar();}
while(ch>='0' && ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} return flag? x:-x;}
template<typename T> void read(T &x){ bool flag=1; x=0; char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-') flag=0; ch=getchar();}
while(ch>='0' && ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} x=(flag? x:-x);}
template<typename T,typename ...Args> void read(T &Re,Args &...Res){read(Re),read(Res...);}
template<typename T> void write(T x,char ch=0){if(x<0) x=-x,putchar('-');
static short s[35],top=-1; do{s[++top]=x%10;x/=10;}while(x);
while(~top) putchar(s[top--]+48); if(ch) putchar(ch);}
int gcd(int a,int b){return b==0? a:gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
} using namespace Memory_Love;
const int N=50;
const int dx[10]={0,1,0,-1};
const int dy[10]={1,0,-1,0};
const char C[4]={'E','S','W','N'};
const char c[4]={'e','s','w','n'};
int n,m;
char a[N][N];
struct Node
{
int mx,my,bx,by;
string s;
int Step,Num;
bool friend operator <(const Node &a,const Node &b)
{
if(a.Step!=b.Step)
return a.Step>b.Step;
else
return a.Num>b.Num;
}
}s;
bool vis[N][N][N][N];
bool check(Node &t,int w)
{
if(t.mx<1 || t.mx>n || t.my<1 || t.my>m || a[t.mx][t.my]=='#') return false;
if(vis[t.mx][t.my][t.bx][t.by]) return false;
if(t.mx==t.bx && t.my==t.by)
{
int x=t.bx+dx[w],y=t.by+dy[w];
if(x<1 || x>n || y<1 || y>m || a[x][y]=='#') return false;
t.bx=x,t.by=y;
t.Step++;
t.s+=C[w];
}
else t.s+=c[w];
t.Num++;
vis[t.mx][t.my][t.bx][t.by]=1;
return true;
}
priority_queue<Node> q;
bool bfs(Node s)
{
int i;
while(q.size()) q.pop();
q.push(s);
vis[s.mx][s.my][s.bx][s.by]=1;
while(q.size())
{
Node t=q.top();
q.pop();
for(i=0;i<=3;i++)
{
Node P=t;
P.mx=t.mx+dx[i];
P.my=t.my+dy[i];
if(check(P,i))
{
if(a[P.bx][P.by]=='T')
{
cout<<P.s<<'\n';
return true;
}
q.push(P);
}
}
}
}
bool Ending;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int k,i,j;
for(k=1;;k++)
{
cin>>n>>m;
if(n==0 || m==0) return 0;
memset(vis,0,sizeof(vis));
cout<<"Maze #"<<k<<'\n';
s.s="",s.Step=s.Num=0;
s.mx=s.my=s.bx=s.by=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]=='S') s.mx=i,s.my=j;
if(a[i][j]=='B') s.bx=i,s.by=j;
}
}
if(bfs(s)==false)
cout<<"Impossible."<<'\n';
cout<<'\n';
}
cerr<<"\nused:"<<(abs(&Ending-&Beginning)/1048576)<<"MB\n";
return 0;
}