結果
問題 | No.612 Move on grid |
ユーザー | firiexp |
提出日時 | 2019-12-27 09:46:41 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,500 ms |
コード長 | 2,877 bytes |
コンパイル時間 | 967 ms |
コンパイル使用メモリ | 101,160 KB |
実行使用メモリ | 42,496 KB |
最終ジャッジ日時 | 2024-11-15 19:14:17 |
合計ジャッジ時間 | 2,615 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 10 ms
12,800 KB |
testcase_04 | AC | 74 ms
42,496 KB |
testcase_05 | AC | 68 ms
42,496 KB |
testcase_06 | AC | 68 ms
42,496 KB |
testcase_07 | AC | 74 ms
42,496 KB |
testcase_08 | AC | 67 ms
42,496 KB |
testcase_09 | AC | 48 ms
42,496 KB |
testcase_10 | AC | 33 ms
27,776 KB |
testcase_11 | AC | 13 ms
15,104 KB |
testcase_12 | AC | 45 ms
32,512 KB |
testcase_13 | AC | 22 ms
19,840 KB |
testcase_14 | AC | 55 ms
37,248 KB |
testcase_15 | AC | 15 ms
15,744 KB |
testcase_16 | AC | 64 ms
42,112 KB |
testcase_17 | AC | 22 ms
20,480 KB |
testcase_18 | AC | 53 ms
37,888 KB |
testcase_19 | AC | 37 ms
30,080 KB |
testcase_20 | AC | 52 ms
40,320 KB |
ソースコード
#include <limits> #include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; template <class T, class U> vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); } template<class... Ts, class U> auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); } template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); } template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); } template<u32 M = 1000000007> struct modint{ u32 val; modint(): val(0){} template<typename T> modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;} modint pow(ll k) const { modint res(1), x(val); while(k){ if(k&1) res *= x; x *= x; k >>= 1; } return res; } template<typename T> modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;} modint inv() const {return pow(M-2);} modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;} modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;} modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;} modint& operator/=(modint a){return (*this) *= a.inv();} modint operator+(modint a) const {return modint(val) +=a;} modint operator-(modint a) const {return modint(val) -=a;} modint operator*(modint a) const {return modint(val) *=a;} modint operator/(modint a) const {return modint(val) /=a;} modint operator-(){return modint(M-val);} bool operator==(const modint a) const {return val == a.val;} bool operator!=(const modint a) const {return val != a.val;} bool operator<(const modint a) const {return val < a.val;} }; using mint = modint<MOD>; int main() { int t, a, b, c, d, e; cin >> t >> a >> b >> c >> d >> e; a = abs(a); b = abs(b); c = abs(c); int M = 10001, X = max({a, b, c}); auto dp = make_v(t+1, 2*M+1, mint(0)); int l = M, r = M; dp[0][M] = 1; for (int i = 0; i < t; ++i) { for (int j = l; j <= r; ++j) { dp[i+1][j+a] += dp[i][j]; dp[i+1][j-a] += dp[i][j]; dp[i+1][j+b] += dp[i][j]; dp[i+1][j-b] += dp[i][j]; dp[i+1][j+c] += dp[i][j]; dp[i+1][j-c] += dp[i][j]; } l -= X; r += X; } mint ans; for (int i = d; i <= e; ++i) { ans += dp[t][i+M]; } cout << ans.val << "\n"; return 0; }