QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#393146#7185. Poor StudentsqwqUwU_WA 2ms4208kbC++202.3kb2024-04-18 10:59:562024-04-18 10:59:57

Judging History

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

  • [2024-04-18 10:59:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4208kb
  • [2024-04-18 10:59:56]
  • 提交

answer

// clang-format off
#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
mt19937 gen(time(0));
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; typedef pair<ll,int> pli; typedef pair<ll,ll> pll; typedef pair<int,ll> pil;
inline ll read(){
	ll x=0,f=1,c=getchar();
	while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
const int mod=998244353;
inline int fp(int x,ll p=mod-2,int m=mod,int res=1){
	for(;p;p>>=1){if(p&1)res=1ll*res*x%m;x=1ll*x*x%m;}
	return res;
}
const int N=5e4+3;
const int K=10;
priority_queue<pii,vector<pii>,greater<pii>>q1[K*K],q2[K];
// clang-format on
int n,m,c[N][K],a[K],mh[N];
ll ans,f[K][K],pre[K],dis[K];
inline void add(int i,int j){
	if(~mh[i])++a[mh[i]];
	--a[mh[i]=j];
	rep(k,0,m-1)if(k!=j)q1[j*m+k].push(P(c[i][k]-c[i][j],i));
}
int main() {
    //freopen("data.in", "r", stdin);
    // freopen(".in","r",stdin);
    // freopen("myans.out","w",stdout);
	n=read(),m=read();
	rep(i,1,n)rep(j,0,m-1)c[i][j]=read();
	rep(j,0,m-1){
		a[j]=read();
		rep(i,1,n)q2[j].push(P(c[i][j],i));
	}
	rep(i,1,n)mh[i]=-1;
	rep(_,1,n){
		rep(j,0,m-1){
			rep(k,0,m-1)if(k!=j){
				int t=k*m+j;
				while(!q1[t].empty() && mh[q1[t].top().se]!=k)q1[t].pop();
				f[j][k]=q1[t].empty()?1e15:q1[t].top().fi;
			}
		}
		static bool inq[K];queue<int>q;
		rep(j,0,m-1){
			pre[j]=0;
			if(a[j])dis[j]=0,q.push(j),inq[j]=1;
			else dis[j]=1e15,inq[j]=0;
		}
		while(!q.empty()){
			int u=q.front();q.pop();inq[u]=0;
			rep(j,0,m-1)if(j!=u && dis[j] > dis[u] + f[u][j]){
				dis[j] = dis[u] + f[u][j];pre[j]=u;
				if(!inq[j])inq[j]=1,q.push(j);
			}
		}
		ll mn=1e15;int lp,rp;
		rep(j,0,m-1){
			while(!q2[j].empty() && ~mh[q2[j].top().se])q2[j].pop();
			int i=q2[j].top().se;
			if(c[i][j] + dis[j] < mn){
				mn = dis[j] + c[i][j];
				lp=i,rp=j;
			}
		}
		ans += mn;
		for(int u=rp;pre[u];u=pre[u]){
			int t=u*m+pre[u];
			add(q1[t].top().se,pre[u]);
		}
		add(lp,rp);
	}
	cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

output:

12

result:

ok answer is '12'

Test #2:

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

input:

3 3
1 2 3
2 4 6
6 5 4
1 1 1

output:

8

result:

ok answer is '8'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 4208kb

input:

1000 10
734 303 991 681 755 155 300 483 702 442
237 256 299 675 671 757 112 853 759 233
979 340 288 377 718 199 935 666 576 842
537 363 592 349 494 961 864 727 84 813
340 78 600 492 118 421 478 925 552 617
517 589 716 7 928 638 258 297 706 787
266 746 913 978 436 859 701 951 137 44
815 336 471 720 2...

output:

91310

result:

wrong answer expected '92039', found '91310'