QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570045#9315. Rainbow Bracket SequenceLateRegistration#WA 0ms3752kbC++172.8kb2024-09-17 13:27:282024-09-17 13:27:29

Judging History

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

  • [2024-09-17 13:27:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3752kb
  • [2024-09-17 13:27:28]
  • 提交

answer

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

#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(y<x)x=y;}

#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define mem(x) memset((x),0,sizeof(x))

typedef double db;
typedef long long ll;
typedef vector<int>vi;
typedef pair<int,int>pii;

typedef unsigned u32;
typedef unsigned uint;
typedef unsigned long long u64;

namespace EK{
  static const int inf=INT_MAX;
  static const int maxN=510;
  static const int maxM=1e5+10;
  int ecnt,h[maxN];
  struct edges{
    int nxt,to,w,c;
  }E[maxM];
  void addline(int u,int v,int w,int c){
    E[++ecnt]={h[u],v,w,c},h[u]=ecnt;
    E[++ecnt]={h[v],u,0,-c},h[v]=ecnt;
  }
  bool inq[maxN];
  int S,T,fl[maxN],dis[maxN],pre[maxN];
  void gnxt(int&x){if(++x==maxN)x=0;}
  bool spfa(){
    static int Q[maxN];
    memset(dis,0x3f,sizeof dis);
    int l=0,r=1;Q[0]=S,dis[S]=0,fl[S]=inf;
    while(l!=r){
      int u=Q[l];gnxt(l),inq[u]=0;
      for(int i=h[u];i;i=E[i].nxt){
        int v=E[i].to;
        if(E[i].w&&dis[v]>dis[u]+E[i].c){
          pre[v]=i,fl[v]=min(fl[u],E[i].w),dis[v]=dis[u]+E[i].c;
          if(!inq[v]){
            Q[r]=v,inq[v]=1;if(l!=r&&dis[Q[l]]>dis[Q[r]])swap(Q[l],Q[r]);gnxt(r);
          }
        }
      }
    }
    return dis[T]<1e9;
  }
  pair<int,int>EK(){
    int w=0;int c=0;
    while(spfa()){
      w+=fl[T],c+=fl[T]*dis[T];
      for(int u=T;u!=S;u=E[pre[u]^1].to){
        E[pre[u]].w-=fl[T],E[pre[u]^1].w+=fl[T];
      }
    }
    return{w,c};
  }
}

int n;
int l[105],c[205],v[205];

void solve(){
  int m;
  cin>>n>>m;
  rep(i,1,m)cin>>l[i];
  rep(i,1,n+n)cin>>c[i];
  rep(i,1,n+n)cin>>v[i];
  
  int s=m+2*n+2*n+1,t=s+1;
  int ss=t+1,tt=ss+1;
  int sum_low=0;ll dt=0;
  
  EK::ecnt=1;
  memset(EK::h,0,sizeof EK::h);
  EK::S=ss,EK::T=tt;
  
  auto add=[&](int u,int v,int w_l,int w_r,ll c){
    EK::addline(u,v,w_r-w_l,c);
    sum_low+=w_l;
    dt+=w_l*c;
    if(w_l){
      EK::addline(ss,v,w_l,0);
      EK::addline(u,tt,w_l,0);
    }
  };
  
  rep(i,1,m)add(s,i,l[i],n,0); 
  rep(i,1,2*n)add(c[i],m+i,0,1,-v[i]);
  rep(i,1,2*n){
    add(m+i,m+2*n+i,0,1,0);
    if(i>1)add(m+2*n+i-1,m+2*n+i,i/2,n,0);
  }
  add(m+2*n+2*n,t,n,n,0);
  
  EK::addline(t,s,(int)1e9,0);
  
  auto pr=EK::EK();
//  printf("(%d %d) %lld\n",pr.first,sum_low,pr.second);
  
  if(pr.first==sum_low){
    cout<<-dt-pr.second<<endl;
  }else{
    cout<<-1<<endl;
  }
}

signed main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
  int T;cin>>T;while(T--)solve();
//  solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3732kb

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
-1943886550
-868002077
-1
-1
1351561190
-1755648428
1013080942
-1
-1
-1
-2063769636
-1575835568
-311339655
-1
-1
1046749330
1820247461
-373979093
-1
-392878350
-1
-1728413304
-1
1682153452
-1084433058
-1
759308175
1467678317
883992368
1044562986
-1
-270332793
-1
1447294256
-1832326870
-...

result:

wrong answer 3rd numbers differ - expected: '2351080746', found: '-1943886550'