QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184507 | #5420. Inscryption | chitoge# | WA | 160ms | 3468kb | C++14 | 1.9kb | 2023-09-20 20:17:29 | 2023-09-20 20:17:29 |
Judging History
answer
#pragma GCC optimize("Ofast")
//booster_^^
#include<bits/stdc++.h>
#define FC(a,b,c) for(int i=a;i<b;i++)cin>>c[i]
#define Fn(n) for(int i=0;i<n;i++)
#define fin(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define F(a,b) for(int i=a;i<b;i++)
#define all(a) a.begin(),a.end()
#define umap_boost(x) x.reserve(1024);x.max_load_factor(0.25);
#define PII pair<int,int>
#define ll long long
#define endl '\n'
using namespace std;
inline void cin_unlocked()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
}
template <typename T>
inline void stable_unique(vector<T>& v ){
set<T> m(v.begin(),v.end());
v.assign(m.begin(),m.end());
}
class dsu{
public:
int n;
vector<int> c;
int q(int x){
if(c[x]!=x){
c[x]=q(c[x]);
}
return c[x];
}
void u(int a,int b){
int fa=q(a);
int fb=q(b);
if(fa!=fb)
c[fa]=fb;
}
dsu(int &_n){
this->n=_n+5;
this->c.resize(n);
for(int i=0;i<n;i++)c[i]=i;
}
};
int pow_mod(int a, int b,int mod) {//a^b
int ans = 1;
while(b > 0) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
inline void solve(){
int n;
cin>>n;
vector<int> arr(n+5),pre(n+5);
for(int i=1;i<=n;i++)cin>>arr[i];
for(int i=n;i>0;i--)pre[i]=pre[i+1]+(arr[i]==-1);
int ans=1,c=1;
int x=0;
for(int i=1;i<=n;i++){
if(arr[i]==1){
c++;ans++;
}
if(arr[i]==0){
x++;
}
if(arr[i]==-1){
if(c<=1){
if(x){
x--;
ans++;c++;
}
else{
cout<<"-1"<<endl;
return;
}
}
c--;
}
}
if(c>x){
c-=x;
}else{
x-=c;
x++;
ans+=x/2;
c=x/2+x%2;
}
cout<<ans/__gcd(ans,c)<<' '<<c/__gcd(ans,c)<<endl;
}
int main(){
cin_unlocked();
int t;cin>>t;for(;t--;)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3432kb
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: 160ms
memory: 3468kb
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: 71ms
memory: 3468kb
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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