結果

問題 No.1241 Eternal Tours
ユーザー tko919tko919
提出日時 2021-02-10 23:29:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 467 ms / 6,000 ms
コード長 4,422 bytes
コンパイル時間 2,819 ms
コンパイル使用メモリ 207,372 KB
実行使用メモリ 32,584 KB
最終ジャッジ日時 2023-09-22 20:02:38
合計ジャッジ時間 10,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 140 ms
11,600 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 207 ms
7,912 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 52 ms
4,724 KB
testcase_17 AC 467 ms
32,584 KB
testcase_18 AC 439 ms
13,872 KB
testcase_19 AC 400 ms
11,368 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 427 ms
22,064 KB
testcase_23 AC 14 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 257 ms
11,600 KB
testcase_29 AC 261 ms
11,672 KB
testcase_30 AC 307 ms
11,800 KB
testcase_31 AC 201 ms
7,496 KB
testcase_32 AC 461 ms
32,576 KB
testcase_33 AC 430 ms
11,224 KB
testcase_34 AC 406 ms
11,668 KB
testcase_35 AC 405 ms
11,808 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 440 ms
11,140 KB
testcase_39 AC 428 ms
11,224 KB
testcase_40 AC 423 ms
11,656 KB
testcase_41 AC 327 ms
32,536 KB
testcase_42 AC 275 ms
11,160 KB
testcase_43 AC 269 ms
11,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=998244353>struct fp {
   using uint=unsigned; uint v;
   static uint get_mod(){return mod;}
   int inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp(ll x=0){init(x%mod+mod);}
   fp& init(uint x){v=(x<mod?x:x-mod); return *this;}
   fp operator-()const{return fp()-*this;}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){return init(v+x.v);}
   fp& operator-=(const fp& x){return init(v+mod-x.v);}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
   friend istream& operator>>(istream& is,fp& x){is>>x.v; return is;}
   friend ostream& operator<<(ostream& os,fp& x){os<<x.v; return os;}
}; using Fp=fp<>;
template<typename T>struct factorial {
   vector<T> Fact,Finv,Inv;
   factorial(int maxx){
      Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
      Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1;
      rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv();
      for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];}
   }
   T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);}
   T inv(int n){if(n<0)return 0; return Inv[n];}
   T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);}
   T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);}
};

template<typename T=Fp,unsigned p=3>struct NTT{
   vector<T> rt,irt;
   NTT(int lg=21){
      unsigned m=T::get_mod()-1; T prt=p;
      rt.resize(lg); irt.resize(lg);
      rep(k,0,lg){
         rt[k]=-prt.pow(m>>(k+2));
         irt[k]=rt[k].inv();
      }
   }
   void ntt(vector<T>& f,bool inv=0){
      int n=f.size();
      if(inv){
         for(int m=1;m<n;m<<=1){ T w=1;
            for(int s=0,t=0;s<n;s+=m*2){
               for(int i=s,j=s+m;i<s+m;i++,j++){
                  auto x=f[i],y=f[j];
                  f[i]=x+y; f[j]=(x-y)*w;
               } w*=irt[__builtin_ctz(++t)];
            }
         } T mul=T(n).inv(); rep(i,0,n)f[i]*=mul;
      }else{
         for(int m=n;m>>=1;){ T w=1;
            for(int s=0,t=0;s<n;s+=m*2){
               for(int i=s,j=s+m;i<s+m;i++,j++){
                  auto x=f[i],y=f[j]*w;
                  f[i]=x+y; f[j]=x-y;
               } w*=rt[__builtin_ctz(++t)];
            }
         }
      }
   }
   vector<T> mult(const vector<T>& a,const vector<T>& b,bool same=0){
      if(a.empty() or b.empty())return vector<T>();
      int n=a.size()+b.size()-1,m=1<<__lg(n*2-1);
      vector<T> res(m); rep(i,0,a.size()){res[i]=a[i];} ntt(res);
      if(same)rep(i,0,m)res[i]*=res[i];
      else{
         vector<T> c(m); rep(i,0,b.size())c[i]=b[i];
         ntt(c); rep(i,0,m)res[i]*=c[i];
      } ntt(res,1); return res;
   }
};

NTT<Fp,3> ntt;
void ntt2d(vector<vector<Fp>>& a,bool inv=0){
   for(auto& v:a)ntt.ntt(v,inv);
   int h=a.size(),w=a[0].size();
   rep(j,0,w){
      vector<Fp> v(h);
      rep(i,0,h)v[i]=a[i][j];
      ntt.ntt(v,inv);
      rep(i,0,h)a[i][j]=v[i];
   }
}

int main(){
   int x,y,a,b,c,d; ll t;
   cin>>x>>y>>t>>a>>b>>c>>d;
   int h=1<<(x+1),w=1<<(y+1);
   vector base(h,vector<Fp>(w));
   auto step=base;

   base[a][b]=base[h-a][w-b]=1;
   base[a][w-b]=base[h-a][b]=-1;
   step[0][0]=step[0][1]=step[1][0]=step[0][w-1]=step[h-1][0]=1;

   ntt2d(base); ntt2d(step);
   rep(i,0,h)rep(j,0,w)base[i][j]*=step[i][j].pow(t);
   ntt2d(base,1);
   
   cout<<base[c][d]<<'\n';
   return 0;
}
0