結果
問題 | No.1753 Don't cheat. |
ユーザー | sapphire__15 |
提出日時 | 2021-11-20 00:22:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 195 ms / 3,000 ms |
コード長 | 7,669 bytes |
コンパイル時間 | 1,472 ms |
コンパイル使用メモリ | 146,952 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-06-10 12:13:20 |
合計ジャッジ時間 | 6,424 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 3 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 4 ms
6,944 KB |
testcase_07 | AC | 184 ms
11,008 KB |
testcase_08 | AC | 190 ms
11,392 KB |
testcase_09 | AC | 108 ms
7,680 KB |
testcase_10 | AC | 186 ms
11,136 KB |
testcase_11 | AC | 106 ms
8,064 KB |
testcase_12 | AC | 177 ms
10,752 KB |
testcase_13 | AC | 123 ms
8,576 KB |
testcase_14 | AC | 155 ms
10,112 KB |
testcase_15 | AC | 176 ms
10,880 KB |
testcase_16 | AC | 130 ms
8,960 KB |
testcase_17 | AC | 187 ms
11,648 KB |
testcase_18 | AC | 164 ms
10,496 KB |
testcase_19 | AC | 128 ms
8,960 KB |
testcase_20 | AC | 172 ms
10,880 KB |
testcase_21 | AC | 120 ms
8,704 KB |
testcase_22 | AC | 156 ms
10,240 KB |
testcase_23 | AC | 103 ms
7,936 KB |
testcase_24 | AC | 176 ms
11,136 KB |
testcase_25 | AC | 140 ms
9,472 KB |
testcase_26 | AC | 189 ms
11,520 KB |
testcase_27 | AC | 195 ms
11,520 KB |
testcase_28 | AC | 189 ms
11,648 KB |
testcase_29 | AC | 192 ms
11,520 KB |
testcase_30 | AC | 190 ms
11,520 KB |
testcase_31 | AC | 191 ms
11,520 KB |
ソースコード
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> #include <random> #include <complex> #include <bitset> #include <iomanip> #include <memory> #include <chrono> #include <functional> #define rep(i, n, s) for(int i = (s); i < int(n); i++) #define per(i, n, s) for(int i = (n - 1); i >= int(s); i--) #define MM << " " << #define all(x) x.begin(), x.end() #define rall(x) rbegin(x), rend(x) template <class T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <class T> using MaxHeap = std::priority_queue<T>; using ll = long long; using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>; using Pdd = std::pair<double, double>; template <class T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } else { return false; } } template <class T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } else { return false; } } template <class T> void vdeb(const std::vector<T> &da) { auto n = da.size(); for (size_t i = 0; i < n; i++) { if (i == n - 1) std::cout << da[i]; else std::cout << da[i] << " "; } std::cout << std::endl; } template<class T> void vdeb(const std::vector<std::vector<T>> &da) { auto n = da.size(); for (size_t i = 0; i < n; i++) { std::cout << i << " : "; vdeb(da[i]); } std::cout << std::endl; } template <> void vdeb(const std::vector<std::string> &da) { auto n = da.size(); for (size_t i = 0; i < n; i++) { std::cout << da[i] << std::endl; } } struct modint { long long num; const static long long p = 998244353; constexpr static long long pow(long long n, long long k) {//n^k(mod p) long long ret = 1; while(k) { if(k&1) ret = ret * n % p; n = n * n % p; k >>= 1; } return ret; } // a*A + b*B = 1 constexpr static void euclid(long long &a, long long &b) { // a>=b A*b+B*(a-a/b*b)=1 if (a == 1) { a = 1; } else { long long A = b, B = a % b; euclid(A, B); b = (A - (p + a / b) % p * B % p + p) % p; a = B; } } constexpr static long long rev(const long long n) {// n*x-p*y=1 //long long q = p; //euclid(p, n, p); //return n % q; return pow(n,p-2); } constexpr modint() : num(0) {} constexpr modint(long long x) : num(x%p < 0 ? x%p+p : x%p) {} constexpr modint inv() const {return rev(num);} modint operator-() const {return modint(p-num);} modint& operator+=(const modint &other){ num = (num + other.num) % p; return *this; } modint& operator-=(const modint &other){ num = (num - other.num + p) % p; return *this; } modint& operator*=(const modint &other){ num = (num * other.num) % p; return *this; } modint& operator/=(const modint &other){ (*this) *= other.inv(); return *this; } modint& operator+=(const long long &other){ num = (num + other) % p; return *this; } modint& operator-=(const long long &other){ num = (num - other + p) % p; return *this; } modint& operator*=(const long long &other){ num = (num * other) % p; return *this; } modint& operator/=(const long long &other){ (*this) *= rev(other); return *this; } modint& operator++(){return *this += 1;} modint& operator--(){return *this -= 1;} modint& operator=(const long long &other){return (*this) = modint(other);} modint operator+(const modint &other) const{return modint(*this) += other;} modint operator-(const modint &other) const{return modint(*this) -= other;} modint operator*(const modint &other) const{return modint(*this) *= other;} modint operator/(const modint &other) const{return modint(*this) /= other;} modint operator+(const long long &other) const{return modint(*this) += other;} modint operator-(const long long &other) const{return modint(*this) -= other;} modint operator*(const long long &other) const{return modint(*this) *= other;} modint operator/(const long long &other) const{return modint(*this) /= other;} bool operator==(const modint &other) const{return num == other.num;} }; std::istream& operator>>(std::istream &is, modint x) { is >> x.num; return is; } std::ostream& operator<<(std::ostream &os, const modint &x){ os << x.num; return os; } /** * @brief fast-Walsh–Hadamard-transform * * @tparam T element type of vector */ template<class T> std::vector<T> fast_hadamard_transform(std::vector<T> vec) { using hadamard_size_type = typename std::vector<T>::size_type; auto vec_size = vec.size(); assert(((vec_size - 1)&vec_size) == 0); // check vec_size is power of 2 for(hadamard_size_type i = 1; i < vec_size; i = i << 1) { auto mask = ~i; for(auto j = i; j < vec_size; j = (j+1)|i) { T a = vec[j&mask]; T &b = vec[j]; vec[j&mask] += b; b = a - b; } } return vec; } /** * @brief invrese-fast-Walsh–Hadamard-transform * * @tparam T std::vector<S> * @tparam S element type of T * @param inv_vec_size inverse of size of vec */ template<class T, class S> auto inv_fast_hadamard_transform (T &&vec, S inv_vec_size) { auto &&ret = fast_hadamard_transform(std::forward<T>(vec)); for(auto &i : ret) i *= inv_vec_size; return ret; } /** * @brief invrese-fast-Walsh–Hadamard-transform * * @tparam T std::vector<> */ template<class T> auto inv_fast_hadamard_transform (T &&vec) { auto vec_size = vec.size(); auto &&ret = fast_hadamard_transform(std::forward<T>(vec)); for(auto &i : ret) i /= vec_size; return ret; } /** * @brief bitwise xor convolution using fast-Walsh–Hadamard-transform. * * @tparam T element type of vector */ template<class T> std::vector<T> xor_convolution (const std::vector<T> &a, const std::vector<T> &b) { using xorconv_size_type = typename std::vector<T>::size_type; assert(a.size() == b.size()); auto vec_size = a.size(); std::vector<T> &&transa = fast_hadamard_transform(a), &&transb = fast_hadamard_transform(b); for(xorconv_size_type i = 0; i < vec_size; i++) { transa[i] *= transb[i]; } std::vector<T> &&ret = inv_fast_hadamard_transform(transa); return ret; } using namespace std; using mint = modint; const int M = 1<<10; const mint INV = mint(1) / M; int main() { int n; cin >> n; vector<int> da(n+1); rep(i,n+1,0) { cin >> da[i]; } int su = accumulate(all(da), 0); vector<mint> base(M); rep(i,n+1,1) { base[i] += da[i]; base[i] /= su; } vector<vector<mint>> li(n+1, base); base = fast_hadamard_transform(base); rep(i,M,0) base[i] = base[i] / (mint(1) - base[i]); base = inv_fast_hadamard_transform(base, INV); rep(i,n+1,1) { li[i][i] = 0; auto tmp = fast_hadamard_transform(li[i]); rep(i,M,0) tmp[i] = tmp[i] / (mint(1) - tmp[i]); li[i] = inv_fast_hadamard_transform(tmp, INV); } mint ans = (base[0] + 1) * da[0] / su; rep(i,n+1,1) { ans += (base[i] - li[i][i]) * da[0] / su; } cout << mint(1) - ans << endl; }