結果

問題 No.1017 Reiwa Sequence
ユーザー cureskolcureskol
提出日時 2020-04-04 12:53:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,407 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 174,828 KB
実行使用メモリ 13,584 KB
最終ジャッジ日時 2023-09-16 05:38:32
合計ジャッジ時間 14,318 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 28 ms
5,108 KB
testcase_13 AC 89 ms
12,464 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 10 ms
4,376 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 7 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 6 ms
4,376 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 5 ms
4,380 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 9 ms
4,376 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 7 ms
4,376 KB
testcase_40 AC 124 ms
12,716 KB
testcase_41 AC 125 ms
12,004 KB
testcase_42 AC 119 ms
12,132 KB
testcase_43 AC 125 ms
11,592 KB
testcase_44 AC 129 ms
12,004 KB
testcase_45 AC 123 ms
12,640 KB
testcase_46 AC 123 ms
12,256 KB
testcase_47 AC 126 ms
11,780 KB
testcase_48 AC 140 ms
12,176 KB
testcase_49 AC 146 ms
12,164 KB
testcase_50 AC 149 ms
13,584 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 8 ms
4,376 KB
testcase_53 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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>=24)n=24;
  vector<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.push_back(P(tmp,j));
  }

  sort(s.begin(),s.end());

  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;
    }
    int l=-1,r=s.size();
    while(r-l>1){
      int m=(r+l)>>1;
      if(s[m].first>=tmp)r=m;
      else l=m;
    }
    if(r<s.size()&&s[r].first==tmp&&s[r].second+j)FIN(s[r],P(tmp,j));
    r++;
    if(r<s.size()&&s[r].first==tmp&&s[r].second+j)FIN(s[r],P(tmp,j));
    if(l>=0&&s[l].second+j&&s[l].first==tmp)FIN(s[l],P(tmp,j));
    l--;
    if(l>=0&&s[l].second+j&&s[l].first==tmp)FIN(s[l],P(tmp,j));
  }

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