QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607109#8936. Team ArrangementKomorebie#RE 0ms0kbC++172.6kb2024-10-03 13:56:142024-10-03 13:56:14

Judging History

This is the latest submission verdict.

  • [2024-10-03 13:56:14]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-03 13:56:14]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define maxn 70
#define ll long long
ll w[maxn], maxx = LLONG_MIN, dp[maxn];
int n, cnt[maxn], tot, l, r;

vector<int> to[maxn];
priority_queue<int, vector<int>, greater<int> > p;

void dfs(int x, int y, ll ans)
{ // to[x] 已经入队
    priority_queue<int, vector<int>, greater<int> > p0 = p;
    priority_queue<int, vector<int>, greater<int> > p1; // 记录的是原先r的情况

    if ((p.empty() || p.top() >= y) && y >= tot && ans + w[y] > maxx)
    {
        for (int i = x + 1; i <= y; i++)
        { // 处理剩余部分全部入帐的情况
            for (int j = 0; j < to[i].size(); j++)
            {
                p.push(to[i][j]);
            }
        }
        if (p.top() >= y && p.size() == y)
        { // 全部入队了
            maxx = ans + w[y];
        }
    }
    p = p0; // 回退到都没有 选择
    for (int i = x; i * 2 <= y; i++)//保证 y-i 大于或等于 i
    {
        if (!p.empty() && p.top() < i) // 有一个 队员 没有分配 是错误 的
            break;
        if (i != x)
        {
            for (int j = 0; j < to[i].size(); j++)
            {
                p.push(to[i][j]);
            }
        } // to[x] 已经入队过了
        if(ans+dp[y-i]+w[i]>maxx){
            p1 = p;
            if (p.size() >= i)
            {
                for (int j = 1; j <= i; j++)
                {
                    p.pop();
                }
                dfs(i, y - i, ans + w[i]);
            }
            p = p1; // 回退到没有选择 i 个
        }
    }
    p = p0; // 回退到 都没有选择
    return;
}
int main()
{
    freopen("text.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> l >> r;
        for(int j=l;j<=r;j++){
            cnt[j]++;
        }
        to[l].push_back(r);
        tot = max(tot, l);
    }

    for (int i = 1; i <= n; i++)
    {
        cin >> w[i];
    }

    for(int i=1;i<=n+1;i++){
        dp[i]=INT_MIN;
    }
    dp[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j >=1; j--)
        {
            if (dp[i - j] != dp[n + 1])
                dp[i] = max(dp[i], dp[i - j] + w[j]);
        }
        if(cnt[i]==n&&n%i==0){
            maxx=max(maxx,w[i]*n/i);
        }
    }//dp用于 减枝
    for (int i = 0; i < to[1].size(); i++)
    {
        p.push(to[1][i]);
    }

    dfs(1, n, 0);
    if (maxx == LLONG_MIN)
    {
        cout << "impossible" << endl;
    }
    else
    {
        cout << maxx << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
2 3
1 2
2 2
4 5 100

output:


result: