QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721026#5420. InscryptionLeoGWA 75ms3552kbC++232.9kb2024-11-07 15:00:442024-11-07 15:00:46

Judging History

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

  • [2024-11-07 15:00:46]
  • 评测
  • 测评结果:WA
  • 用时:75ms
  • 内存:3552kb
  • [2024-11-07 15:00:44]
  • 提交

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++;
        }
    }
    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, cnt = 1;
    std::cin >> t;
    for (int i = 1; i <= t; i++) {
        if (t > 10) {
        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();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 75ms
memory: 3480kb

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:

[0]

result:

wrong answer 1st lines differ - expected: '1 1', found: '[0]'