QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725277 | #5420. Inscryption | hellocccl | WA | 145ms | 7956kb | C++20 | 1.9kb | 2024-11-08 16:57:31 | 2024-11-08 16:57:32 |
Judging History
answer
//ALL IN
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int long long
#define double long double
const int N=2e6+7;
const int mod=1e9+7;
const int inf=4e18;
mt19937 rnd(time(0));
clock_t start,over;// start=clock(); last=(final-over)*1.0/1000
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0',ch=getchar();}return x*f;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');return;}
int a[N];
int pre[N];
int pre1[N];
void solve(){
int n;cin>>n;
pre[0]=1;
vector<int>v0;
vector<int>v_;
for(int i=1;i<=n;i++){
pre[i]=0;
pre1[i]=0;
}
for(int i=1;i<=n;i++){
cin>>a[i];
pre[i]=pre[i-1];
pre1[i]=pre1[i-1];
if(a[i]==0 or a[i]==1)pre[i]++;
if(a[i]==1)pre1[i]++;
if(a[i]==0)v0.push_back(i);
if(a[i]==-1)v_.push_back(i);
}
int cnt=0;
for(int i=1;i<=n;i++){
if(a[i]==-1){
cnt++;
if(cnt>=pre[i]){
cout<<-1<<'\n';
return;
}
}
}
int ccc=0;
int now=1;
int last=0;
for(auto i:v_){
ccc++;
int x=pre1[i];
if(ccc<now+x){
continue;
}else{
int t=ccc-(now+x)+1;//需要的0的数量
for(int j=last;j<last+t;j++){
a[v0[j]]=1;
}
last=last+t;
now+=t;
}
}
int cnm=1;
for(int i=1;i<=n;i++){
if(a[i]==0){
if(cnm&1)
a[i]=1;
else
a[i]=-1;
cnm++;
}
}
int ansx=1,ansy=1;
for(int i=1;i<=n;i++){
if(a[i]==1){
ansx++;
ansy++;
}else if(a[i]==0){
ansy--;
}else{
ansy--;
}
}
int g=__gcd(ansx,ansy);
cout<<ansx/g<<" "<<ansy/g<<'\n';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _=1;
cin>>_;
while(_--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7788kb
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: 145ms
memory: 7956kb
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 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