QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719036#9422. Two-star Contestcyc_43346WA 31ms24660kbC++143.0kb2024-11-06 22:10:422024-11-06 22:10:42

Judging History

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

  • [2024-11-06 22:10:42]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:24660kb
  • [2024-11-06 22:10:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define maxn 400005
#define inf 0x3f3f3f3f
vector<int>vt[maxn],ans[maxn];
struct P {
    int x, i;
    ll sum;
    bool operator < (P b) {
        if (x == b.x)return sum > b.sum;
        return x > b.x;
    }
}p[maxn];
void solve()
{
    int n,m,k;
    cin >> n>>m>>k;
    for (int i = 1; i <= n; i++) {
        vt[i].clear();
        ans[i].resize(m);
    }
    for (int i = 1; i <= n; i++) {
        cin >> p[i].x;
        p[i].i = i;
        ll sum = 0;
        for (int j = 1; j <= m; j++) {
            int x;
            cin >> x;
            if (x != -1) {
                sum += x;
            }
            else {
                sum += k;
            }
            vt[i].push_back(x);
        }
        p[i].sum = sum;
    }
    sort(p + 1, p + 1 + n);
    ll minv = 1e18;
    ll lminv = 1e18;
    bool f = 0;
    for (int i = 1; i <= n; i++) {
        bool flag = 0;
        if (i > 1 && p[i].x == p[i - 1].x) {
            flag = 1;
        }
        if (!flag) {
            ll sum = 0;
            for (int j = 0; j < m; j++) {
                if (vt[p[i].i][j] == -1) {
                    continue;
                }
                else {
                    ans[p[i].i][j] = vt[p[i].i][j];
                    sum += vt[p[i].i][j];
                }
            }
            if (sum >= minv) {
                f = 1;
            }
            for (int j = 0; j < m; j++) {
                if (vt[p[i].i][j] == -1) {
                    if (sum + k < minv) {
                        sum += k;
                        ans[p[i].i][j] = k;
                    }
                    else {
                        ans[p[i].i][j] = minv - sum - 1;
                        sum = minv - 1;
                    }
                }
            }
            minv = sum;
        }
        else {
            ll sum = 0;
            for (int j = 0; j < m; j++) {
                if (vt[p[i].i][j] == -1) {
                    continue;
                }
                else {
                    ans[p[i].i][j] = vt[p[i].i][j];
                    sum += vt[p[i].i][j];
                }
            }
            for (int j = 0; j < m; j++) {
                if (vt[p[i].i][j] == -1) {
                    if (sum + k <= minv) {
                        sum += k;
                        ans[p[i].i][j] = k;
                    }
                    else {
                        ans[p[i].i][j] = minv - sum;
                        sum = minv;
                    }
                }
            }
            minv = sum;
        }
    }
    if (f) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

signed main()
{
    int t;
    cin.tie(0)->sync_with_stdio(false);
    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: 23712kb

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: 31ms
memory: 24660kb

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 96295 96295 96295 
Yes
72716304 72716304 66436933 72716304 45419040 55642613 
72716304 62712753 72716304 2...

result:

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