結果

問題 No.93 ペガサス
ユーザー hogloidhogloid
提出日時 2016-05-12 23:27:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 2,957 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 161,864 KB
実行使用メモリ 19,220 KB
最終ジャッジ日時 2024-04-15 15:24:48
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,072 KB
testcase_01 AC 8 ms
19,072 KB
testcase_02 AC 7 ms
19,072 KB
testcase_03 AC 8 ms
19,116 KB
testcase_04 AC 11 ms
19,220 KB
testcase_05 AC 9 ms
19,172 KB
testcase_06 AC 8 ms
19,200 KB
testcase_07 AC 19 ms
19,072 KB
testcase_08 AC 13 ms
19,200 KB
testcase_09 AC 27 ms
19,080 KB
testcase_10 AC 8 ms
19,080 KB
testcase_11 AC 8 ms
19,072 KB
testcase_12 AC 24 ms
19,184 KB
testcase_13 AC 15 ms
19,200 KB
testcase_14 AC 9 ms
19,144 KB
testcase_15 AC 22 ms
19,200 KB
testcase_16 AC 10 ms
19,104 KB
testcase_17 AC 8 ms
19,200 KB
testcase_18 AC 8 ms
19,072 KB
testcase_19 AC 29 ms
19,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}


template<lint mod>
struct Int_{
  unsigned x;
  unsigned mpow(Int_ a,unsigned k){
    Int_ res=1;
    while(k){
      if(k&1) res=res*a;
      a=a*a;
      k>>=1;
    }
    return res.x;
  }
  unsigned inverse(Int_ a){
    return mpow(a,mod-2);
  }
  Int_(): x(0) { }
  Int_(long long sig) {
    int sigt=sig%mod;
    if(sigt<0) sigt+=mod;
    x=sigt;
  }
  unsigned get() const { return (unsigned)x; }
  
  Int_ &operator+=(Int_ that) { if((x += that.x) >= mod) x -= mod; return *this; }
  Int_ &operator-=(Int_ that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
  Int_ &operator*=(Int_ that) { x = (unsigned long long)x * that.x % mod; return *this; }
  Int_ &operator=(Int_ that) { x=that.x; return *this;}
  Int_ &operator/=(Int_ that) { x=(unsigned long long) x * inverse(that.x)%mod; return *this;}
  bool operator==(Int_ that) const { return x==that.x; }
  bool operator!=(Int_ that) const { return x!=that.x; }

  Int_ operator-() const { return Int_(0)-Int_(*this);}
  Int_ operator+(Int_ that) const { return Int_(*this) += that; }
  Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
  Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
  Int_ operator/(Int_ that) const { return Int_(*this) /= that; }

};

namespace std{
  template<lint mod>
  ostream &operator <<(ostream& out,const Int_<mod>& a){
    out<<a.get();
    return out;
  }
  template<lint mod>
  istream &operator >>(istream& in,Int_<mod>& a){
    in>>a.x;
    return in;
  }
};

typedef Int_<1000000007> Int;
//const int INF=5e8;

Int dp[1005][1005][2][2];

int n;
int main(){
  cin>>n;
  dp[1][0][0][0]=1;
  dp[2][0][0][0]=2;
  for(int i=2;i<n;++i) REP(j,i+1) REP(t,2) REP(t2,2) if(dp[i][j][t][t2]!=0){
    Int val=dp[i][j][t][t2]; 
    dp[i+1][j+1][t2][1]+=val*(2-t);
    dp[i+1][j][t2][1]+=val*t;
    dp[i+1][j][t2][0]+=val*(i+1-j-(2-t));
    if(j) dp[i+1][j-1][t2][0]+=val*(j-t-t2);
    if(j) dp[i+1][j-1][0][0]+=val*t2;
  }
  Int res=0;
  REP(t,2) REP(t2,2) res+=dp[n][0][t][t2];
  cout<<res<<endl;
  return 0;
}


0