QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621530#9422. Two-star ContestzhoudashuaiRE 1ms3608kbC++142.4kb2024-10-08 15:10:392024-10-08 15:10:40

Judging History

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

  • [2024-10-08 15:10:40]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3608kb
  • [2024-10-08 15:10:39]
  • 提交

answer

#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<set> 
#include<stack>
#include<bitset>
#include<unordered_map>
#include<iomanip>
#include<cassert>
#define fi first
#define se second
#define endl '\n'
#define pb push_back
#define ep emplace_back 
#define debug(x) cout<<x<<'\n'
#define RES cout<<res<<'\n'
#define ANS cout<<ans<<'\n'
#define YES	cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes	cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define me(a,x) memset(a,x,sizeof(a))
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)
#define r23 cout<<233<<endl;return;
#define int long long 
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<PII,int> PIII;
typedef unsigned long long ull;
const int N=4e5+5,P=131,mod=998244353;

int n,m,k; 
struct node{
	int s,sum,cnt,id;
};
bool cmp(node a,node b){
	if(a.s==b.s)return a.sum<b.sum;
	return a.s<b.s;
}
void solve(){
	cin>>n>>m>>k;
	int f=1;
	struct node a[n+3];
	int g[m+3][m+3];
	L(i,1,n){
		cin>>a[i].s;
		int sum=0,cnt=0;
		L(j,1,m){
			cin>>g[i][j];
			if(g[i][j]==-1)cnt++;
			else sum+=g[i][j];
		}
		a[i].sum=sum,a[i].id=i,a[i].cnt=cnt;
	}
	sort(a+1,a+1+n,cmp);
	int ma=a[1].sum;
	int pre=-1;
	L(i,1,m){
		if(g[a[1].id][i]==-1)g[a[1].id][i]=0;
	}
	L(i,2,n){
		if(a[i].s==a[i-1].s){
			ma=max(ma,a[i].sum);
			if(a[i].sum>pre){
				L(j,1,m){
					if(g[a[i].id][j]==-1)g[a[i].id][j]=0;
				}
			}else{
				int nd=pre-a[i].sum+1;
				if(a[i].cnt*k<nd){
					f=0;break;
				} else{
					L(j,1,m){
						if(g[a[i].id][j]==-1){
							g[a[i].id][j]=min(nd,k);nd-=k;
							if(nd<=0)nd=0;
						}
					}
				}
			}
			L(j,1,m){
				if(g[a[i].id][j]==-1)g[a[i].id][j]=0;
			}
		}else{
			pre=ma;
			if(a[i].sum>pre){
				ma=a[i].sum;
				L(j,1,m){
					if(g[a[i].id][j]==-1)g[a[i].id][j]=0;
				}
			}else{
				int nd=pre-a[i].sum+1;
				if(a[i].cnt*k<nd){
					f=0;break;
				} else{
					L(j,1,m){
						if(g[a[i].id][j]==-1){
							g[a[i].id][j]=min(nd,k);nd-=k;
							if(nd<=0)nd=0;
						}
					}
				}
				ma=ma+1;
			}
		}
	}
	if(!f){
		No;
	}else{
		Yes;
		L(i,1,n){
			L(j,1,m){
				cout<<g[i][j]<<' ';
			}cout<<endl;
		}
	}
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

input:

5
3 4 5
5 1 3 -1 -1
2 -1 5 -1 5
3 3 -1 -1 4
2 3 10
10000 5 0 -1
1 10 10 10
2 3 10
10 1 2 3
100 4 5 6
2 3 10
100 1 2 3
10 4 5 6
2 3 10000
100 -1 -1 -1
1 -1 -1 -1

output:

Yes
1 3 5 3 
0 5 0 5 
3 4 0 4 
No
Yes
1 2 3 
4 5 6 
No
Yes
1 0 0 
0 0 0 

result:

ok ok 5 cases (5 test cases)

Test #2:

score: -100
Runtime Error

input:

1013
3 2 1
1 -1 -1
2 0 1
3 -1 -1
4 8 96295
302790137 -1 849 -1 -1 33907 7926 9461 70117
695984050 -1 -1 56792 -1 -1 -1 19527 -1
302790137 12828 30553 40825 67577 91517 77952 55631 63781
302790137 29385 -1 -1 -1 750 -1 -1 -1
2 6 72716304
892657961 -1 -1 66436933 -1 45419040 55642613
892657961 -1 6271...

output:


result: