QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625434 | #9422. Two-star Contest | Dung1604 | WA | 39ms | 5488kb | C++17 | 3.8kb | 2024-10-09 19:18:04 | 2024-10-09 19:18:05 |
Judging History
answer
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <tuple>
#include <iomanip>
#include <map>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <unordered_map>
#define ll long long
#define inf 10000000000007
#define mod 1000000007
using namespace std;
const int BLOCK = 450;
ll fastpow(ll n, ll x) {
if (x == 0) {
return 1;
}
else {
ll ret = fastpow(n, x / 2);
ret = ((ret % mod) * (ret % mod)) % mod;
if (x % 2 == 0) {
return ret;
}
else {
return ((ret) * (n)) % mod;
}
}
}
ll gcd(ll a, ll b) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
else {
return gcd(b, a % b);
}
}
ll lcm(ll a, ll b) {
ll val = (a % mod * b % mod) % mod;
val = (val * fastpow(gcd(a, b), mod - 2)) % mod;
return val;
}
int Logk(ll n, ll k) {
if (k == 1) {
return 1;
}
if (n == 0) {
return 0;
}
int count = -1;
while (n > 0) {
count++;
n /= k;
}
return count;
}
struct Dsu {
vector<int> par;
void init(int n) {
par.resize(n + 5, 0);
for (int i = 1; i <= n; i++) par[i] = i;
}
int find(int u) {
if (par[u] == u) return u;
return par[u] = find(par[u]);
}
bool join(int u, int v) {
u = find(u); v = find(v);
if (u == v) return false;
par[v] = u;
return true;
}
} dsu;
bool cmp(pair<vector<ll>, ll> a, pair<vector<ll>, ll> b) {
if (a.first[0] == b.first[0]) {
return a.second < b.second;
}
else {
return a.first[0] < b.first[0];
}
}
void solve() {
ll n, m, k;
cin >> n >> m >> k;
vector<pair<vector<ll>, ll>> a(n + 1);
vector<pair<vector<ll>, ll>> b(n + 1);
map<pair<ll,ll>, pair<ll, ll>> sum;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) {
ll x;
cin >> x;
a[i].second = i;
a[i].first.push_back(x);
if (j > 0) {
if (x == -1) {
sum[{a[i].first[0], i}].second += 1;
}
else {
sum[{a[i].first[0], i}].first += x;
}
}
}
}
b = a;
sort(b.begin() + 1, b.end());
ll prev = -10;
ll prev_pos = 0;
for (int i = 1; i <= n; i++) {
ll cur_sum = sum[{b[i].first[0], b[i].second}].first;
ll rate = b[i].first[0];
ll id = b[i].second;
ll slot = sum[{b[i].first[0], b[i].second}].second;
if (rate == prev_pos) {
if (cur_sum >= prev) {
for (int j = 1; j <= m; j++) {
if (a[id].first[j] == -1) {
a[id].first[j] = 0;
}
}
prev = cur_sum;
}
else {
ll need = prev - cur_sum;
for (int j = 1; j <= m; j++) {
if (a[id].first[j] == -1) {
a[id].first[j] = min(k, need);
need -= a[id].first[j];
cur_sum += a[id].first[j];
}
}
if (cur_sum < prev) {
cout << "No\n";
return;
}
else {
prev = cur_sum;
}
}
}
else {
if (cur_sum > prev) {
for (int j = 1; j <= m; j++) {
if (a[id].first[j] == -1) {
a[id].first[j] = 0;
}
}
prev = cur_sum;
}
else {
ll need = prev - cur_sum + 1;
for (int j = 1; j <= m; j++) {
if (a[id].first[j] == -1) {
a[id].first[j] = min(k, need);
need -= a[id].first[j];
cur_sum += a[id].first[j];
}
}
if (cur_sum <= prev) {
cout << "No\n";
return;
}
else {
prev = cur_sum;
}
}
}
prev_pos = rate;
}
cout << "Yes\n";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << a[i].first[j] << " ";
}
cout << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
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: 39ms
memory: 5488kb
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 96295 96295 96295 750 96295 25349 0 Yes 0 0 66436933 0 45419040 55642613 14090347 62712753 0 21765515 56544945 12385026 Yes 975402536 975402536 9...
result:
wrong answer Participant fails to find an answer while the jury found one. (test case 39)