QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#706367 | #5420. Inscryption | hejinming983282# | WA | 83ms | 5752kb | C++14 | 2.1kb | 2024-11-03 10:53:57 | 2024-11-03 10:53:58 |
Judging History
answer
// Author : hejinming2012
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(x) cout << #x " = " << (x) << endl
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(0);
#define quickout cout.tie(0);
using namespace std;
inline int read() {
int now = 0, nev = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') nev = -1; c = getchar(); }
while(c >= '0' && c <= '9') { now = (now << 1) + (now << 3) + (c & 15); c = getchar(); }
return now * nev;
}
void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int a[1000005];
int b[1000005];
priority_queue <int> q;
signed main() {
quickio
quickin
quickout
int T; cin >> T;
while(T--) {
int n; cin >> n;
while(!q.empty()) q.pop();
for(int i = 1; i <= n; i++)
cin >> a[i];
int lst = n + 1;
for(int i = n; i >= 1; i--) {
b[i] = lst;
if(a[i] >= 0) lst = i;
}
q.push(1);
bool ok = 1;
for(int i = 1; i <= n; i++)
if(a[i] == 1) q.push(1);
else if(a[i] == -1) {
if(q.size() <= 1) {
ok = 0;
break ;
} else {
int topf = q.top(); q.pop();
int tops = q.top(); q.pop();
q.push(topf + tops);
}
} else {
if(q.size() - 1 < b[i] - i) q.push(1);
else {
int topf = q.top(); q.pop();
int tops = q.top(); q.pop();
q.push(topf + tops);
}
}
int num = q.size(), sum = 0;
while(!q.empty()) sum += q.top(), q.pop();
int GCD = __gcd(num, sum);
num /= GCD, sum /= GCD;
if(ok) {
write(sum), putchar(' ');
write(num), putchar(10);
} else write(-1), putchar(10);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5720kb
input:
6 7 1 1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