QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#721101 | #5420. Inscryption | LeoG | WA | 303ms | 3612kb | C++23 | 3.0kb | 2024-11-07 15:14:53 | 2024-11-07 15:15:02 |
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 {
if (cnt == 1) cnt++;
else st++;
}
}
while (cnt > 1 && st) {
cnt--;
st--;
mx++;
}
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;
for (int i = 1; i <= t; i++) {
if (t == 100000000) {
int n;
std::cin >> n;
vi a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
if (i == 28) {
print(a);
}
}
else solve();
}
//while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 303ms
memory: 3528kb
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 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