QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#390104 | #5420. Inscryption | VeryAmazed | WA | 190ms | 3892kb | C++14 | 1.7kb | 2024-04-15 04:06:43 | 2024-04-15 04:06:43 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int t; cin >> t;
while (t--){
int n;
cin >> n;
int total = 1;
vector<int> ones;
vector<int> zeros;
vector<int> negs;
for(int i = 0; i < n; i++){
int a;
cin >> a;
if(a == 1){
total++;
ones.pb(i);
}else if(a == 0){
zeros.pb(i);
}else{
negs.pb(i);
}
}
vector<pii> vec;
int ind = 0;
for(int i = 0; i < ones.size(); i++){
while(ind < negs.size() && negs[ind] <= ones[i]){
ind++;
}
if(ind == negs.size()) break;
ones[i] = -1;
negs[ind] = -1;
}
int givens = 0;
int combines = 0;
for(int i = 0; i < ones.size(); i++){
if(ones[i] == -1) continue;
vec.pb({ones[i], 1});
}
for(int i = 0; i < negs.size(); i++){
if(negs[i] == -1) continue;
vec.pb({negs[i], -1});
combines++;
}
for(int i = 0; i < zeros.size(); i++){
vec.pb({zeros[i], 0});
}
sort(vec.begin(), vec.end());
/*
for(int i = 0; i < vec.size(); i++){
cout << vec[i].s << " ";
}
cout << "\n";
*/
bool works = true;
for(int i = 0; i < vec.size(); i++){
if(vec[i].s == 1) givens++;
else if(vec[i].s == -1){
givens--;
combines--;
}else{
if(givens > combines) givens--;
else{
givens++;
total++;
}
}
if(givens < 0) works = false;
}
if(works){
int g = __gcd(total, givens+1);
cout << total/g << " " << (givens+1)/g << "\n";
}else{
cout << -1 << "\n";
}
}
cout << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
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 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