QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#365085 | #8102. Mall | ckiseki# | WA | 1ms | 3748kb | C++20 | 3.6kb | 2024-03-24 19:19:01 | 2024-03-24 19:19:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
const int inf = 1000000007;
void solve() {
int n;
cin >> n;
vector<pair<int,int>> v(n);
for (int i = 0; i < n; i++) {
auto &[x, y] = v[i];
cin >> x >> y;
}
if (n == 1) {
cout << "YES 1\n";
return;
}
vector<int> ans(n, -1);
vector<int> unbounded;
for (int i = 0; i < n; i++) {
int len = inf;
for (int j = 0; j < n; j++)
if (j != i && v[j].first >= v[i].first && v[j].second >= v[i].second) {
len = min(len, min(v[j].first-v[i].first, v[j].second-v[i].second));
}
if (len == inf) {
unbounded.push_back(i);
} else {
ans[i] = len;
}
}
using lld = int64_t;
sort(all(unbounded), [&](int a, int b) {
return make_pair(v[a].first, -v[a].second) < make_pair(v[b].first, -v[b].second);
});
for (int t = 0; t < (int)unbounded.size(); t++) {
int M = unbounded[t];
bool ok = true;
int left = inf, right = inf;
{
vector<pair<int,int>> stk; // (y, x)
for (int i = t - 1; i >= 0; i--) {
int x = unbounded[i];
while (stk.size() && stk.back().first > v[x].second) {
stk.pop_back();
}
if (stk.empty()) {
ok = false;
break;
}
ans[x] = stk.back().second - v[x].first;
if (stk.back().first < v[x].second + ans[x]) {
ok = false;
break;
}
stk.emplace_back(v[x].second + ans[x], v[x].first);
}
if (stk.size())
left = stk.front().first - v[M].second;
}
{
vector<pair<int,int>> stk; // (x, y)
for (int i = t + 1; i < (int)unbounded.size(); i++) {
int x = unbounded[i];
while (stk.size() && stk.back().first > v[x].first) {
stk.pop_back();
}
if (stk.empty()) {
ok = false;
break;
}
ans[x] = stk.back().second - v[x].second;
if (stk.back().first < v[x].first + ans[x]) {
ok = false;
break;
}
stk.emplace_back(v[x].first + ans[x], v[x].second);
}
if (stk.size())
right = stk.front().first - v[M].first;
}
if (!ok) continue;
if (left != inf && right != inf && left != right) {
continue;
}
if (left == inf && right == inf) {
safe; debug("WEIRD");
continue;
}
ans[M] = left==inf ? right : left;
lld lx = inf, rx = -inf, ly = inf, ry = -inf;
lld area = 0;
for (int i = 0; i < n; i++) {
lx = min<lld>(lx, v[i].first);
rx = max<lld>(rx, v[i].first);
ly = min<lld>(ly, v[i].second + ans[i]);
ry = max<lld>(ry, v[i].second + ans[i]);
area += 1LL * ans[i] * ans[i];
}
if ((rx - lx) * (ry - ly) == area) {
cout << "YES";
for (int i = 0; i < n; i++)
cout << ' ' << ans[i];
cout << '\n';
return;
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3748kb
input:
4 4 1 2 2 2 4 2 1 3 1 1
output:
YES 1 YES 1 YES 1
result:
wrong output format Expected integer, but "YES" found