QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184471 | #5420. Inscryption | chitoge# | WA | 167ms | 3588kb | C++14 | 1.8kb | 2023-09-20 19:50:11 | 2023-09-20 19:50:12 |
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;
for(int i=1;i<=n;i++){
if(arr[i]==1){
c++;ans++;
}
if(arr[i]==0){
if(c<=pre[i]+1){
c++;
ans++;
}else{
c--;
}
}
if(arr[i]==-1){
if(c<=1){
cout<<"-1"<<endl;
return;
}
c--;
}
}
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: 0ms
memory: 3588kb
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: 167ms
memory: 3528kb
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: 66ms
memory: 3488kb
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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