結果

問題 No.1885 Flat Permutation
ユーザー inksamuraiinksamurai
提出日時 2022-03-26 03:15:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,980 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 164,120 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 12:47:42
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 4 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 4 ms
6,940 KB
testcase_29 AC 3 ms
6,944 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 4 ms
6,944 KB
testcase_32 AC 4 ms
6,940 KB
testcase_33 AC 4 ms
6,944 KB
testcase_34 AC 3 ms
6,944 KB
testcase_35 AC 4 ms
6,940 KB
testcase_36 AC 4 ms
6,944 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 4 ms
6,944 KB
testcase_40 AC 3 ms
6,940 KB
testcase_41 AC 3 ms
6,944 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 4 ms
6,944 KB
testcase_44 AC 3 ms
6,940 KB
testcase_45 AC 4 ms
6,940 KB
testcase_46 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3ulnVOy ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<"\n";}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

//snuke's mod int
template <ll mod>
struct modint{
	ll x; // typedef long long ll;
	modint(ll x=0):x((x%mod+mod)%mod){}
	modint operator-()const{return modint(-x);}
	modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;}
	modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
	modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;}
	modint operator+(const modint a)const{modint res(*this); return res+=a;}
	modint operator-(const modint a)const{modint res(*this); return res-=a;}
	modint operator*(const modint a)const{modint res(*this); return res*=a;}
	modint pow(ll n)const{
		modint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modint inv()const{return pow(mod-2);}
};
using mint=modint<998244353>;

signed main(){
_3ulnVOy;
	int n,l,r;
	cin>>n>>l>>r;
	if(l>r) swap(l,r);

	// {
	// 	vi a;
	// 	rep(i,n) a.pb(i);

	// 	int ans1=0;
	// 	do{
	// 		if(a[0]!=l-1 or a.back()!=r-1) continue;
	// 		bool pok=1;
	// 		rng(i,1,n){
	// 			if(abs(a[i]-a[i-1])>2){
	// 				pok=0;
	// 				break;
	// 			}
	// 		}
	// 		if(not pok) continue;
	// 		ans1+=1;
	// 	}while(next_permutation(a.begin(),a.end()));

	// 	print(ans1);
	// }

	vec(mint) faf(n+1);
	faf[1]=1;
	rng(i,2,n+1){
		faf[i]=faf[i-1];
		if(i>3) faf[i]+=faf[i-3];
	}

	mint ans=0;
	if(l==1){
		ans=faf[r-1+(r==n)];
	}else{
		// print(r-l);
		ans=faf[r-l-1+(r==n)];
	}
	print(ans.x);
//
	return 0;
}
0