QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759911#5420. InscryptionMitsubachiCompile Error//C++142.2kb2024-11-18 13:16:572024-11-18 13:16:58

Judging History

你现在查看的是最新测评结果

  • [2024-11-18 13:16:58]
  • 评测
  • [2024-11-18 13:16:57]
  • 提交

answer

// g++-13 1.cpp -std=c++17 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
 
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
 
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

random_device seed;
mt19937_64 randint(seed());

ll grr(ll mi, ll ma) { // [mi, ma)
    return mi + randint() % (ma - mi);
}

using P = pair<ll,ll>;

P ok(int n,vi &a){
  int p=1,q=1;
  rep(i,0,n){
    if(a[i]==1)p++;
    q+=a[i];
    if(q==0)return {-1,1};
  }
  return {p,q};
}

P big(P &a,P &b){
  auto [ap,aq]=a;
  auto [bp,bq]=b;
  if(ap*bq<aq*bp)return b;
  return a;
}

void solve(){
  int n;cin>>n;
  vi a(n);
  vi z;
  rep(i,0,n){
    cin>>a[i];
    if(a[i]==0){
      z.emplace_back(i);
    }
  }

  int sz=z.size();
  {
    vi a2=a;
    rep(i,0,n){
      if(a2[i]==0)a2[i]=1;
    }
    if(ok(n,a2).first==-1){
      cout<<-1<<"\n";
      return;
    }
  }

  int mx=sz,mn=-1;
  while(mx-mn>1){
    int c=(mx+mn)/2;
    vi a2=a;
    rep(i,0,c)a2[z[i]]=1;
    rep(i,c,sz)a2[z[i]]=-1;
    if(ok(n,a2).first==-1)mn=c;
    else mx=c;
  }

  P ans;
  {
    vi a2=a;
    rep(i,0,mx)a2[z[i]]=1;
    rep(i,mx,sz)a2[z[i]]=-1;
    ans=ok(n,a2);
  }

  rep(i,mx+1,sz+1){
    auto [p,q]=ans;
    P ans2={p+1,q+2};
    ans=big(ans,ans2);
  }

  auto [p,q]=ans;
  int g=gcd(p,q);
  cout<<p/g<<" "<<q/g<<"\n";
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;cin>>t;
  while(t--){
    solve();
  }
}

Details

answer.code: In function ‘P big(P&, P&)’:
answer.code:56:8: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   56 |   auto [ap,aq]=a;
      |        ^
answer.code:57:8: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   57 |   auto [bp,bq]=b;
      |        ^
answer.code: In function ‘void solve()’:
answer.code:104:10: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  104 |     auto [p,q]=ans;
      |          ^
answer.code:109:8: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  109 |   auto [p,q]=ans;
      |        ^
answer.code:110:9: error: ‘gcd’ was not declared in this scope
  110 |   int g=gcd(p,q);
      |         ^~~