QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99794#4798. Floor Tiles in a Parkckiseki#AC ✓51ms3524kbC++204.4kb2023-04-23 19:08:192023-04-23 19:08:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-23 19:08:21]
  • 评测
  • 测评结果:AC
  • 用时:51ms
  • 内存:3524kb
  • [2023-04-23 19:08:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define orange(a...) orange_(#a, a)
#define debug(a...) debug_(#a, a)
template <typename i>
void orange_(const char * s, i l, i r) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; l != r; l++)
        cerr << (f++ ? " " : "") << *l;
    cerr << " ]\e[0m\n";
}
template <typename ...T>
void debug_(const char * s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

int a[10][10];
int cnt[10];

void dfs(const int n, const int m, int i, int j, int k) {
    while (i < n) {
        while (j < m && a[i][j])
            ++j;
        if (j == m) {
            j = 0;
            i++;
        } else {
            break;
        }
    }

    if (i == n) {
        cnt[k] += 1;
        // debug(n, m, i, j);
        // for (int t = 0; t < n; t++)
        //     orange(a[t], a[t]+m);

        return;
    }

    if (k >= 5) {
        return;
    }

    const auto clean = [&](int T, int S) {
        for (int t = 0; t < T; t++) {
            for (int s = 0; s < S; s++)
                a[i + t][j + s] = 0;
        }
    };

    for (int A = 1; i + A <= n; A++) {
        for (int B = 1; j + B <= m; B++) {
            bool ok = true;
            for (int t = 0; t < A; t++)
                if (a[i + t][j + B - 1])
                    ok = false;
            if (!ok) {
                clean(A, B - 1);
                break;
            }
            for (int t = 0; t < A; t++)
                a[i + t][j + B - 1] = k + 1;

            dfs(n, m, i, j+B, k + 1);

            if (j + B == m)
                clean(A, B);
        }
    }
}

const int mod = 998244353;

int modpow(int e, int p) {
    int r = 1;
    while (p) {
        if (p & 1) r = 1LL*r*e%mod;
        e = 1LL*e*e%mod;
        p >>= 1;
    }
    return r;
}

int modinv(int z) {
    return modpow(z, mod - 2);
}

vector<int> mul(vector<int> a, vector<int> b) {
    vector<int> c(a.size() + b.size() - 1);
    for (size_t i = 0; i < a.size(); i++) {
        for (size_t j = 0; j < b.size(); j++) {
            c[i + j] = (c[i + j] + 1LL * a[i] * b[j]) % mod;
        }
    }
    return c;
}

int modsub(int a, int b) {
    return a - b < 0 ? a - b + mod : a - b;
}
int mul(int64_t a, int64_t b) {
    return static_cast<int>(a * b % mod);
}
int modadd(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b;
}

int eval(vector<int> p, int x) {
    int s = 0;
    int prod = 1;
    for (int j = 0; j < p.size(); j++) {
        s = modadd(s, mul(prod , p[j]));
        prod = mul(prod, x);
    }
    return s;
}

vector<int> interpolate(vector<pair<int,int>> pts) {
    const int n = pts.size();
    vector<int> res(n);

    for (int i = 0; i < n; i++) {
        vector<int> tmp{pts[i].second};
        for (int j = 0; j < n; j++) {
            if (j != i)
                tmp[0] = mul(tmp[0],
                        modinv(
                            modsub(pts[i].first, pts[j].first)
                            ));
        }
        for (int j = 0; j < n; j++) {
            if (j != i)
                tmp = mul(tmp, {mod-pts[j].first, 1});
        }
        for (int i = 0; i < n; i++) {
            res[i] = modadd(res[i], tmp[i]);
        }
    }

    debug(n);
    for (int i = 0; i < n; i++) {
        auto [x, y] = pts[i];
        assert (eval(res, x) == y);
    }

    return res;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    vector<int> poly[6][10];

    for (int n = 1; n <= 6; n++) {

        vector<pair<int,int>> pr[6];
        for (int m = 1; m <= 6; m++) {
            memset(cnt, 0, sizeof(cnt));
            dfs(n, m, 0, 0, 0);
            orange(cnt, cnt + 6);
            for (int k = 1; k <= 5; k++) {
                pr[k].emplace_back(m, cnt[k]);
            }
        }

        for (int k = 1; k <= 5; k++) {
            poly[k][n] = interpolate(pr[k]);
        }

    }

    {
        int N, M, k;
        cin >> N >> M >> k;

        vector<int> coef(6);
        for (int j = 0; j < 6; j++) {
            vector<pair<int,int>> tmp;
            for (int n = 1; n <= 6; n++) {
                tmp.emplace_back(n, poly[k][n][j]);
            }
            auto ret = interpolate(tmp);
            coef[j] = eval(ret, N);
        }

        cout << eval(coef, M) << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 33ms
memory: 3384kb

input:

2 3 5

output:

7

result:

ok 1 number(s): "7"

Test #2:

score: 0
Accepted
time: 28ms
memory: 3376kb

input:

4 3 5

output:

307

result:

ok 1 number(s): "307"

Test #3:

score: 0
Accepted
time: 33ms
memory: 3452kb

input:

6 372065168 5

output:

114514

result:

ok 1 number(s): "114514"

Test #4:

score: 0
Accepted
time: 29ms
memory: 3496kb

input:

6 7 3

output:

145

result:

ok 1 number(s): "145"

Test #5:

score: 0
Accepted
time: 30ms
memory: 3380kb

input:

4 8 2

output:

10

result:

ok 1 number(s): "10"

Test #6:

score: 0
Accepted
time: 32ms
memory: 3448kb

input:

7 5 4

output:

1104

result:

ok 1 number(s): "1104"

Test #7:

score: 0
Accepted
time: 30ms
memory: 3452kb

input:

8 6 1

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 33ms
memory: 3368kb

input:

8 2 5

output:

1092

result:

ok 1 number(s): "1092"

Test #9:

score: 0
Accepted
time: 32ms
memory: 3408kb

input:

2 7 4

output:

191

result:

ok 1 number(s): "191"

Test #10:

score: 0
Accepted
time: 34ms
memory: 3520kb

input:

6 6 4

output:

1145

result:

ok 1 number(s): "1145"

Test #11:

score: 0
Accepted
time: 32ms
memory: 3444kb

input:

1 5 5

output:

1

result:

ok 1 number(s): "1"

Test #12:

score: 0
Accepted
time: 28ms
memory: 3380kb

input:

5 1 5

output:

1

result:

ok 1 number(s): "1"

Test #13:

score: 0
Accepted
time: 33ms
memory: 3380kb

input:

1 4 4

output:

1

result:

ok 1 number(s): "1"

Test #14:

score: 0
Accepted
time: 32ms
memory: 3380kb

input:

2 2 4

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 32ms
memory: 3380kb

input:

4 1 4

output:

1

result:

ok 1 number(s): "1"

Test #16:

score: 0
Accepted
time: 29ms
memory: 3464kb

input:

1 3 3

output:

1

result:

ok 1 number(s): "1"

Test #17:

score: 0
Accepted
time: 33ms
memory: 3380kb

input:

2 2 3

output:

4

result:

ok 1 number(s): "4"

Test #18:

score: 0
Accepted
time: 32ms
memory: 3376kb

input:

3 1 3

output:

1

result:

ok 1 number(s): "1"

Test #19:

score: 0
Accepted
time: 32ms
memory: 3492kb

input:

1 2 2

output:

1

result:

ok 1 number(s): "1"

Test #20:

score: 0
Accepted
time: 33ms
memory: 3376kb

input:

2 1 2

output:

1

result:

ok 1 number(s): "1"

Test #21:

score: 0
Accepted
time: 33ms
memory: 3504kb

input:

2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #22:

score: 0
Accepted
time: 33ms
memory: 3464kb

input:

1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #23:

score: 0
Accepted
time: 29ms
memory: 3408kb

input:

1 2 1

output:

1

result:

ok 1 number(s): "1"

Test #24:

score: 0
Accepted
time: 46ms
memory: 3376kb

input:

2 1 1

output:

1

result:

ok 1 number(s): "1"

Test #25:

score: 0
Accepted
time: 29ms
memory: 3448kb

input:

1000000000 1000000000 5

output:

709563207

result:

ok 1 number(s): "709563207"

Test #26:

score: 0
Accepted
time: 33ms
memory: 3376kb

input:

1000000000 1000000000 4

output:

966434087

result:

ok 1 number(s): "966434087"

Test #27:

score: 0
Accepted
time: 32ms
memory: 3376kb

input:

1000000000 1000000000 3

output:

566309320

result:

ok 1 number(s): "566309320"

Test #28:

score: 0
Accepted
time: 29ms
memory: 3452kb

input:

1000000000 1000000000 2

output:

3511292

result:

ok 1 number(s): "3511292"

Test #29:

score: 0
Accepted
time: 29ms
memory: 3380kb

input:

1000000000 1000000000 1

output:

1

result:

ok 1 number(s): "1"

Test #30:

score: 0
Accepted
time: 32ms
memory: 3500kb

input:

1 1000000000 5

output:

206661581

result:

ok 1 number(s): "206661581"

Test #31:

score: 0
Accepted
time: 28ms
memory: 3484kb

input:

1000000000 1 5

output:

206661581

result:

ok 1 number(s): "206661581"

Test #32:

score: 0
Accepted
time: 32ms
memory: 3376kb

input:

1 1000000000 4

output:

243529510

result:

ok 1 number(s): "243529510"

Test #33:

score: 0
Accepted
time: 32ms
memory: 3500kb

input:

1000000000 1 4

output:

243529510

result:

ok 1 number(s): "243529510"

Test #34:

score: 0
Accepted
time: 32ms
memory: 3412kb

input:

1 1000000000 3

output:

854524156

result:

ok 1 number(s): "854524156"

Test #35:

score: 0
Accepted
time: 33ms
memory: 3464kb

input:

1000000000 1 3

output:

854524156

result:

ok 1 number(s): "854524156"

Test #36:

score: 0
Accepted
time: 32ms
memory: 3420kb

input:

1 1000000000 2

output:

1755646

result:

ok 1 number(s): "1755646"

Test #37:

score: 0
Accepted
time: 31ms
memory: 3396kb

input:

1000000000 1 2

output:

1755646

result:

ok 1 number(s): "1755646"

Test #38:

score: 0
Accepted
time: 32ms
memory: 3468kb

input:

1 1000000000 1

output:

1

result:

ok 1 number(s): "1"

Test #39:

score: 0
Accepted
time: 28ms
memory: 3512kb

input:

1000000000 1 1

output:

1

result:

ok 1 number(s): "1"

Test #40:

score: 0
Accepted
time: 28ms
memory: 3452kb

input:

998244353 998244353 5

output:

104

result:

ok 1 number(s): "104"

Test #41:

score: 0
Accepted
time: 32ms
memory: 3444kb

input:

998244353 998244353 2

output:

998244351

result:

ok 1 number(s): "998244351"

Test #42:

score: 0
Accepted
time: 29ms
memory: 3376kb

input:

998244353 998244353 3

output:

6

result:

ok 1 number(s): "6"

Test #43:

score: 0
Accepted
time: 33ms
memory: 3380kb

input:

998244353 998244353 4

output:

998244330

result:

ok 1 number(s): "998244330"

Test #44:

score: 0
Accepted
time: 32ms
memory: 3444kb

input:

998244353 998244353 1

output:

1

result:

ok 1 number(s): "1"

Test #45:

score: 0
Accepted
time: 29ms
memory: 3464kb

input:

167959139 481199252 5

output:

636943179

result:

ok 1 number(s): "636943179"

Test #46:

score: 0
Accepted
time: 33ms
memory: 3468kb

input:

641009859 54748096 4

output:

21254172

result:

ok 1 number(s): "21254172"

Test #47:

score: 0
Accepted
time: 32ms
memory: 3444kb

input:

524125987 923264237 5

output:

806978440

result:

ok 1 number(s): "806978440"

Test #48:

score: 0
Accepted
time: 33ms
memory: 3372kb

input:

702209411 496813081 4

output:

567318593

result:

ok 1 number(s): "567318593"

Test #49:

score: 0
Accepted
time: 32ms
memory: 3520kb

input:

585325539 365329221 5

output:

135702788

result:

ok 1 number(s): "135702788"

Test #50:

score: 0
Accepted
time: 33ms
memory: 3444kb

input:

58376259 643910770 4

output:

906285669

result:

ok 1 number(s): "906285669"

Test #51:

score: 0
Accepted
time: 29ms
memory: 3376kb

input:

941492387 72235422 3

output:

984446484

result:

ok 1 number(s): "984446484"

Test #52:

score: 0
Accepted
time: 29ms
memory: 3420kb

input:

824608515 940751563 4

output:

714960410

result:

ok 1 number(s): "714960410"

Test #53:

score: 0
Accepted
time: 32ms
memory: 3372kb

input:

2691939 514300407 2

output:

516992344

result:

ok 1 number(s): "516992344"

Test #54:

score: 0
Accepted
time: 32ms
memory: 3412kb

input:

802030518 598196518 2

output:

401982681

result:

ok 1 number(s): "401982681"

Test #55:

score: 0
Accepted
time: 29ms
memory: 3520kb

input:

685146646 26521171 5

output:

359577836

result:

ok 1 number(s): "359577836"

Test #56:

score: 0
Accepted
time: 32ms
memory: 3444kb

input:

863230070 895037311 4

output:

615300281

result:

ok 1 number(s): "615300281"

Test #57:

score: 0
Accepted
time: 32ms
memory: 3504kb

input:

41313494 468586155 5

output:

965938269

result:

ok 1 number(s): "965938269"

Test #58:

score: 0
Accepted
time: 32ms
memory: 3452kb

input:

219396918 747167704 4

output:

53928649

result:

ok 1 number(s): "53928649"

Test #59:

score: 0
Accepted
time: 33ms
memory: 3508kb

input:

102513046 615683844 5

output:

875740368

result:

ok 1 number(s): "875740368"

Test #60:

score: 0
Accepted
time: 29ms
memory: 3456kb

input:

985629174 189232688 4

output:

219741272

result:

ok 1 number(s): "219741272"

Test #61:

score: 0
Accepted
time: 33ms
memory: 3444kb

input:

458679894 912524637 5

output:

941073341

result:

ok 1 number(s): "941073341"

Test #62:

score: 0
Accepted
time: 29ms
memory: 3452kb

input:

341796022 486073481 5

output:

845467585

result:

ok 1 number(s): "845467585"

Test #63:

score: 0
Accepted
time: 51ms
memory: 3416kb

input:

519879446 764655030 4

output:

706045468

result:

ok 1 number(s): "706045468"

Test #64:

score: 0
Accepted
time: 33ms
memory: 3476kb

input:

452405440 586588704 5

output:

335640429

result:

ok 1 number(s): "335640429"

Test #65:

score: 0
Accepted
time: 33ms
memory: 3340kb

input:

335521569 160137548 4

output:

951724102

result:

ok 1 number(s): "951724102"

Test #66:

score: 0
Accepted
time: 25ms
memory: 3356kb

input:

808572289 733686393 4

output:

619610341

result:

ok 1 number(s): "619610341"

Test #67:

score: 0
Accepted
time: 32ms
memory: 3372kb

input:

691688417 162011045 5

output:

616539456

result:

ok 1 number(s): "616539456"

Test #68:

score: 0
Accepted
time: 33ms
memory: 3452kb

input:

869771841 30527185 5

output:

763472087

result:

ok 1 number(s): "763472087"

Test #69:

score: 0
Accepted
time: 33ms
memory: 3500kb

input:

752887969 604076030 4

output:

483504483

result:

ok 1 number(s): "483504483"

Test #70:

score: 0
Accepted
time: 32ms
memory: 3500kb

input:

930971393 177624874 4

output:

921062862

result:

ok 1 number(s): "921062862"

Test #71:

score: 0
Accepted
time: 32ms
memory: 3408kb

input:

109054817 751173719 5

output:

84946027

result:

ok 1 number(s): "84946027"

Test #72:

score: 0
Accepted
time: 32ms
memory: 3444kb

input:

992170945 324722563 3

output:

386957789

result:

ok 1 number(s): "386957789"

Test #73:

score: 0
Accepted
time: 29ms
memory: 3376kb

input:

170254369 48014511 4

output:

848817111

result:

ok 1 number(s): "848817111"

Test #74:

score: 0
Accepted
time: 33ms
memory: 3376kb

input:

248004555 280013594 3

output:

784895115

result:

ok 1 number(s): "784895115"

Test #75:

score: 0
Accepted
time: 29ms
memory: 3500kb

input:

131120683 148529734 5

output:

652027866

result:

ok 1 number(s): "652027866"

Test #76:

score: 0
Accepted
time: 28ms
memory: 3516kb

input:

604171403 722078578 5

output:

912747535

result:

ok 1 number(s): "912747535"

Test #77:

score: 0
Accepted
time: 29ms
memory: 3420kb

input:

487287531 295627423 5

output:

642940101

result:

ok 1 number(s): "642940101"

Test #78:

score: 0
Accepted
time: 32ms
memory: 3504kb

input:

665370955 18919371 3

output:

799728148

result:

ok 1 number(s): "799728148"

Test #79:

score: 0
Accepted
time: 32ms
memory: 3412kb

input:

843454379 297500920 4

output:

732179859

result:

ok 1 number(s): "732179859"

Test #80:

score: 0
Accepted
time: 28ms
memory: 3464kb

input:

21537803 166017060 4

output:

546398482

result:

ok 1 number(s): "546398482"

Test #81:

score: 0
Accepted
time: 32ms
memory: 3524kb

input:

904653932 739565904 5

output:

24413120

result:

ok 1 number(s): "24413120"

Test #82:

score: 0
Accepted
time: 32ms
memory: 3380kb

input:

787770060 313114749 5

output:

299104715

result:

ok 1 number(s): "299104715"

Test #83:

score: 0
Accepted
time: 32ms
memory: 3376kb

input:

260820780 181630889 5

output:

929524647

result:

ok 1 number(s): "929524647"

Test #84:

score: 0
Accepted
time: 33ms
memory: 3512kb

input:

43603670 268405779 5

output:

811242775

result:

ok 1 number(s): "811242775"

Test #85:

score: 0
Accepted
time: 32ms
memory: 3464kb

input:

221687094 136921920 5

output:

381700361

result:

ok 1 number(s): "381700361"

Test #86:

score: 0
Accepted
time: 32ms
memory: 3420kb

input:

399770518 710470764 5

output:

13710244

result:

ok 1 number(s): "13710244"

Test #87:

score: 0
Accepted
time: 32ms
memory: 3380kb

input:

282886646 284019609 5

output:

186074064

result:

ok 1 number(s): "186074064"

Test #88:

score: 0
Accepted
time: 31ms
memory: 3364kb

input:

460970070 857568453 5

output:

871930088

result:

ok 1 number(s): "871930088"

Test #89:

score: 0
Accepted
time: 32ms
memory: 3416kb

input:

639053494 285893105 5

output:

381113127

result:

ok 1 number(s): "381113127"

Test #90:

score: 0
Accepted
time: 32ms
memory: 3384kb

input:

817136918 154409246 5

output:

904298071

result:

ok 1 number(s): "904298071"

Test #91:

score: 0
Accepted
time: 33ms
memory: 3376kb

input:

700253046 727958090 5

output:

722840722

result:

ok 1 number(s): "722840722"

Test #92:

score: 0
Accepted
time: 33ms
memory: 3440kb

input:

583369174 301506934 5

output:

4601844

result:

ok 1 number(s): "4601844"

Test #93:

score: 0
Accepted
time: 33ms
memory: 3440kb

input:

56419894 875055779 5

output:

396259549

result:

ok 1 number(s): "396259549"

Test #94:

score: 0
Accepted
time: 32ms
memory: 3496kb

input:

134170081 256797965 5

output:

976322422

result:

ok 1 number(s): "976322422"

Test #95:

score: 0
Accepted
time: 29ms
memory: 3412kb

input:

998244354 998244354 2

output:

0

result:

ok 1 number(s): "0"

Test #96:

score: 0
Accepted
time: 33ms
memory: 3380kb

input:

5 5 5

output:

3474

result:

ok 1 number(s): "3474"