QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623088#9422. Two-star ContestnguyenthaiduongWA 0ms3608kbC++142.5kb2024-10-09 10:05:522024-10-09 10:05:53

Judging History

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

  • [2024-10-09 10:05:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-10-09 10:05:52]
  • 提交

answer

#include <bits/stdc++.h>
#define inf LONG_LONG_MAX
#define ll long long
using namespace std;

bool cmp(vector<ll> a, vector<ll> b)
{
    return a[0] > b[0];
}
void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    
    vector<vector<ll>> pro(n + 1);
    vector<vector<ll>> a(n + 1);
    map<ll, ll> pos;
    map<ll, ll> sum;
    
    vector<ll> slot(n + 1, 0);
    for (int i = 1; i <= n; i++)
    {
        
        for (int j = 0; j <= m; j++)
        {
            
            ll x;
            cin >> x;
            if (j == 0)
            {
                pos[x] = i;
            }
            if (j != 0 && x != -1)
            {
                sum[a[i][0]] += x;
            }
            else if (x == -1)
            {
                slot[i]++;
            }

            pro[i].push_back(x);

            a[i].push_back(x);
        }
    }
    
    sort(pro.begin() + 1, pro.end(), cmp);
    
    for (int i = 1; i <= n; i++)
    {
        pos[pro[i][0]] = i;
    }
    ll sum_prev = sum[pro[1][0]] + k * slot[pos[pro[1][0]]];
    for (int j = 1; j <= m; j++)
    {
        if (a[pos[pro[1][0]]][j] == -1)
        {
            a[pos[pro[1][0]]][j] = k;
        }
    }
    
    for (int i = 2; i <= n; i++)
    {
        
        if (sum[pro[i][0]] < sum_prev)
        {
            
            int need = sum_prev - sum[pro[i][0]] - 1;
            ll new_sum = sum[pro[i][0]];
            for (int j = 1; j <= m; j++)
            {
                 if (a[pos[pro[i][0]]][j] == -1)
                {
                        a[pos[pro[i][0]]][j] = min(k, need);
                        need -= a[pos[pro[i][0]]][j];
                        new_sum += a[pos[pro[i][0]]][j];
                }
            }
            sum_prev = new_sum;
            
        }
        else
        {
            cout << "No\n";
            
            return;
        }
    }
    cout << "Yes\n";
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
        
    }

    return 0;
}

// 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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
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 5 
5 5 1 5 
3 2 0 4 
No
Yes
1 2 3 
4 5 6 
No
Yes
10000 10000 10000 
10000 10000 9999 

result:

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