QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90635 | #5420. Inscryption | Saanteye | WA | 263ms | 3340kb | C++14 | 1.5kb | 2023-03-24 14:16:31 | 2023-03-24 14:16:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
void solve() {
int n;
cin >> n;
vector<int> a(n);
vector<int> f(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> s;
queue<int> que0;
int p = 1,q = 1;
for(int i = 0; i < n; i++) {
if(a[i] == 1)
s.push_back(i);
else if(a[i] == 0)
que0.push(i);
else if(a[i] == -1) {
if(s.size()) {
s.pop_back();
p += 1;
}
else if(que0.size()){
que0.pop();
p += 1;
}
else {
cout << "-1\n";
return;
}
}
}
int v = 0;
for(int i = 0; i < s.size(); i++) {
if(que0.size()) {
while(!que0.empty() && que0.front() > s[i]) {
v++;
que0.pop();
}
if(s[i] < que0.front())
p += 1;
else {
q+=1;p+=1;
}
}
else {
q+=1;p+=1;
}
}
v += que0.size();
p += v / 2;
p += v % 2;
q += v % 2;
cout << p / __gcd(p,q) << ' ' << q / (__gcd(p,q)) << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3340kb
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: 263ms
memory: 3312kb
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 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