QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#606678#8936. Team ArrangementUESTC_DECAYALI#WA 1ms4116kbC++202.8kb2024-10-03 11:27:322024-10-03 11:27:33

Judging History

This is the latest submission verdict.

  • [2024-10-03 11:27:33]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 4116kb
  • [2024-10-03 11:27:32]
  • Submitted

answer

#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#define RI register int
#define CI const int&
using namespace std;
const int N=65,INF=1e9;
int n,cnt,l[N],r[N],w[N],ans=-INF; vector <int> vec;
namespace Network_Flow
{
    const int NN=150,MM=1e6+5;
    struct edge
    {
        int to,nxt,v;
    }e[MM<<1]; int cnt,head[NN],cur[NN],dep[NN],s,t;
    inline void addedge(CI x,CI y,CI z)
    {
        e[++cnt]=(edge){y,head[x],z}; head[x]=cnt;
        e[++cnt]=(edge){x,head[y],0}; head[y]=cnt;
    }
    #define to e[i].to
    inline bool BFS(void)
    {
        memset(dep,0,(t+1)*sizeof(int)); dep[s]=1;
        queue <int> q; q.push(s);
        while (!q.empty())
        {
            int now=q.front(); q.pop();
            for (RI i=head[now];i;i=e[i].nxt)
            if (e[i].v&&!dep[to]) dep[to]=dep[now]+1,q.push(to);
        }
        return dep[t];
    }
    inline int DFS(CI now,CI tar,int dis)
    {
        if (now==tar) return dis; int ret=0;
        for (RI& i=cur[now];i&&dis;i=e[i].nxt)
        if (e[i].v&&dep[to]==dep[now]+1)
        {
            int dist=DFS(to,tar,min(dis,e[i].v));
            if (!dist) dep[to]=INF;
            dis-=dist; ret+=dist; e[i].v-=dist; e[i^1].v+=dist;
            if (!dis) return ret;
        }
        if (!ret) dep[now]=INF; return ret;
    }
    #undef to
    inline int Dinic(int ret=0)
    {
        while (BFS()) memcpy(cur,head,(t+1)*sizeof(int)),ret+=DFS(s,t,INF); return ret;
    }
    inline void clear(void)
    {
        cnt=1; memset(head,0,(t+1)*sizeof(int));
    }
};
using namespace Network_Flow;
inline int calc(vector <int>& vec)
{
    // for (auto x:vec) printf("%d ",x); putchar('\n');
    int res=0; for (auto x:vec) res+=w[x];
    if (res<ans) return -INF;
    s=n+vec.size()+1; t=s+1; clear();
    for (RI i=1;i<=n;++i) addedge(s,i,1);
    for (RI i=0;i<vec.size();++i) addedge(n+1+i,t,vec[i]);
    for (RI i=1;i<=n;++i)
    {
        int lp=-1,rp=-1;
        for (RI j=0;j<vec.size();++j)
        if (vec[j]>=l[i]) { lp=j+1; break; }
        for (RI j=(int)vec.size()-1;j>=0;--j)
        if (vec[j]<=r[i]) { rp=j+1; break; }
        if (lp==-1||rp==-1) return -INF;
        for (RI j=lp;j<=rp;++j) addedge(i,n+j,1);
    }
    if (Dinic()!=n) return -INF;
    return res;
}
inline void DFS(vector <int>& vec,CI sum,CI lst)
{
    if (sum==n) return (void)(ans=max(ans,calc(vec)));
    for (RI i=min(lst,n-sum);i>=1;--i) vec.push_back(i),DFS(vec,sum+i,i),vec.pop_back();
}
int main()
{
    scanf("%d",&n);
    for (RI i=1;i<=n;++i) scanf("%d%d",&l[i],&r[i]);
    for (RI i=1;i<=n;++i) scanf("%d",&w[i]);
    DFS(vec,0,n);
    //printf("count  = %d\n",cnt);
    if (ans==-INF) puts("impossible"); else printf("%d",ans);
    return 0;
}

详细

Test #1:

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

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

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

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

7

result:

wrong answer 1st lines differ - expected: '6', found: '7'