我去!时间卡这么紧
查看原帖
我去!时间卡这么紧
677091
MnZnOIer楼主2023/10/24 20:13

本人帅气的代码

#include<bits/stdc++.h>
using namespace std;
string a[4] = {"", "1", "2", "error"};
int t, p, x, y, f[10001][10001];
bool vis[10001][10001];
void dfs (int x, int y)
{
	if (vis[x][y])f[x][y] = 3;
	if (f[x][y] != 0)return;
	if (x == 0)
	{
		f[x][y] = 1;
		return;
	}
	if (y == 0)
	{
		f[x][y] = 2;
		return;
	}
	int xx = (x + y) % p;
	int yy = (xx + y) % p;
	vis[x][y] = 1;
	dfs (xx, yy);
	f[x][y] = f[xx][yy];
	vis[x][y] = 0;
}
int main()
{
	scanf ("%d %d", &t, &p);
	while (t --)
	{
		scanf ("%d %d", &x, &y);
		dfs (x, y);
		cout << a[f[x][y]];
		puts ("");
		memset (vis, 0, sizeof (vis));
	}
	return 0;
}

他哥的400ms给我超时了

2023/10/24 20:13
加载中...