QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#385875 | #6846. Wiring Engineering | Tx_Lcy | RE | 20ms | 76496kb | C++14 | 4.1kb | 2024-04-11 09:24:31 | 2024-04-11 09:24:31 |
Judging History
answer
//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define chkmax(x,y) (x=max(x,y))
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
int const N=105;
int n,q,u[N],v[N],w[N][N],a[N],b[N],c[N],d[N],ans[N];
int dp1[N][N][N][2][2],dp2[N][N][N][2][2];
inline void work(int l,int r,int x,int y,vector<int>id){
if (l>r || x>y || !id.size()) return;
// if (r-l+1>=y-x+1){
int md=(l+r)>>1;
vector<int>L,R,M;
for (auto i:id)
if (b[i]<md) L.push_back(i);
else if (a[i]>md) R.push_back(i);
else M.push_back(i);
// cerr<<l<<' '<<r<<' '<<x<<' '<<y<<" nw\n";
rep(tp,0,1){
//tp -> [l,md-1] 与 [md,r] 选择区间是否有交
//[md,i]
memset(dp1,-0x3f,sizeof(dp1));
rep(L,x-1,y+1) dp1[md-1][L][L-1][0][0]=0;
rep(i,md,r){
rep(L,x,y) rep(R,L-1,y) rep(s,0,1) rep(t,0,1){
//加入一个 i,i 不与 R 匹配
chkmax(dp1[i][L][R][0][t],dp1[i-1][L][R][s][t]);
//加入一个 i,i 与 R 匹配
if (L<=R) chkmax(dp1[i][L][R][1][1],dp1[i-1][L][R][s][t]-u[i]-(!t)*v[R]+w[i][R]);
//加入一个 R,i 不与 R 匹配
if (L<=R) chkmax(dp1[i][L][R][s][0],dp1[i][L][R-1][s][t]);
//加入一个 R,i 与 R 匹配
if (L<=R) chkmax(dp1[i][L][R][1][1],dp1[i][L][R-1][s][t]-(!s)*u[i]-v[R]+w[i][R]);
}
}
// rep(i,md,r)
// rep(L,x,y) rep(R,L-1,y) rep(s,0,1) rep(t,0,1)
// cerr<<i<<' '<<L<<' '<<R<<' '<<s<<' '<<t<<' '<<dp1[i][L][R][s][t]<<" error?\n";
// exit(0);
memset(dp2,-0x3f,sizeof(dp2));
rep(L,x-1,y+1) dp2[md][L][L-1][0][0]=0;
per(i,md-1,l){
per(L,y,x) rep(R,L-1,y) rep(s,0,1) rep(t,0,1){
//加入一个 i
chkmax(dp2[i][L][R][0][t],dp2[i+1][L][R][s][t]);
//加入一个 i,i 与 L 匹配
if (L<=R) chkmax(dp2[i][L][R][1][1],dp2[i+1][L][R][s][t]-u[i]-(!t)*v[L]+w[i][L]);
//加入一个 L,i 不与 L 匹配
if (L<=R){
if (L==R && tp);
else chkmax(dp2[i][L][R][s][0],dp2[i][L+1][R][s][t]);
}
//加入一个 L,i 与 L 匹配
if (L<=R) chkmax(dp2[i][L][R][1][1],dp2[i][L+1][R][s][t]-(!s)*u[i]-v[L]+w[i][L]);
}
}
for (auto i:M){
// cerr<<i<<' '<<tp<<' '<<l<<','<<r<<' '<<x<<','<<y<<" sol?\n";
rep(k,c[i],d[i]){
int lef=-1e18,rig=-1e18;
rep(s,0,1) rep(t,0,1){
lef=max(lef,dp2[a[i]][c[i]][k-(!tp)][s][t]),
rig=max(rig,dp1[b[i]][k][d[i]][s][t]);
// cerr<<a[i]<<' '<<c[i]<<','<<k-(!tp)<<' '<<s<<','<<t<<' '<<dp2[a[i]][c[i]][k-(!tp)][s][t]<<" left\n";
// cerr<<b[i]<<' '<<k<<','<<d[i]<<' '<<s<<','<<t<<' '<<dp1[b[i]][k][d[i]][s][t]<<" right\n";
}
// cerr<<i<<' '<<k<<' '<<lef<<' '<<rig<<' '<<tp*v[k]<<" ohhhh\n";
ans[i]=max(ans[i],lef+rig+tp*v[k]);
}
}
}
work(l,md-1,x,y,L),work(md+1,r,x,y,R);
// }
}
inline void solve(){
cin>>n>>q;
rep(i,1,n) cin>>u[i];
rep(i,1,n) cin>>v[i];
rep(i,1,n) rep(j,1,n) cin>>w[i][j];
vector<int>id;
rep(i,1,q) cin>>a[i]>>b[i]>>c[i]>>d[i],id.push_back(i);
work(1,n,1,n,id);
rep(i,1,q) cout<<ans[i]<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while (t--) solve();
cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<" s\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 20ms
memory: 76496kb
input:
3 4 1 2 1 2 1 2 1 2 3 4 5 6 3 2 1 1 3 1 3 2 3 1 2 1 1 2 3 1 2 2 3
output:
8 5 1 7
result:
ok 4 lines
Test #2:
score: -100
Runtime Error
input:
24 90000 8793 8115 9643 2814 6394 7070 3822 4788 6737 6506 2901 4772 5347 5050 3493 2803 584 2544 3834 678 9891 2958 5475 522 9057 3674 3163 6433 5937 8480 4815 1201 5509 1303 4151 8190 6229 9339 9765 3011 2256 3682 8442 3641 2268 5609 4948 9632 5872 4006 7690 2611 5381 6184 9483 8527 8248 960 8124 ...