数据过水,建议加强
查看原帖
数据过水,建议加强
682739
nr0728楼主2025/1/31 19:35

这种显然复杂度不对的爆搜怎么都能过。

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf,ubuf[1<<23],*u=ubuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
	TP x=0;
	int f=0;
	char ch=getchar();
	while(ch<48||ch>57) f|=ch=='-',ch=getchar();
	while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return num=f?-x:x;
}
int T,x,y;
map<pair<int,int>,int> mp;
int dfs(int x,int y)
{
	if(x==y) return 1;
	if(x%y==0||y%x==0) return 1;
	if(mp.count({x,y})) return mp[{x,y}];
	int canwin=0;
	if(x>y) for(int i=y;i<=x;i+=y) canwin|=!dfs(x-i,y);
	else for(int i=x;i<=y;i+=x) canwin|=!dfs(x,y-i);
	return mp[{x,y}]=canwin;
}
signed main()
{
	read(T);
	while(T--)
	{
		read(x),read(y);
		puts(dfs(x,y)?"Stan wins":"Ollie wins");
	}
	return 0;
}

加组 hack:

1
3 2147483647
2025/1/31 19:35
加载中...