QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408055#8285. Shell Sortlight_ink_dots#WA 1ms4024kbC++141.9kb2024-05-09 17:06:542024-05-09 17:06:56

Judging History

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

  • [2024-05-09 17:06:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4024kb
  • [2024-05-09 17:06:54]
  • 提交

answer

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

int main() {
    static const long long mod = 1000000007;
    static const int maxn = 30, maxm = 10;
    int n, m;
    static int d[maxm], msk[maxm][maxn];
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) scanf("%d", d + i);
    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++) {
            int r = j % d[i], x = 0;
            while (r < n) x ^= 1 << r, r += d[i];
            msk[i][j] = x;
        }
    struct node {
        int mx;
        long long cnt;
        inline node operator+(const node rhs) const {
            return { max(mx, rhs.mx), ((mx >= rhs.mx) * cnt + (rhs.mx >= mx) * rhs.cnt) % mod };
        }
    };
    function<node(const vector<int>&)> dfs = [&dfs, n, m](const vector<int>& v) {
        static unordered_map<int, node> dp;
        if (v[0] == (1 << n) - 1)
            return (node){ 0, 1 };
        if (dp.count(v[0]))
            return dp[v[0]];
        node ret = { 0, 0 };
        for (int i = 0; i < d[0]; i++) {
            int p = i + __builtin_popcount(v[0] & msk[0][i]) * d[0];
            if (p >= n)
                continue;
            int cnt = 0;
            auto nxt = v;
            nxt[0] ^= 1 << p;
            for (int r = 1; r < m; r++) {
                int s = nxt[r - 1] & msk[r][p];
                cnt += __builtin_popcount(s >> p) - 1;
                p = p % d[r] + __builtin_popcount(s) * d[r];
                nxt[r] ^= 1 << p;
            }
            node cur = dfs(nxt);
            cur.mx += cnt, ret = ret + cur;
        }
        return dp[v[0]] = ret;
    };
    int cnt = 0;
    for (int i = 0; i < d[0]; i++) {
        int pop = __builtin_popcount(msk[0][i]);
        cnt += pop * (pop - 1) >> 1;
    }
    vector<int> v(m);
    node ans = dfs(v);
    ans.mx += cnt, printf("%d %lld\n", ans.mx, ans.cnt);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 4024kb

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3776kb

input:

5 4
5 4 2 1

output:

2 0

result:

wrong answer 1st numbers differ - expected: '6', found: '2'