QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720930 | #5420. Inscryption | LeoG | WA | 295ms | 3616kb | C++23 | 2.6kb | 2024-11-07 14:43:57 | 2024-11-07 14:43:57 |
Judging History
answer
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#define ll long long
#define all(v) v.begin(),v.end()
#define ld long double
#define pll std::pair<ll,ll>
#define pi std::pair<int,int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define len(x) (int)x.size()
#define vec(T) std::vector<T>
template<typename T, typename = void>
struct is_printable : std::false_type {};
template<typename T>
struct is_printable<T, std::void_t<decltype(std::declval<std::ostream&>() << std::declval<T>())>> : std::true_type {};
template <typename T>
void print(const std::pair<T, T>& pair) {
std::cout << "(" << pair.first << ", " << pair.second << ")";
}
// General print function
template <typename T>
void print(const T& val) {
std::cout << val;
}
// Print function for std::vector
template <typename T>
void print(const std::vector<T>& vec) {
std::cout << '[';
int n = vec.size();
for (int i = 0; i < n; i++) {
print(vec[i]);
if (i < n - 1) {
std::cout << ",";
}
}
std::cout << ']' << '\n';
}
// Variadic template print function
template<typename T, typename... Args>
void print(const T& t, const Args&... args) {
print(t);
std::cout << (is_printable<T>::value ? ' ' : '\0');
print(args...);
if (sizeof...(args) == 1 && is_printable<T>::value) std::cout << '\n';
}
int gcd(int x, int y) {
return (y ? gcd(y, x % y) : x);
}
void solve(){
int n;
std::cin >> n;
vi a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
int cnt = 1, mx = 1, st = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1) {
cnt++;
}
else if (a[i] == -1) {
if (cnt > 1) {
cnt--;
mx++;
}
else if (st) {
st--;
mx++;
}
else {
std::cout << "-1\n";
return;
}
}
else {
st++;
}
}
mx += st / 2;
cnt += st % 2;
int x = mx + cnt - 1;
int g = gcd(x, cnt);
std::cout << x / g << ' ' << cnt / g << std::endl;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
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: 295ms
memory: 3544kb
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: 99ms
memory: 3616kb
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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