QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#385795#5420. InscryptionshepherdWA 176ms3884kbC++205.3kb2024-04-11 04:15:192024-04-11 04:15:19

Judging History

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

  • [2024-04-11 04:15:19]
  • 评测
  • 测评结果:WA
  • 用时:176ms
  • 内存:3884kb
  • [2024-04-11 04:15:19]
  • 提交

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) {
        if (total <= 1) {
          a[i] = 1;
          total++;
        } else {
          zeroes.insert(i);
        }
      } else {
        if (total + len(zeroes) <= 1) {
          possible = false;
          break;
        } else if (total <= 1) {
          a[*zeroes.begin()] = 1;
          zeroes.erase(zeroes.begin());
        } else {
          total--;
        }
      }
    }
    if (!possible) {
      cout << -1 << '\n';
    } else {
      total = 0;
      for (int i = 0; i < n; i++) {
        if (a[i])
          total += a[i];
        else {
          if (total <= 1)
            a[i] = 1, total++;
          else
            a[i] = -1, total--;
        }
      }
      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
}

详细

Test #1:

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

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
3 1
-1
1 1
2 1
-1

result:

ok 6 lines

Test #2:

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

input:

1000000
1
1
1
-1
1
1
1
1
1
1
1
1
1
-1
1
-1
1
0
1
0
1
1
1
0
1
-1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
0
1
0
1
1
1
-1
1
1
1
1
1
-1
1
0
1
1
1
0
1
-1
1
0
1
-1
1
1
1
-1
1
0
1
1
1
1
1
-1
1
0
1
-1
1
-1
1
-1
1
-1
1
0
1
0
1
-1
1
0
1
-1
1
0
1
0
1
0
1
0
1
0
1
-1
1
1
1
0
1
0
1
1
1
0
1
-1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
...

output:

1 1
-1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
1 1
-1
1 1
1 1
1 1
-1
1 1
-1
-1
-1
-1
1 1
1 1
-1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
-1
-1
1 1
1 1
-1
1 1
1 1
1 1
1 1
-1
1 1
1 1
1 ...

result:

ok 1000000 lines

Test #3:

score: -100
Wrong Answer
time: 73ms
memory: 3588kb

input:

181249
6
1 0 -1 0 1 0
4
1 -1 -1 -1
8
-1 0 0 0 1 -1 1 1
3
0 1 0
6
1 0 -1 1 -1 0
4
1 -1 -1 -1
9
0 1 0 -1 -1 0 -1 0 1
1
-1
3
0 -1 1
5
0 0 1 -1 1
3
1 -1 0
6
-1 0 0 -1 0 1
8
1 -1 -1 -1 0 1 -1 0
2
0 0
3
-1 1 0
3
0 -1 -1
10
0 1 0 -1 1 1 0 -1 1 0
3
1 0 0
9
1 -1 1 -1 0 -1 0 0 0
3
0 1 0
3
-1 0 0
7
-1 0 -1 -1 ...

output:

4 1
-1
-1
3 2
4 1
-1
3 1
-1
3 2
2 1
3 2
-1
-1
2 1
-1
-1
6 1
3 2
3 1
3 2
-1
-1
-1
-1
2 1
5 3
-1
5 4
2 1
-1
3 2
5 1
1 1
-1
3 2
-1
1 1
-1
2 1
1 1
-1
1 1
-1
1 1
1 0
-1
-1
-1
-1
3 2
5 2
1 1
-1
1 0
-1
-1
1 1
-1
6 1
3 2
-1
3 2
4 3
2 1
-1
5 3
1 0
-5 1
-1
2 1
2 1
-1
1 1
-1
3 1
-1
-1
4 1
1 1
2 1
5 2
-1
3 1
4 ...

result:

wrong answer 45th lines differ - expected: '3 2', found: '1 0'