#35WA 求hack
查看原帖
#35WA 求hack
490651
zcy942楼主2024/7/29 21:15

已学习过正解,但不明白是什么情况下蒟蒻的代码会WA
个人思路:如果后续每次增加的点数相同了,就说明以后必然都相同了,于是直接计算得出答案
感觉正确性没有问题而且对于随机数据超快
但可能会被精心设计的数据卡TLE

但不应该是WA啊QAQ
求助

#include <bits/stdc++.h>
#define ri register unsigned long long
using namespace std;

inline unsigned long long read(){
	unsigned long long ret=0; bool f=1; char c;
	while((c=getchar())<'0' || c>'9') if(c=='-') f=0;
	while(isdigit(c)) ret=(ret<<3)+(ret<<1)+(c^48),c=getchar();
	return f ? ret : ~ret+1;
}

unordered_map<unsigned long long,unordered_map<unsigned long long,bool> > vis;
string s;
unsigned long long k,len,ad=0,t,ans,x,y;

void dfs(){
	for(ri i=0;i<len;i++){
		switch(s[i]){
			case 'L':{
				x--;
				if(!vis[x][y]) ad++;
				break;
			}
			case 'R':{
				x++;
				if(!vis[x][y]) ad++;
				break;
			}
			case 'U':{
				y--;
				if(!vis[x][y]) ad++;
				break;
			}
			case 'D':{
				y++;
				if(!vis[x][y]) ad++;
				break;
			}
		}
		vis[x][y]=1;
	}
}

int main(){
//	freopen("loop.in","r",stdin);
//	freopen("loop.out","w",stdout);

	getline(cin,s);
	k=read();
	len=s.size();
	vis[x][y]=1,ad=1;
	dfs();
	ans+=ad,t=ad,ad=0;
	if(k==1 || (x==0 && y==0)) return printf("%llu\n",t),0;
	while(k--){
		dfs();
		if(t==ad) break;
		ans+=ad,t=ad,ad=0;
	}
	printf("%llu\n",ans+t*k);

	return 0;
}//By ZCY  awa
2024/7/29 21:15
加载中...