結果

問題 No.473 和と積の和
ユーザー rickythetarickytheta
提出日時 2016-12-23 00:29:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,307 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 156,492 KB
実行使用メモリ 287,640 KB
最終ジャッジ日時 2023-08-22 07:26:45
合計ジャッジ時間 22,000 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 330 ms
44,720 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 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,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,504 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2,259 ms
249,472 KB
testcase_26 AC 158 ms
26,692 KB
testcase_27 AC 270 ms
43,844 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 14 ms
4,376 KB
testcase_30 AC 11 ms
4,380 KB
testcase_31 AC 9 ms
4,376 KB
testcase_32 AC 7 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 TLE -
testcase_35 AC 2,891 ms
248,800 KB
testcase_36 AC 29 ms
5,004 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 2,798 ms
243,184 KB
testcase_39 AC 2,783 ms
198,836 KB
testcase_40 TLE -
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 10 ms
5,460 KB
testcase_44 AC 68 ms
16,648 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

struct myhash{
  size_t operator()(const vi &v) const {
    hash<int> hsh;
    size_t ret=0;
    for(int x:v){
      ret ^= hsh(x);
      ret = ret ^ (ret<<13);
      ret = ret ^ (ret>>17);
      ret = ret ^ (ret<<5);
    }
    return ret;
  }
};

int main(){
  int n;
  int x;
  cin>>n>>x;
  if(n>=30){
    puts("0");
    return 0;
  }
  x++;
  typedef unordered_set<vi,myhash> ss;
  // factorize x with n numbers
  ss S;
  S.insert(vi(n,1));
  for(int p=2;p*p<=x;p++){
    while(x%p==0){
      x/=p;
      ss nxt;
      for(const vi &X : S){
        REP(i,n){
          if(i>0 && X[i]==X[i-1])continue;
          vi add(n,0);
          int nw = X[i]*p;
          int it = 0;
          REP(j,n){
            while(it==i)it++;
            if(it<n && X[it]<nw)add[j]=X[it++];
            else{
              add[j]=nw;
              nw = (1<<30) + 252;
            }
          }
          nxt.insert(add);
        }
      }
      swap(S,nxt);
    }
  }
  if(x!=1){
    ss nxt;
    for(const vi &X : S){
      REP(i,n){
        if(i>0 && X[i]==X[i-1])continue;
        vi add(n,0);
        int nw = X[i]*x;
        int it = 0;
        REP(j,n){
          while(it==i)it++;
          if(it<n && X[it]<nw)add[j]=X[it++];
          else{
            add[j]=nw;
            nw = (1<<30) + 252;
          }
        }
        nxt.insert(add);
      }
    }
    swap(S,nxt);
  }
  int ans = 0;
  for(const vi &X : S){
    if(X[0]!=1)ans++;
  }
  printf("%d\n",ans);
  return 0;
}
0