QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#390198 | #5420. Inscryption | VeryAmazed | WA | 188ms | 3864kb | C++14 | 2.0kb | 2024-04-15 10:05:05 | 2024-04-15 10:05:06 |
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;
/*
This sol doesn't work.
The 1s want to be eliminated right to left
The -1s want to be eliminated left to right
so maybe going from right to left with -1s and then picking the first 1 before
it will work, but it's a bit tricky to implement.
XDDDDDDDDDD
Im stupid
*/
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 = (int)negs.size()-1;
for(int i = (int)ones.size()-1; i >= 0; i--){
if(ind < 0) break;
if(negs[ind] > ones[i]){
ones[i] = -1;
negs[ind] = -1;
ind--;
}
}
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;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
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: 188ms
memory: 3864kb
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: 107ms
memory: 3572kb
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 -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