QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#361944#8509. Expanding STACKS!ucup-team987#WA 0ms3884kbC++234.8kb2024-03-23 13:41:112024-03-23 13:41:12

Judging History

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

  • [2024-03-23 13:41:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-03-23 13:41:11]
  • 提交

answer

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

namespace {

void solve() {
  int n;
  scan(n);
  std::vector<int> a(n * 2);
  std::vector<int> l(n), r(n);
  for (const int pos : rep(n * 2)) {
    int& e = a[pos];
    scan(e);
    if (e < 0) {
      r[~e] = pos;
    } else {
      --e;
      l[e] = pos;
    }
  }

  atcoder::dsu d(n * 2);
  for (const int i : rep(n)) {
    for (const int j : rep(n)) {
      if (l[i] < l[j] && l[j] < r[i] && r[i] < r[j]) {
        d.merge(i, n + j);
        d.merge(n + i, j);
      }
    }
  }

  for (const int i : rep(n)) {
    if (d.same(i, n + i)) {
      print('*');
      return;
    }
  }

  for (const int i : rep(n)) {
    if (!d.same(i, 0) && !d.same(n + i, 0)) {
      d.merge(i, 0);
    }
  }

  std::vector<int> part(n);
  for (const int i : rep(n)) {
    part[i] = d.same(i, 0);
  }

  std::string ans;
  for (const int e : a) {
    if (0 <= e) {
      ans += "GS"[part[e]];
    }
  }

  print(ans);
}

}  // namespace

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout << std::setprecision(DBL_DECIMAL_DIG);

  solve();
}

#else  // __INCLUDE_LEVEL__

#include <bits/stdc++.h>

namespace atcoder {

struct dsu {
 public:
  dsu() : _n(0) {}
  explicit dsu(int n) : _n(n), parent_or_size(n, -1) {}

  int merge(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    int x = leader(a), y = leader(b);
    if (x == y) return x;
    if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
    parent_or_size[x] += parent_or_size[y];
    parent_or_size[y] = x;
    return x;
  }

  bool same(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    return leader(a) == leader(b);
  }

  int leader(int a) {
    assert(0 <= a && a < _n);
    if (parent_or_size[a] < 0) return a;
    return parent_or_size[a] = leader(parent_or_size[a]);
  }

  int size(int a) {
    assert(0 <= a && a < _n);
    return -parent_or_size[leader(a)];
  }

  std::vector<std::vector<int>> groups() {
    std::vector<int> leader_buf(_n), group_size(_n);
    for (int i = 0; i < _n; i++) {
      leader_buf[i] = leader(i);
      group_size[leader_buf[i]]++;
    }
    std::vector<std::vector<int>> result(_n);
    for (int i = 0; i < _n; i++) {
      result[i].reserve(group_size[i]);
    }
    for (int i = 0; i < _n; i++) {
      result[leader_buf[i]].push_back(i);
    }
    result.erase(std::remove_if(result.begin(), result.end(),
                                [&](const std::vector<int>& v) { return v.empty(); }),
                 result.end());
    return result;
  }

 private:
  int _n;
  std::vector<int> parent_or_size;
};

}  // namespace atcoder

template <class T, class U = T>
bool chmin(T& x, U&& y) {
  return y < x && (x = std::forward<U>(y), true);
}

template <class T, class U = T>
bool chmax(T& x, U&& y) {
  return x < y && (x = std::forward<U>(y), true);
}

template <std::signed_integral T = int>
T inf() {
  T ret;
  std::memset(&ret, 0x3f, sizeof(ret));
  return ret;
}

template <std::floating_point T>
T inf() {
  return std::numeric_limits<T>::infinity();
}

template <class T>
concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;

template <class T>
concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;

namespace std {

istream& operator>>(istream& is, Range auto&& r) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

istream& operator>>(istream& is, Tuple auto&& t) {
  return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

ostream& operator<<(ostream& os, Range auto&& r) {
  for (string_view sep = ""; auto&& e : r) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

ostream& operator<<(ostream& os, Tuple auto&& t) {
  const auto f = [&](auto&... xs) -> ostream& {
    [[maybe_unused]] string_view sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

}  // namespace std

void scan(auto&&... xs) { std::cin >> std::tie(xs...); }
void print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; }

template <class F>
class fix {
 public:
  explicit fix(F f) : f_(std::move(f)) {}

  decltype(auto) operator()(auto&&... xs) const {
    return f_(std::ref(*this), std::forward<decltype(xs)>(xs)...);
  }

 private:
  F f_;
};

inline auto rep(int l, int r) { return std::views::iota(std::min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }

namespace ranges = std::ranges;
namespace views = std::views;

using i64 = std::int64_t;

#endif  // __INCLUDE_LEVEL__

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3884kb

input:

2
+2 +1 -1 -2

output:

SS

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

2
+1 +2 -1 -2

output:

SG

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

3
+1 +2 +3 -1 -2 -3

output:

*

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

10
+3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10

output:

SSSSSSSSSS

result:

ok correct

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3584kb

input:

10
+8 -8 +2 +10 -2 -10 +7 -7 +1 -1 +6 -6 +5 +3 +4 +9 -9 -4 -3 -5

output:

SSGSSSSSSS

result:

wrong answer client leaving is not the top of its stack