QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385796#5420. InscryptionshepherdWA 1ms3508kbC++205.1kb2024-04-11 04:22:592024-04-11 04:22:59

Judging History

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

  • [2024-04-11 04:22:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3508kb
  • [2024-04-11 04:22:59]
  • 提交

answer

#include <bits/stdc++.h>

#include <climits>
#include <cstdint>

using namespace std;

#pragma GCC optimize("Ofast,unroll-loops")

using ui = unsigned int;
using ll = long long;
using ull = uint64_t;
using ld = long double;

template <typename K, typename V>
using umap = unordered_map<K, V>;

#define null NULL
#define len(a) static_cast<int>((a).size())
#define present(c, x) (c.find(x) != c.end())
#define inrange(val, start, end) (val >= start && val <= end)
const double PI = 2 * acos(0.0);

constexpr int iinf = 0x3f3f3f3f;
constexpr ll inf = 1'000'000'000'000'000;
constexpr ll mod = 1e9 + 7;

#define var(args...)                       \
  {                                        \
    string _s = #args;                     \
    stringstream _ss;                      \
    string ccurr = "";                     \
    for (int zz = 0; zz < len(_s); zz++) { \
      if (_s[zz] == ' ') continue;         \
      if (_s[zz] == ',') {                 \
        _ss << ' ' + ccurr;                \
        ccurr = "";                        \
      } else {                             \
        ccurr += _s[zz];                   \
      }                                    \
    }                                      \
    _ss << ' ' + ccurr;                    \
    istream_iterator<string> _it(_ss);     \
    vars(_it, args);                       \
  }
#define debugDecimal(d) cerr << setprecision(d) << fixed

void vars(istream_iterator<string> it) { cerr << '\n'; }
template <typename T, typename... Args>
void vars(istream_iterator<string> it, T a, Args... args) {
  cerr << " [" << *it << ": " << a << "] ";
  vars(++it, args...);
}

#define printVerdict(verdict) cout << (verdict ? "YES" : "NO") << '\n'
#define printDecimal(d) cout << setprecision(d) << fixed
#define printCase(_) cout << "Case #" << (_) << ": "

template <int I, typename TupleT>
ostream& printTupleImpl(ostream& out, const TupleT& t) {
  if constexpr (I < tuple_size_v<TupleT>) {
    out << get<I>(t) << " ";
    printTupleImpl<I + 1, TupleT>(out, t);
  }
  return out;
}
template <typename... Ts>
ostream& operator<<(ostream& out, const tuple<Ts...>& t) {
  return printTupleImpl<0>(out, t);
}

template <int I, typename TupleT>
istream& readTupleImpl(istream& in, TupleT* t) {
  if constexpr (I < tuple_size_v<TupleT>) {
    in >> get<I>(*t);
    readTupleImpl<I + 1, TupleT>(in, t);
  }
  return in;
}

template <typename... Ts>
istream& operator>>(istream& in, tuple<Ts...>& t) {
  return readTupleImpl<0>(in, &t);
}

template <typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  return out << p.first << " " << p.second;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
  for (const T& a : arr) out << a << " ";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<vector<T>>& grid) {
  for (const vector<T>& row : grid) out << row << '\n';
  return out;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& arr) {
  for (T& a : arr) in >> a;
  return in;
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}

template <typename Fun>
class y_combinator_result {
  Fun fun_;

 public:
  template <typename T>
  explicit y_combinator_result(T&& fun) : fun_{std::forward<T>(fun)} {}

  template <typename... ArgTs>
  decltype(auto) operator()(ArgTs&&... args) {
    return fun_(std::ref(*this), std::forward<ArgTs>(args)...);
  }
};

template <typename Fun>
decltype(auto) y_combinator(Fun&& fun) {
  return y_combinator_result<decay_t<Fun>>(std::forward<Fun>(fun));
}

inline void prayGod() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    a.insert(a.begin(), 1);
    n++;
    set<int> zeroes;
    int total = 0;
    bool possible = true;
    for (int i = 0; i < n && possible; i++) {
      if (a[i] == 1)
        total++;
      else if (a[i] == 0) {
        zeroes.insert(i);
      } else {
        total--;
      }
      if (total - len(zeroes) < 1) {
        if (!zeroes.empty()) {
          a[*zeroes.begin()] = 1;
          zeroes.erase(zeroes.begin());
        } else {
          possible = false;
          break;
        }
      }
    }
    if (!possible) {
      cout << -1 << '\n';
    } else {
      for (int i = 0; i < n; i++) {
        if (!a[i]) {
          a[i] = -1;
        }
      }
      int numerator = 0, denominator = 0;
      for (int i = 0; i < n; i++) {
        if (a[i] == 1) numerator++;
        denominator += a[i];
      }
      int g = __gcd(numerator, denominator);
      cout << numerator / g << " " << denominator / g << '\n';
    }
  }
}

int main() {
#ifdef LLOCAL
  clock_t start = clock();
#endif
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);

  prayGod();
#ifdef LLOCAL
  clock_t end = clock();

  double time_taken = double(end - start) / CLOCKS_PER_SEC;
  debugDecimal(5) << time_taken << " s" << '\n';
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3508kb

input:

6
7
1 1 1 -1 1 1 -1
4
1 0 -1 0
4
0 -1 -1 0
1
0
2
0 0
1
-1

output:

3 2
4 3
-1
1 1
1 1
-1

result:

wrong answer 2nd lines differ - expected: '3 1', found: '4 3'