QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625532 | #9422. Two-star Contest | Dung1604 | WA | 41ms | 5484kb | C++17 | 3.4kb | 2024-10-09 19:37:59 | 2024-10-09 19:38: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 = -100000000;
for (int i = 1; i <= n; i++) {
ll ret = -100;
ll rate = b[i].first[0];
for (int j = i; j <= n; j++) {
ll cur_sum = sum[{b[j].first[0], b[j].second}].first;
ll id = b[j].second;
ll cur_rate = b[j].first[0];
if (cur_rate == rate) {
if (cur_sum > prev) {
for (int z = 1; z <= m; z++) {
if (a[id].first[z] == -1) {
a[id].first[z] = 0;
}
}
ret = max(ret, cur_sum);
}
else {
ll need = prev + 1 - cur_sum;
for (int z = 1; z <= m; z++) {
if (a[id].first[z] == -1) {
a[id].first[z] = min(k, need);
need -= a[id].first[z];
cur_sum += a[id].first[z];
}
}
if (cur_sum < prev) {
cout << "No\n";
return;
}
else {
ret = max(ret, cur_sum);
}
}
if (j == n) {
i = n + 10;
}
}
else {
i = j - 1;
break;
}
}
prev = ret;
}
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: 1ms
memory: 3544kb
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: 41ms
memory: 5484kb
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 0 0 0 750 0 0 0 Yes 0 0 66436933 0 45419040 55642613 0 62712753 0 21765515 56544945 12385026 Yes 975402536 975402536 975402536 975402536 97540253...
result:
wrong answer Participant cannot satisfy the constraint. (test case 30)