QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#365085#8102. Mallckiseki#WA 1ms3748kbC++203.6kb2024-03-24 19:19:012024-03-24 19:19:02

Judging History

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

  • [2024-03-24 19:19:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3748kb
  • [2024-03-24 19:19:01]
  • 提交

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