QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#721041#5420. InscryptionLeoGWA 283ms3844kbC++232.9kb2024-11-07 15:02:572024-11-07 15:02:58

Judging History

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

  • [2024-11-07 15:02:58]
  • 评测
  • 测评结果:WA
  • 用时:283ms
  • 内存:3844kb
  • [2024-11-07 15:02:57]
  • 提交

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;
    std::cin >> t;
    for (int i = 1; i <= t; i++) {
        if (t == 181249) {
        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: 3620kb

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: 283ms
memory: 3560kb

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: 49ms
memory: 3844kb

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:

[0,1,1,1,-1]

result:

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