1 条题解

  • 0
    @ 2023-3-10 10:11:52

    纯暴力 = 25 分

    建议在OJ上评测时加上 assert,爱护评测机。。

    比赛时那就让程序撒丫子跑,说不定就多过几个点。

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXK = 4;
    const int MAXN = 50000;
    int T, k;
    int n, ans;
    int p[MAXN + 5];
    int a[MAXK + 5][MAXN + 5];
    int cMax[MAXK + 5], cMin[MAXK + 5];
    void dfs(int now)
    {
        if (now > n)
        {
            for (int i = 0; i <= k - 1; i++)
                cMax[i] = cMin[i] = a[i][1];
            for (int i = 2; i <= n; i++)
                for (int j = 0; j < k; j++)
                    cMax[j] = max(cMax[j], a[(j + p[i]) % k][i]),
                    cMin[j] = min(cMin[j], a[(j + p[i]) % k][i]);
            /*
            cout << "======\n";
            for(int i=1;i<=n;i++)
                cout<<p[i]<<" ";
                cout<<"---\n";
            for (int j = 0; j <= k - 1; j++)
            {
                cout<<cMax[j]<<":"<<cMin[j]<<" ";
                for (int i = 1; i <= n; i++)
                {
                    cout << a[(j + p[i]) % k][i] << " ";
                }
                cout << "\n";
            }
            */
            int now = 0;
            for (int i = 0; i < k; i++)
                now = max(now, cMax[i] - cMin[i]);
            // cout << "= " << now << "\n";
            ans = min(ans, now);
            return;
        }
        for (int i = 0; i < k; i++)
        {
            p[now] = i;
            dfs(now + 1);
        }
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> T >> k;
        while (T--)
        {
            cin >> n;
            assert(k == 1 || n <= 20);
            for (int j = 0; j <= k - 1; j++)
                for (int i = 1; i <= n; i++)
                    cin >> a[j][i];
            // a[j][1] 固定,a[j][2~n] 枚举所有可能性
            // 第 i 个拨圈的第 j 行为 a[(j + p[i]) % k][i]
            p[1] = 0;
            ans = 30005;
            dfs(2);
            cout << ans << "\n";
        }
        return 0;
    }
    
    • 1

    信息

    ID
    1237
    时间
    2500ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    43
    已通过
    1
    上传者