QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569971#9315. Rainbow Bracket SequenceVegetable_DogWA 1ms3832kbC++233.1kb2024-09-17 12:59:312024-09-17 12:59:31

Judging History

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

  • [2024-09-17 12:59:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3832kb
  • [2024-09-17 12:59:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int ll
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define Rep(i,a,b) for(int i=a;i>=(b);i--)
#define pb push_back
#define mid(l,r) (l+(r-l)/2)
#define MID(l,r) (l+(r-l+1)/2)
#define MEM(a,x) memset(a,x,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define lson(k) (k<<1)
#define rson(k) (k<<1|1)
#define lowbit(x) ((x)&-(x))
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef __int128_t i128;
const int mod=1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int qpow(int a,int b,int P=mod){int res=1;a%=P;assert(b>=0);for(;b;b>>=1){if(b&1)res=1ll*res*a%P;a=1ll*a*a%P;}return res;}
// Think twice,code once
const int N=1005;
const int inf=1e15;
struct Edge{
    int from,to,cap,flow,cost;
    Edge(int u,int v,int c,int f,int w):from(u),to(v),cap(c),flow(f),cost(w){}
};
struct MCMF{
    int n,m;
    vector<Edge>edges;
    vector<int>G[N];
    int inq[N];
    int d[N];
    int a[N];
    int p[N];
    void init(int n){
        this->n=n;
        edges.clear();
        rep(i,0,n)G[i].clear();
    }
    void add(int u,int v,int c,int w){
        edges.push_back(Edge(u,v,c,0,w));
        edges.push_back(Edge(v,u,0,0,-w));
        m=edges.size();
        G[u].push_back(m-2);
        G[v].push_back(m-1);
    }
    bool Bellman_Ford(int s,int t,int&flow,int&cost){
        rep(i,0,n)d[i]=inf,inq[i]=0;
        queue<int>q;
        d[s]=0,a[s]=1,p[s]=0,inq[s]=1;
        q.push(s);
        while(!q.empty()){
            int x=q.front();q.pop();
            inq[x]=0;
            rep(i,0,G[x].size()){
                Edge&e=edges[G[x][i]];
                if(e.cap>e.flow&&d[e.to]>d[x]+e.cost){
                    d[e.to]=d[x]+e.cost;
                    a[e.to]=min(a[x],e.cap-e.flow);
                    p[e.to]=G[x][i];
                    if(!inq[e.to])q.push(e.to),inq[e.to]=1;
                }
            }
        }
        if(d[t]==inf)return 0;
        flow+=a[t];
        cost+=d[t]*a[t];
        for(int u=t;u!=s;u=edges[p[u]].from){
            edges[p[u]].flow+=a[t];
            edges[p[u]^1].flow-=a[t];
        }
        return 1;
    }
    int MincostFlow(int s,int t,int&cost){
        int flow=0;cost=0;
        while(Bellman_Ford(s,t,flow,cost));
        return flow;
    }
}g;
void solve(){
    int n,m;cin>>n>>m;
    vi l(m),cs(m),c(2*n),v(2*n);
    rep(i,0,m)cin>>l[i];
    rep(i,0,2*n)cin>>c[i],cs[--c[i]]++;
    int vs=0;
    rep(i,0,2*n)cin>>v[i],vs+=v[i];
    int s=2*n+m,t=s+1;
    g.init(t+1);
    g.add(s,2*n-1,n,0);
    rep(i,0,2*n-1)g.add(i+1,i,(i+1)/2,0);
    rep(i,0,2*n)g.add(i,2*n+c[i],1,v[i]);
    rep(i,0,m)g.add(2*n+i,t,max(0ll,cs[i]-l[i]),0);
    int cost;
    if(g.MincostFlow(s,t,cost)!=n)cout<<-1<<endl;
    else cout<<vs-cost<<endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

2
3 2
1 2
1 2 2 2 1 2
3 1 4 2 2 1
3 2
2 2
1 2 2 2 1 2
3 1 4 2 2 1

output:

9
-1

result:

ok 2 number(s): "9 -1"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3832kb

input:

50
8 6
0 2 2 0 3 1
3 5 1 1 5 3 5 2 3 2 2 1 2 2 4 6
998133227 879226371 59632864 356493387 62611196 827258251 296576565 204244054 812713672 780267148 614679390 447700005 102067050 544546349 116002772 761999375
1 1
1
1 1
343766215 374461155
3 1
2
1 1 1 1 1 1
796323508 303640854 701432076 853325162 610...

output:

-1
343766215
2351080746
3426965219
-1
1497027962
1351561190
2539318868
1013080942
4656646546
-1
-1
2231197660
2719131728
3983627641
4712174168
3121174891
1046749330
6115214757
3920988203
3914858167
3902088946
-1
2566553992
5268471900
5977120748
7505501534
-1
5054275471
1467678317
883992368
104456298...

result:

wrong answer 6th numbers differ - expected: '-1', found: '1497027962'