QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#658019#9422. Two-star ContestXiaoYang3WA 37ms26168kbC++233.6kb2024-10-19 15:59:402024-10-19 15:59:41

Judging History

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

  • [2024-10-19 15:59:41]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:26168kb
  • [2024-10-19 15:59:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
ll n, m, k;
const int N = 4e5 + 5;
const int P = 1e9 + 7;
struct node {
    ll s, i;
    ll sm, cnt;
    vector<ll> mm;
} st[N];
bool cmp(node a, node b) {
    return a.s < b.s;
}
bool cmp1(node a, node b) {
    return a.i < b.i;
}
// 1 2 2
// 1 2 3
void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> st[i].s;
        st[i].i = i;
        st[i].mm.resize(m + 1);
        st[i].sm = st[i].cnt = 0;
        for (int j = 1; j <= m; j++) {
            cin >> st[i].mm[j];
            if (st[i].mm[j] != -1) {
                st[i].sm += st[i].mm[j];
            } else {
                st[i].cnt++;
            }
        }
    }
    ll lsum = 0;
    ll sum = 0;
    // 1 1
    sort(st + 1, st + 1 + n, cmp);
    for (int i = 1; i <= n; i++) {
        if (i == 1) {
            for (int j = 1; j <= m; j++) {
                if (st[i].mm[j] == -1) {
                    st[i].mm[j] = 0;
                }
                sum += st[i].mm[j];
            }
            continue;
        }
        if (st[i].s == st[i - 1].s) {
            if (st[i].sm > lsum) {
                for (int j = 1; j <= m; j++) {
                    if (st[i].mm[j] == -1) {
                        st[i].mm[j] = 0;
                    }
                }
            } else {
                ll res = lsum - st[i].sm + 1;
                if (st[i].cnt == 0) {
                    cout << "No\n";
                    return;
                }
                ll cu = res / st[i].cnt;
                ll yu = res % st[i].cnt;
                for (int j = 1; j <= m; j++) {
                    if (st[i].mm[j] == -1) {
                        st[i].mm[j] = cu;
                        if (yu) {
                            st[i].mm[j]++;
                            yu--;
                        }
                        if (st[i].mm[j] > k) {
                            cout << "No\n";
                            return;
                        }
                    }
                }
            }
            sum = max({sum, lsum + 1, st[i].sm});
        } else {
            if (st[i].sm > sum) {
                for (int j = 1; j <= m; j++) {
                    if (st[i].mm[j] == -1) {
                        st[i].mm[j] = 0;
                    }
                }
            } else {
                ll res = sum - st[i].sm + 1;
                if (st[i].cnt == 0) {
                    cout << "No\n";
                    return;
                }
                ll cu = res / st[i].cnt;
                ll yu = res % st[i].cnt;
                for (int j = 1; j <= m; j++) {
                    if (st[i].mm[j] == -1) {
                        st[i].mm[j] = cu;
                        if (yu) {
                            st[i].mm[j]++;
                            yu--;
                        }
                        if (st[i].mm[j] > k) {
                            cout << "No\n";
                            return;
                        }
                    }
                }
            }
            lsum = sum;
            sum = max({sum + 1, st[i].sm});
        }
    }
    cout << "Yes\n";
    sort(st + 1, st + 1 + n, cmp1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << st[i].mm[j] << ' ';
        }
        cout << '\n';
    }
}
// 2 3 4
int main() {
    ios::sync_with_stdio(0);
    cin.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: 3ms
memory: 25652kb

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 4 4 
0 5 0 5 
3 2 2 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: 37ms
memory: 26168kb

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 
60725 60725 56792 60724 60724 60724 19527 60724 
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
569508118 569508118 569508118 569508117 ...

result:

wrong answer Participant fails to find an answer while the jury found one. (test case 11)