QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#417028#524. 扫地机器人Max_s_xaM100 ✓30ms3592kbC++174.4kb2024-05-22 13:15:262024-05-22 13:15:28

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 13:15:28]
  • 评测
  • 测评结果:100
  • 用时:30ms
  • 内存:3592kb
  • [2024-05-22 13:15:26]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 60, MAXM = 2510, mod = 998244353;

int n, m;
char mp[MAXN][MAXN];

int odr[MAXM][2], top;
int pre[MAXN][MAXN], suf[MAXN][MAXN];
ll f[MAXN][MAXN], g[MAXN][MAXN], ans;

inline void Solve()
{
    Read(n), Read(m);
    for (int i = 0; i < n; i++) Read(mp[i]);
    int dd = __gcd(n, m);
    ans = 0;
    for (int s = 0, t; s <= dd; s++)
    {
        t = dd - s;
        if (s >= n || t >= m) continue;
        top = 0;
        int xx = s, yy = t;
        while (xx || yy) top++, odr[top][0] = xx, odr[top][1] = yy, xx = (xx + s) % n, yy = (yy + t) % m;
        top++, odr[top][0] = odr[top][1] = 1;
        if (top != n * m / dd) continue;

        // cout << s << " " << t << "\n";
        s++, t++;

        for (int i = 1; i <= s; i++)
            for (int j = 1; j <= t; j++)
                pre[i][j] = suf[i][j] = 0;
        for (int cs = 1; cs <= top; cs++)
        {
            xx = odr[cs][0] - s, yy = odr[cs][1] - t;
            for (int i = 1; i <= s; i++)
                for (int j = 1; j <= t; j++)
                    pre[i][j] |= (mp[(xx + i + n) % n][(yy + j + m) % m] - '0');

            memset(f, 0, sizeof(f)), memset(g, 0, sizeof(g));
            for (int i = 1; i <= s; i++)
                for (int j = 1; j <= t; j++)
                    if (i == 1 && j == 1) f[i][j] = !pre[i][j];
                    else if (!pre[i][j]) f[i][j] = (f[i - 1][j] + f[i][j - 1]) % mod;
            for (int i = s; i >= 1; i--)
                for (int j = t; j >= 1; j--)
                    if (i == s && j == t) g[i][j] = !suf[i][j];
                    else if (!suf[i][j]) g[i][j] = (g[i + 1][j] + g[i][j + 1]) % mod;

            for (int i = 1; i <= s; i++)
                for (int j = 1; j <= t; j++)
                    if (i != s || j != t) ans = (ans + f[i][j] * g[i][j]) % mod;

            // for (int i = 1; i <= s; i++, cout << "\n")
            //     for (int j = 1; j <= t; j++)
            //         cout << pre[i][j] << ' ';
            // cout << ans << '\n';

            for (int i = 1; i <= s; i++)
                for (int j = 1; j <= t; j++)
                    suf[i][j] |= (mp[(xx + i + n) % n][(yy + j + m) % m] - '0');
        }
        s--, t--;
    }
    cout << ans << '\n';
}

int main()
{
    // freopen("B.in", "r", stdin);
    // freopen("B.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    int T;
    Read(T);
    while (T--) Solve();
    return 0;
}

詳細信息

Test #1:

score: 20
Accepted
time: 1ms
memory: 3572kb

input:

6
4 4
0000
0100
0000
0001
4 4
0000
0000
0100
0010
3 4
0010
0000
0011
4 2
01
00
00
01
3 3
000
010
000
4 4
0000
0011
1011
0010

output:

32
48
0
7
18
29

result:

ok 6 lines

Test #2:

score: 30
Accepted
time: 10ms
memory: 3592kb

input:

6
36 48
011111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111...

output:

1608
561
0
522350459
873501488
5769552

result:

ok 6 lines

Test #3:

score: 50
Accepted
time: 30ms
memory: 3580kb

input:

10
36 24
010000100000000000101000
000000000000010100000000
000000000000010000010010
110101000000000100000100
000000000000000000010000
000110000000000000100101
010100000001000100000000
001100101100000001000000
000000000000011011000000
101010010000000000010000
010000000000000010010100
0100000100000000...

output:

5825
383731359
98032859
2019
783509382
454661140
169333321
0
341832245
858152425

result:

ok 10 lines

Extra Test:

score: 0
Extra Test Passed