QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471834#1269. New Equipmentsgrass8cow#AC ✓32ms4368kbC++171.7kb2024-07-11 09:52:592024-07-11 09:52:59

Judging History

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

  • [2024-07-11 09:52:59]
  • 评测
  • 测评结果:AC
  • 用时:32ms
  • 内存:4368kb
  • [2024-07-11 09:52:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int S,T;
#define ll long long
int c=1,head[8010],to[101000],nxt[101000],flow[101000];
ll ct[101000];
void ad(int u,int v,ll w){
	to[++c]=v,nxt[c]=head[u],flow[c]=1,ct[c]=w,head[u]=c;
	to[++c]=u,nxt[c]=head[v],flow[c]=0,ct[c]=-w,head[v]=c;
}
ll d[8010];
int pr1[8010],pr2[8010];
bool vis[8010];
const ll I=1e18;
bool spfa(){
	queue<int>q;q.push(S),vis[S]=1;
    for(int i=1;i<=T;i++)d[i]=I;
	d[S]=0;
	while(!q.empty()){
		int u=q.front();q.pop(),vis[u]=0;
		for(int i=head[u];i;i=nxt[i])if(flow[i]&&d[to[i]]>d[u]+ct[i]){
			d[to[i]]=d[u]+ct[i],pr1[to[i]]=u,pr2[to[i]]=i;
			if(!vis[to[i]])vis[to[i]]=1,q.push(to[i]);
		}
	}
	return d[T]<I;
}
ll ans;
void up(){
	ans+=d[T];
	int u=T;
	while(u!=S){
		int i=pr2[u];
		flow[i]--,flow[i^1]++,u=pr1[u];
	}
}
int n,R;
ll A[60],B[60],C[60],M[60],m,qc[10010];
void sol(){
    ans=0;
    scanf("%d%lld",&n,&m);
    R=0;
    for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld",&A[i],&B[i],&C[i]);
        if(B[i]>0)M[i]=1;
        else{
            M[i]=max((-B[i])/(A[i]*2),1ll);
            M[i]=min(M[i],m);
        }
        for(ll j=max(1ll,M[i]-n-1);j<=min(m,M[i]+n+1);j++)qc[++R]=j;
    }
    sort(qc+1,qc+R+1);R=unique(qc+1,qc+R+1)-qc-1;
    S=n+R+1,T=S+1;c=1;
    for(int i=1;i<=T;i++)head[i]=0;
    for(int i=1;i<=n;i++)ad(S,i,0);
    for(int i=1;i<=R;i++)ad(n+i,T,0);
    for(int i=1;i<=n;i++)for(ll j=max(1ll,M[i]-n-1);j<=min(m,M[i]+n+1);j++){
        int p=lower_bound(qc+1,qc+R+1,j)-qc;
        ad(i,n+p,A[i]*j*j+B[i]*j+C[i]);
    }
    ans=0;
    for(int i=1;i<=n;i++)spfa(),up(),printf("%lld ",ans);puts("");
}
int main(){
    int T;scanf("%d",&T);while(T--)sol();
} 

详细

Test #1:

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

input:

1
3 5
2 3 10
2 -3 10
1 -1 4

output:

4 15 37 

result:

ok single line: '4 15 37 '

Test #2:

score: 0
Accepted
time: 32ms
memory: 4368kb

input:

10
50 50
2 -16 79
8 -21 54
8 -1 3
1 -7 47
5 -20 89
1 -2 47
2 -10 26
10 31 28
2 -16 37
6 -16 44
2 -8 100
3 -26 65
3 -6 91
10 -33 56
2 -7 22
2 -12 74
1 -3 7
7 -30 51
1 -4 8
1 -10 62
2 -5 5
1 -3 38
7 -32 57
4 -24 65
1 -8 97
7 -28 71
5 -13 71
2 -14 49
6 -33 100
2 7 69
8 -22 38
5 -23 88
7 20 57
7 -11 83
...

output:

2 4 9 14 24 40 72 117 170 239 327 445 592 771 972 1202 1467 1772 2117 2506 2954 3461 4035 4690 5415 6223 7137 8145 9272 10499 11858 13366 15003 16798 18736 20810 23058 25517 28172 31062 34194 37566 41209 45136 49371 53924 58847 64143 69813 75884 
4 9 17 25 33 43 57 78 107 146 194 266 356 461 590 744...

result:

ok 10 lines