QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751907 | #9422. Two-star Contest | endeavorHao | WA | 60ms | 51672kb | C++20 | 3.4kb | 2024-11-15 21:15:03 | 2024-11-15 21:15:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6;
struct Node
{
int rate;
vector<int>v;
int sum;
int id;
}nd[N];
bool cmp(Node x,Node y)
{
return x.rate<y.rate;
}
bool cmp2(Node x,Node y)
{
return x.id<y.id;
}
map<int,int>mp;
void solve(){
int n,m,k;
mp.clear();
cin>>n>>m>>k;
int flag=1;
for(int i=0;i<n;i++)nd[i].v.clear();
for(int i=0;i<n;i++)
{
cin>>nd[i].rate;
for(int j=0;j<m;j++)
{
int t;
cin>>t;
nd[i].v.push_back(t);
}
nd[i].id=i;
}
sort(nd,nd+n,cmp);
for(int i=0;i<n;i++)
{
int sum=0;
for(int j=0;j<m;j++)
{
if(nd[i].v[j]!=-1)sum+=nd[i].v[j];
}
nd[i].sum=sum;
}
int last=-1;
for(int i=0;i<m;i++)
if(nd[0].v[i]==-1)nd[0].v[i]=0;
mp[nd[0].rate]=nd[0].sum;
for(int i=1;i<n;i++)
{
int t=nd[i].sum-mp[nd[i-1].rate];
if(nd[i].rate!=nd[i-1].rate)
{
last=i-1;
if(t>0)
{
for(int j=0;j<m;j++)
{
if(nd[i].v[j]==-1)
nd[i].v[j]=0;
}
t=0;
}
else
{
t=abs(t);
t++;
for(int j=0;j<m;j++)
{
if(nd[i].v[j]==-1)
{
if(t>k)
{
nd[i].v[j]=k;
nd[i].sum+=k;
t-=k;
}
else
{
nd[i].v[j]=t;
nd[i].sum+=t;
t=0;
}
}
}
mp[nd[i].rate]=max(mp[nd[i].rate],nd[i].sum);
}
}
else
{
if(last==-1)
{
t=0;
for(int j=0;j<m;j++)if(nd[i].v[j]==-1)nd[i].v[j]=0;
}
else
{
t=nd[i].sum-mp[nd[last].rate];
t=abs(t);
t++;
for(int j=0;j<m;j++)
{
if(nd[i].v[j]==-1)
{
if(t>k)
{
nd[i].v[j]=k;
nd[i].sum+=k;
t-=k;
}
else
{
nd[i].v[j]=t;
nd[i].sum+=t;
t=0;
}
}
}
mp[nd[i].rate]=max(mp[nd[i].rate],nd[i].sum);
}
}
if(t)flag=0;
}
if(!flag)cout<<"No"<<endl;
else
{
sort(nd,nd+n,cmp2);
cout<<"Yes"<<endl;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<nd[i].v[j]<<" ";
}
cout<<endl;
}
}
}
signed main(){
int t;
cin>>t;
while(t--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 50672kb
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
Wrong Answer
time: 60ms
memory: 51672kb
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:
Yes 0 0 0 1 1 0 Yes 0 849 0 0 33907 7926 9461 70117 45942 0 56792 0 0 0 19527 0 12828 30553 40825 67577 91517 77952 55631 63781 29385 0 0 0 750 0 0 0 Yes 0 0 66436933 0 45419040 55642613 0 62712753 0 21765515 56544945 12385026 No Yes 9 0 0 0 3 4 0 7 25 22 15 0 0 0 0 22 0 0 6 11 13 18 5 12...
result:
wrong answer Participant cannot satisfy the constraint. (test case 1)