QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638658#9422. Two-star ContestzhaaaWA 30ms6152kbC++143.1kb2024-10-13 16:31:472024-10-13 16:31:48

Judging History

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

  • [2024-10-13 16:31:48]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:6152kb
  • [2024-10-13 16:31:47]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const ll MX=1e9+10;
ll n,m,k;
struct MS{
    ll id,sum,cnt,s;
}a[N];
bool cmp(MS a,MS b){
    return a.s>b.s;
}

void solve(){
    cin>>n>>m>>k;
    vector<ll>v1[n+10];
    for(int i=1;i<=n;i++){
        ll s,sum=0,cnt=0;
        cin>>s;
        for(int j=1;j<=m;j++){
            ll s1;
            cin>>s1;
            v1[i].push_back(s1);
            if(s1>=0){
                sum+=s1;
            }else{
                cnt++;
            }
        }
        a[i]={i,sum,cnt,s};
    }
    sort(a+1,a+1+n,cmp);
    a[n+1]={MX,MX,MX,0};
    /*
    map<ll,ll>mp;
    ll l=0,r=1e18+10;
    ll last=r;
    bool f=false;
    for(int i=1;i<=n+1;i++){
        if(a[i].s!=a[i-1].s&&i!=1){
            if(l>=r) 
            {
                f=true;
                break;
            }
            mp[a[i-1].s]=r;
            r--;
            l=a[i].sum;
            r=min(r,a[i].sum+k*a[i].cnt);
            //cout<<l<<" "<<r<<endl;
            if(l>r&&i!=n+1){
                //cout<<i<<endl;
                f=true;
                break;
            }
        }else{
            l=max(l,a[i].sum);
            r=min(r,a[i].sum+a[i].cnt*k);
        }
    }
    if(f){
        cout<<"No"<<endl;
        return;
    }
    cout<<"Yes"<<endl;
    vector<ll>v[n+10];
    for(int i=1;i<=n;i++){
        ll id=a[i].id;
        ll sum=max(0ll,mp[a[i].s]-a[i].sum);
        for(int j=0;j<m;j++){
            if(v1[id][j]!=-1){
                v[id].push_back(v1[id][j]);
            }else{
                ll t=min(sum,k);
                v[id].push_back(t);
                sum-=t;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<m;j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    } */
    bool f=false;
    map<ll,ll>mp;
    mp[0]=1e18+10;
    for(int i=1;i<=n;i++){
        int j=i+1;
        ll l=a[i].sum;
        ll r=a[i].sum+a[i].cnt*k;
        while(a[j].s==a[i].s){
            l=max(l,a[j].sum);
            r=min(r,a[i].sum+a[i].cnt*k);
            j++;
        }
        j--;
        if(l>=mp[a[i-1].s]){
            f=true;
            break;
        }
        mp[a[j].s]=min(mp[a[i-1].s]-1,r);
        i=j;
    }
    if(f){
        cout<<"No"<<endl;
        return;
    }
    vector<ll>v[n+10];
    cout<<"Yes"<<endl;
    for(int i=1;i<=n;i++){
        ll id=a[i].id;
        ll sum=max(mp[a[i].s]-a[i].sum,0ll);
        for(int j=0;j<m;j++){
            if(v1[id][j]==-1){
                ll t=min(sum,k);
                v[id].push_back(t);
                sum-=t;
            }else{
                v[id].push_back(v1[id][j]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<m;j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        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 5 
2 5 0 5 
3 5 1 4 
No
Yes
1 2 3 
4 5 6 
No
Yes
10000 10000 10000 
10000 10000 9999 

result:

ok ok 5 cases (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 30ms
memory: 6152kb

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
96295 849 96295 96295 33907 7926 9461 70117 
96295 96295 56792 96295 96295 96295 19527 96295 
12828 30553 40825 67577 91517 77952 55631 63781 
29385 96295 96295 96295 750 92125 0 0 
Yes
72716304 72716304 66436933 72716304 45419040 55642613 
72716304 62712753 72716304 21765515 ...

result:

wrong answer Participant cannot satisfy the constraint. (test case 6)