結果

問題 No.1354 Sambo's Treasure
ユーザー ningenMeningenMe
提出日時 2021-01-17 15:50:20
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 9,185 bytes
コンパイル時間 3,118 ms
コンパイル使用メモリ 227,048 KB
実行使用メモリ 98,536 KB
最終ジャッジ日時 2024-12-16 03:59:04
合計ジャッジ時間 12,260 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
14,932 KB
testcase_01 AC 26 ms
15,112 KB
testcase_02 AC 29 ms
14,880 KB
testcase_03 AC 26 ms
14,920 KB
testcase_04 AC 25 ms
14,924 KB
testcase_05 AC 25 ms
14,928 KB
testcase_06 AC 28 ms
14,932 KB
testcase_07 AC 25 ms
14,948 KB
testcase_08 AC 24 ms
14,920 KB
testcase_09 AC 25 ms
14,928 KB
testcase_10 AC 25 ms
14,936 KB
testcase_11 AC 27 ms
15,024 KB
testcase_12 AC 26 ms
14,920 KB
testcase_13 AC 25 ms
14,812 KB
testcase_14 AC 23 ms
15,000 KB
testcase_15 AC 28 ms
14,916 KB
testcase_16 AC 25 ms
14,936 KB
testcase_17 AC 24 ms
14,996 KB
testcase_18 AC 26 ms
14,940 KB
testcase_19 AC 25 ms
14,988 KB
testcase_20 AC 27 ms
14,944 KB
testcase_21 AC 26 ms
14,984 KB
testcase_22 AC 26 ms
14,968 KB
testcase_23 AC 237 ms
92,396 KB
testcase_24 AC 251 ms
98,536 KB
testcase_25 AC 239 ms
93,824 KB
testcase_26 AC 241 ms
93,800 KB
testcase_27 AC 242 ms
92,296 KB
testcase_28 AC 239 ms
92,196 KB
testcase_29 AC 248 ms
98,516 KB
testcase_30 AC 235 ms
90,704 KB
testcase_31 AC 242 ms
93,792 KB
testcase_32 AC 242 ms
92,244 KB
testcase_33 AC 237 ms
92,260 KB
testcase_34 AC 244 ms
96,864 KB
testcase_35 AC 242 ms
95,384 KB
testcase_36 AC 250 ms
97,024 KB
testcase_37 AC 251 ms
96,976 KB
testcase_38 AC 238 ms
90,700 KB
testcase_39 AC 244 ms
95,400 KB
testcase_40 AC 249 ms
96,964 KB
testcase_41 AC 243 ms
93,852 KB
testcase_42 AC 242 ms
92,260 KB
testcase_43 AC 66 ms
15,168 KB
testcase_44 AC 67 ms
15,076 KB
testcase_45 AC 70 ms
15,004 KB
testcase_46 AC 74 ms
15,096 KB
testcase_47 AC 73 ms
15,128 KB
testcase_48 AC 86 ms
15,168 KB
testcase_49 AC 71 ms
15,108 KB
testcase_50 AC 72 ms
15,012 KB
testcase_51 AC 84 ms
15,160 KB
testcase_52 AC 81 ms
15,120 KB
testcase_53 AC 80 ms
15,176 KB
testcase_54 AC 72 ms
15,180 KB
testcase_55 AC 68 ms
15,100 KB
testcase_56 AC 81 ms
15,124 KB
testcase_57 AC 79 ms
15,164 KB
testcase_58 AC 76 ms
15,108 KB
testcase_59 AC 72 ms
15,172 KB
testcase_60 AC 80 ms
15,164 KB
testcase_61 AC 70 ms
15,216 KB
testcase_62 AC 87 ms
15,124 KB
testcase_63 AC 237 ms
90,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using int128 = __int128_t;
using int64 = long long;
using int32 = int;
using uint128 = __uint128_t;
using uint64 = unsigned long long;
using uint32 = unsigned int;
#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>;
constexpr int64 MOD = 1'000'000'000LL + 7; //'
constexpr int64 MOD2 = 998244353;
constexpr int64 HIGHINF = 1'000'000'000'000'000'000LL;
constexpr int64 LOWINF = 1'000'000'000'000'000LL; //'
constexpr long double PI = 3.1415926535897932384626433L;
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x
    .second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj
    .begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr !
    = obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "")
    << obj[i]; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const deque<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") <<
    obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer,
    delemiter) ) res.push_back(buffer); return res;}
inline constexpr int msb(int x) {return x?31-__builtin_clz(x):-1;}
inline constexpr int64 ceil_div(const int64 a,const int64 b) {return (a+(b-1))/b;}// return ceil(a/b)
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}
/*
* @title ModInt
* @docs md/util/ModInt.md
*/
template<long long mod> class ModInt {
public:
long long x;
constexpr ModInt():x(0) {}
constexpr ModInt(long long y) : x(y>=0?(y%mod): (mod - (-y)%mod)%mod) {}
ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
ModInt &operator+=(const long long y) {ModInt p(y);if((x += p.x) >= mod) x -= mod;return *this;}
ModInt &operator+=(const int y) {ModInt p(y);if((x += p.x) >= mod) x -= mod;return *this;}
ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
ModInt &operator-=(const long long y) {ModInt p(y);if((x += mod - p.x) >= mod) x -= mod;return *this;}
ModInt &operator-=(const int y) {ModInt p(y);if((x += mod - p.x) >= mod) x -= mod;return *this;}
ModInt &operator*=(const ModInt &p) {x = (x * p.x % mod);return *this;}
ModInt &operator*=(const long long y) {ModInt p(y);x = (x * p.x % mod);return *this;}
ModInt &operator*=(const int y) {ModInt p(y);x = (x * p.x % mod);return *this;}
ModInt &operator^=(const ModInt &p) {x = (x ^ p.x) % mod;return *this;}
ModInt &operator^=(const long long y) {ModInt p(y);x = (x ^ p.x) % mod;return *this;}
ModInt &operator^=(const int y) {ModInt p(y);x = (x ^ p.x) % mod;return *this;}
ModInt &operator/=(const ModInt &p) {*this *= p.inv();return *this;}
ModInt &operator/=(const long long y) {ModInt p(y);*this *= p.inv();return *this;}
ModInt &operator/=(const int y) {ModInt p(y);*this *= p.inv();return *this;}
ModInt operator=(const int y) {ModInt p(y);*this = p;return *this;}
ModInt operator=(const long long y) {ModInt p(y);*this = p;return *this;}
ModInt operator-() const {return ModInt(-x); }
ModInt operator++() {x++;if(x>=mod) x-=mod;return *this;}
ModInt operator--() {x--;if(x<0) x+=mod;return *this;}
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
ModInt operator^(const ModInt &p) const { return ModInt(*this) ^= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inv() const {int a=x,b=mod,u=1,v=0,t;while(b > 0) {t = a / b;swap(a -= t * b, b);swap(u -= t * v, v);} return ModInt(u);}
ModInt pow(long long n) const {ModInt ret(1), mul(x);for(;n > 0;mul *= mul,n >>= 1) if(n & 1) ret *= mul;return ret;}
friend ostream &operator<<(ostream &os, const ModInt &p) {return os << p.x;}
friend istream &operator>>(istream &is, ModInt &a) {long long t;is >> t;a = ModInt<mod>(t);return (is);}
};
using modint = ModInt<MOD2>;
/*
* @title CombinationMod - mod
* @docs md/math/CombinationMod.md
*/
template<long long mod> class CombinationMod {
vector<long long> fac,finv,inv;
public:
CombinationMod(int N) : fac(N + 1), finv(N + 1), inv(N + 1) {
fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
for (int i = 2; i <= N; ++i) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod%i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
inline long long binom(int n, int k) {
return ((n < 0 || k < 0 || n < k) ? 0 : fac[n] * (finv[k] * finv[n - k] % mod) % mod);
}
inline long long factorial(int n) {
return fac[n];
}
};
//verify https://atcoder.jp/contests/abc021/tasks/abc021_d
using Pa = pair<int64,int64>;
CombinationMod<MOD2> CM(500000);
//s to g s: vp.front, g: vp.back
modint f(vector<Pa> vp) {
int N = vp.size();
for(int i=N-1; 0<=i; --i) vp[i].first -= vp[0].first;
for(int i=N-1; 0<=i; --i) vp[i].second -= vp[0].second;
vector<modint> dp(N,0);
for(int i=1;i<N;++i) {
dp[i] = CM.binom(vp[i].first+vp[i].second,vp[i].first);
for(int j=1;j<i;++j) {
int64 y = vp[i].first - vp[j].first;
int64 x = vp[i].second - vp[j].second;
if(y<0 || x<0) continue;
dp[i] -= dp[j]*CM.binom(y+x,x);
}
}
return dp.back();
}
vector<modint> calc(vector<Pa> vp) {
int N = vp.size();
auto coe = multivector(N,N,modint(0));
for(int i=0;i+1<N;++i) {
vector<Pa> tmp;
tmp.push_back(vp[i]);
for(int j=i+1;j<N;++j) {
tmp.push_back(vp[j]);
coe[i][j] = f(tmp);
}
}
auto dp = multivector(N,N,modint(0));
dp[0][0] = 1;
for(int i=0;i<N;++i) {
for(int j=i+1; j<N;++j) {
for(int k=0;k<N;++k) {
if(j!=N-1 && k+1<=N) dp[j][k+1] += dp[i][k]*coe[i][j];
if(j==N-1) dp[j][k] += dp[i][k]*coe[i][j];
}
}
}
return dp[N-1];
}
/**
* @url
* @est
*/
int main() {
cin.tie(0);ios::sync_with_stdio(false);
int N,M,L,K; cin >> N >> M >> L >> K;
vector<int64> cy(M+2),cx(M+2),dy(L),dx(L);
cy[0]=cx[0]=0, cy[M+1]=cx[M+1]=N;
for(int i=1;i<=M;++i) cin >> cy[i] >> cx[i];
for(int i=0;i< L;++i) cin >> dy[i] >> dx[i];
auto dp = multivector(M+2,L+1,modint(0));
dp[0][0] = 1;
for(int i=0; i+1 < M+2; ++i) {
Pa s = {cy[i] ,cx[i]};
Pa g = {cy[i+1],cx[i+1]};
vector<Pa> vp;
vp.push_back(s);
vp.push_back(g);
int flg = 0;
for(int j=0;j<L;++j) {
if(s.first == dy[j] && s.second == dx[j]) continue;
if(g.first == dy[j] && g.second == dx[j]) {
flg = 1;
continue;
}
if(s.first <= dy[j] && s.second <= dx[j] && dy[j] <= g.first && dx[j] <= g.second) {
vp.emplace_back(dy[j],dx[j]);
}
}
sort(ALL(vp),[&](Pa l,Pa r){return l.first+l.second < r.first+r.second;});
auto tp = calc(vp);
int X = tp.size();
for(int j=0; j<=L; ++j) {
for(int k=0; k<X; ++k) {
if(j + k + flg <= L) {
dp[i+1][j+k+flg] += dp[i][j]*tp[k];
}
}
}
}
modint ans = 0;
for(int i=0;i<=L;++i) if(i <= K) ans += dp[M+1][i];
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0