QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#614154 | #9422. Two-star Contest | 123adad | WA | 29ms | 4404kb | C++20 | 2.3kb | 2024-10-05 15:44:01 | 2024-10-05 15:44:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=4e5+9;
struct node
{
int id,num,sum,flag;
}s[N];
bool cmp(node x,node y)
{
if(x.num==y.num)
{
return x.sum<y.sum;
}
return x.num<y.num;
}
void solve()
{
int n,m,k;cin>>n>>m>>k;
std::vector<vector<int>> p(n+10,vector<int>(m+10));
for(int i=1;i<=n;i++)
{
cin>>s[i].num;
s[i].id=i;
s[i].sum=0;
s[i].flag=0;
for(int j=1;j<=m;j++)
{
cin>>p[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(p[i][j]==-1) s[i].flag++;
else s[i].sum+=p[i][j];
}
}
sort(s+1,s+1+n,cmp);
//for(int i=1;i<=n;i++) cout<<s[i].num<<' ';
//cout<<'\n';
for(int j=1;j<=m;j++) if(p[s[1].id][j]==-1) p[s[1].id][j]=0;
for(int i=2;i<=n;i++)
{
if(s[i].num>s[i-1].num)
{
//cout<<s[i].sum<<' '<<s[i-1].sum<<'\n';
if(s[i].sum<=s[i-1].sum)
{
if(s[i].flag==0)
{
cout<<"No\n";
return;
}
int x=s[i-1].sum-s[i].sum+1ll;
//cout<<x<<'\n';
if(x<=k)
{
for(int j=1;j<=m;j++)
{
if(p[s[i].id][j]==-1)
{
p[s[i].id][j]=x;
s[i].sum+=x;
break;
}
}
for(int j=1;j<=m;j++)
{
if(p[s[i].id][j]==-1)p[s[i].id][j]=0;
}
}
else
{
int xx=x/k,cnt=0;
if(xx>s[i].flag)
{
cout<<"No\n";
return;
}
for(int j=1;j<=m;j++)
{
if(p[s[i].id][j]==-1)
{
if(xx) p[s[i].id][j]=k,s[i].sum+=k;
xx--;cnt++;
if(!xx) break;
}
}
if(x%k!=0)
{
if(cnt>=s[i].flag)
{
cout<<"No\n";
return;
}
for(int j=1;j<=m;j++)
{
if(p[s[i].id][j]==-1)
{
p[s[i].id][j]=(x%k),s[i].sum+=(x%k);
break;
}
}
}
for(int j=1;j<=m;j++)
{
if(p[s[i].id][j]==-1)p[s[i].id][j]=0;
}
}
}
else for(int j=1;j<=m;j++) if(p[s[i].id][j]==-1)p[s[i].id][j]=0;
}
else for(int j=1;j<=m;j++) if(p[s[i].id][j]==-1)p[s[i].id][j]=0;
}
cout<<"Yes\n";
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<p[i][j]<<' ';
}
cout<<'\n';
}
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _=1;cin>>_;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 29ms
memory: 4404kb
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 1 Yes 0 849 0 0 33907 7926 9461 70117 96295 96295 56792 96295 75461 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 Yes 975402536 975402536 975402536 975402536 97540253...
result:
wrong answer Participant cannot satisfy the constraint. (test case 4)