挟关注以求大佬,大佬可以不从(40pts求条)
查看原帖
挟关注以求大佬,大佬可以不从(40pts求条)
772815
一咕咕一楼主2024/8/24 17:08

球球了

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LD;
short ans[10007][10007];
set<pair<int, int>> st;
int T, p;
short DFS(int x, int y, int step)
{
    if (st.count({x, y}))
        return 3;
    if (ans[x][y] != -1)
        return ans[x][y];
    st.insert({x, y});
    if (x == 0)
        return 1;
    if (y == 0)
        return 2;
    if (step & 1)
        return ans[x][y] = DFS((x % p + y % p) % p, y, step + 1);
    else
        return ans[x][y] = DFS(x, (x % p + y % p) % p, step + 1);
}
int main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    cin >> T >> p;
    fill(ans[0], ans[0] + 10007 * 10007, -1);
    while (T--)
    {
        st.clear();
        int x, y;
        cin >> x >> y;
        int Ans = DFS(x, y, 1);
        if (Ans < 3)
            cout << Ans << '\n';
        else
            cout << "error\n";
    }
    return 0;
}

哇哇哇哇哇(闭关)

2024/8/24 17:08
加载中...