結果
問題 | No.1885 Flat Permutation |
ユーザー |
![]() |
提出日時 | 2022-03-26 12:17:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,575 bytes |
コンパイル時間 | 1,126 ms |
コンパイル使用メモリ | 86,528 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 04:15:42 |
合計ジャッジ時間 | 1,933 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 998244353; const ll INF = 1e16; int main() { ll n, a, b; cin >> n >> a >> b; if(a > b) { swap(a, b); } vl f(n+10); f[1] = 1; f[2] = 1; f[3] = 1; exrep(i, 4, n) { f[i] = (f[i-1] + f[i-3]) % mod; } if(b == a+1) { // 領域2がないとき if(a == 1 || b == n) { // 領域1のみ、または、領域3のみのとき out(1); } else { // 領域1も領域3もあるとき out(0); } re0; } else if(a == 1 && b == n) { // 領域2のみのとき out(f[n]); } else if(a == 1 || b == n) { // 領域1がないとき、または、領域3がないとき out(f[b - a]); } else { // 領域1~3すべてあるとき out(f[b - a - 1]); } re0; }