結果

問題 No.1017 Reiwa Sequence
ユーザー cureskol
提出日時 2020-04-04 12:22:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 1,230 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 177,912 KB
実行使用メモリ 141,088 KB
最終ジャッジ日時 2024-07-03 07:10:51
合計ジャッジ時間 26,658 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int f(int a){
  if(a%3<=1)return a%3;
  return -1;
}
int n;
vector<int> v;
typedef pair<int,int> P;
void FIN(P a,P b){
  cout<<"Yes"<<endl;
  int u=a.second,w=b.second;
  for(int i=0;i<n/2;i++){
    cout<<v[i]*f(u)<<" ";
    u/=3;
  }
  for(int i=0;i<n-n/2;i++){
    cout<<-v[n/2+i]*f(w)<<" ";
    w/=3;
  }
  for(int i=n;i<v.size();i++)cout<<0<<" ";
  cout<<endl;
  exit(0);
}
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)res*=n;
    n*=n;
    k>>=1;
  }
  return res;
}

signed main(){
  cin>>n;
  v.resize(n);
  for(int i=0;i<n;i++)cin>>v[i];
  if(n>=32)n=32;
  set<P> s;
  for(int j=0;j<pw(3,n/2);j++){
    int tmp=0,tmpj=j;
    for(int k=0;k<n/2;k++){
      tmp+=v[k]*f(tmpj);
      tmpj/=3;
    }
    s.insert(P(tmp,j));
  }

  for(int j=0;j<pw(3,n-n/2);j++){
    int tmp=0,tmpj=j;
    for(int k=0;k<n-n/2;k++){
      tmp+=v[n/2+k]*f(tmpj);
      tmpj/=3;
    }
    if(s.upper_bound(P(tmp,j))->first==tmp)FIN(*s.upper_bound(P(tmp,j)),P(tmp,j));
    if((--s.lower_bound(P(tmp,j)))->first==tmp)FIN(*--s.lower_bound(P(tmp,j)),P(tmp,j));
    if(j)if(s.lower_bound(P(tmp,j))->first==tmp)FIN(*s.lower_bound(P(tmp,j)),P(tmp,j));
  }

  cout<<"No"<<endl;
}
0