QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720937 | #5420. Inscryption | LeoG | WA | 316ms | 3836kb | C++23 | 2.7kb | 2024-11-07 14:45:40 | 2024-11-07 14:45:40 |
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;
if (st % 2) {
if (cnt == 1) cnt++;
else {
cnt--;
mx++;
}
}
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();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
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: 316ms
memory: 3836kb
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: 87ms
memory: 3628kb
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 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