QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#475099 | #9116. DRD String | ucup-team008# | AC ✓ | 13ms | 11016kb | C++17 | 7.9kb | 2024-07-13 11:20:57 | 2024-07-13 11:20:58 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(0) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
template<class T>
bool updmin(T& a, T b) {
if(b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool updmax(T& a, T b) {
if(b > a) {
a = b;
return true;
}
return false;
}
typedef int64_t ll;
struct barrett_reduction {
unsigned mod;
uint64_t div;
barrett_reduction(unsigned m) : mod(m), div(-1LLU / m) {}
unsigned operator()(uint64_t a) const {
#ifdef __SIZEOF_INT128__
uint64_t q = uint64_t(__uint128_t(div) * a >> 64);
uint64_t r = a - q * mod;
return unsigned(r < mod ? r : r - mod);
#endif
return unsigned(a % mod);
}
};
template<const int &MOD, const barrett_reduction &barrett>
struct _b_int {
int val;
_b_int(int64_t v = 0) {
if (v < 0) v = v % MOD + MOD;
if (v >= MOD) v %= MOD;
val = int(v);
}
_b_int(uint64_t v) {
if (v >= uint64_t(MOD)) v %= MOD;
val = int(v);
}
_b_int(int v) : _b_int(int64_t(v)) {}
_b_int(unsigned v) : _b_int(uint64_t(v)) {}
static int inv_mod(int a, int m = MOD) {
// https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
int g = m, r = a, x = 0, y = 1;
while (r != 0) {
int q = g / r;
g %= r; swap(g, r);
x -= q * y; swap(x, y);
}
return x < 0 ? x + m : x;
}
explicit operator int() const { return val; }
explicit operator unsigned() const { return val; }
explicit operator int64_t() const { return val; }
explicit operator uint64_t() const { return val; }
explicit operator double() const { return val; }
explicit operator long double() const { return val; }
_b_int& operator+=(const _b_int &other) {
val -= MOD - other.val;
if (val < 0) val += MOD;
return *this;
}
_b_int& operator-=(const _b_int &other) {
val -= other.val;
if (val < 0) val += MOD;
return *this;
}
static unsigned fast_mod(uint64_t x) {
#if !defined(_WIN32) || defined(_WIN64)
return barrett(x);
#endif
// Optimized mod for Codeforces 32-bit machines.
// x must be less than 2^32 * MOD for this to work, so that x / MOD fits in an unsigned 32-bit int.
unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
unsigned quot, rem;
asm("divl %4\n"
: "=a" (quot), "=d" (rem)
: "d" (x_high), "a" (x_low), "r" (MOD));
return rem;
}
_b_int& operator*=(const _b_int &other) {
val = fast_mod(uint64_t(val) * other.val);
return *this;
}
_b_int& operator/=(const _b_int &other) {
return *this *= other.inv();
}
friend _b_int operator+(const _b_int &a, const _b_int &b) { return _b_int(a) += b; }
friend _b_int operator-(const _b_int &a, const _b_int &b) { return _b_int(a) -= b; }
friend _b_int operator*(const _b_int &a, const _b_int &b) { return _b_int(a) *= b; }
friend _b_int operator/(const _b_int &a, const _b_int &b) { return _b_int(a) /= b; }
_b_int& operator++() {
val = val == MOD - 1 ? 0 : val + 1;
return *this;
}
_b_int& operator--() {
val = val == 0 ? MOD - 1 : val - 1;
return *this;
}
_b_int operator++(int) { _b_int before = *this; ++*this; return before; }
_b_int operator--(int) { _b_int before = *this; --*this; return before; }
_b_int operator-() const {
return val == 0 ? 0 : MOD - val;
}
friend bool operator==(const _b_int &a, const _b_int &b) { return a.val == b.val; }
friend bool operator!=(const _b_int &a, const _b_int &b) { return a.val != b.val; }
friend bool operator<(const _b_int &a, const _b_int &b) { return a.val < b.val; }
friend bool operator>(const _b_int &a, const _b_int &b) { return a.val > b.val; }
friend bool operator<=(const _b_int &a, const _b_int &b) { return a.val <= b.val; }
friend bool operator>=(const _b_int &a, const _b_int &b) { return a.val >= b.val; }
_b_int inv() const {
return inv_mod(val);
}
_b_int pow(int64_t p) const {
if (p < 0)
return inv().pow(-p);
_b_int a = *this, result = 1;
while (p > 0) {
if (p & 1)
result *= a;
p >>= 1;
if (p > 0)
a *= a;
}
return result;
}
friend ostream& operator<<(ostream &os, const _b_int &m) {
return os << m.val;
}
friend istream& operator>>(istream &is, _b_int &m) {
int64_t x;
is >> x;
m = x;
return is;
}
};
int MOD = 998244353;
barrett_reduction barrett(MOD);
using mnum = _b_int<MOD, barrett>;
void solve() {
int n, m;
cin >> n >> m;
vector<mnum> mpows(n+1);
mpows[0] = 1;
for(int i = 1; i <= n; i++) mpows[i] = mpows[i-1] * m;
vector<mnum> dp(n+1);
dp[1] = m;
for(int i = 2; i <= n; i++) {
dp[i] = dp[i-1] * m;
if(i%2==0) dp[i] -= dp[i/2];
}
mnum ret = 0;
for(int i = 1; 2*i < n; i++) ret += dp[i] * mpows[n-2*i];
cout << ret << "\n";
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
6 2
output:
40
result:
ok "40"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3017 7801
output:
515391664
result:
ok "515391664"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3 1
output:
1
result:
ok "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
4 7
output:
343
result:
ok "343"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
5 4
output:
304
result:
ok "304"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
8 8
output:
2355200
result:
ok "2355200"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
7 6
output:
54216
result:
ok "54216"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
1330 3031
output:
139921223
result:
ok "139921223"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4946 3837
output:
64102067
result:
ok "64102067"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
4236 3305
output:
78581604
result:
ok "78581604"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
399 3245
output:
714500544
result:
ok "714500544"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4881 2346
output:
28365995
result:
ok "28365995"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
4647 3069
output:
798067847
result:
ok "798067847"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
3414 4280
output:
669878613
result:
ok "669878613"
Test #15:
score: 0
Accepted
time: 13ms
memory: 10884kb
input:
1000000 1000000
output:
469217978
result:
ok "469217978"
Test #16:
score: 0
Accepted
time: 9ms
memory: 10944kb
input:
1000000 1
output:
1
result:
ok "1"
Test #17:
score: 0
Accepted
time: 3ms
memory: 6444kb
input:
418909 302156
output:
189551565
result:
ok "189551565"
Test #18:
score: 0
Accepted
time: 6ms
memory: 10884kb
input:
984572 895728
output:
567020798
result:
ok "567020798"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
50545 723857
output:
651400574
result:
ok "651400574"
Test #20:
score: 0
Accepted
time: 6ms
memory: 8256kb
input:
668791 286918
output:
27505324
result:
ok "27505324"
Test #21:
score: 0
Accepted
time: 8ms
memory: 10088kb
input:
898539 238506
output:
9072376
result:
ok "9072376"
Test #22:
score: 0
Accepted
time: 10ms
memory: 8644kb
input:
711024 686568
output:
221989803
result:
ok "221989803"
Test #23:
score: 0
Accepted
time: 9ms
memory: 10588kb
input:
970385 660016
output:
104842944
result:
ok "104842944"
Test #24:
score: 0
Accepted
time: 8ms
memory: 10352kb
input:
943632 224593
output:
631779281
result:
ok "631779281"
Test #25:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
26758 836991
output:
860673946
result:
ok "860673946"
Test #26:
score: 0
Accepted
time: 11ms
memory: 9696kb
input:
838661 823355
output:
34634389
result:
ok "34634389"
Test #27:
score: 0
Accepted
time: 12ms
memory: 10488kb
input:
923587 8580
output:
549615557
result:
ok "549615557"
Test #28:
score: 0
Accepted
time: 0ms
memory: 5184kb
input:
275456 449218
output:
745638801
result:
ok "745638801"
Test #29:
score: 0
Accepted
time: 2ms
memory: 3808kb
input:
96512 594328
output:
159367796
result:
ok "159367796"
Test #30:
score: 0
Accepted
time: 10ms
memory: 11016kb
input:
995445 996221
output:
785170205
result:
ok "785170205"
Test #31:
score: 0
Accepted
time: 11ms
memory: 9624kb
input:
821123 195922
output:
950462887
result:
ok "950462887"
Test #32:
score: 0
Accepted
time: 10ms
memory: 8744kb
input:
715365 748511
output:
571984302
result:
ok "571984302"
Test #33:
score: 0
Accepted
time: 8ms
memory: 9804kb
input:
867858 338674
output:
698272834
result:
ok "698272834"
Test #34:
score: 0
Accepted
time: 6ms
memory: 6176kb
input:
406213 206504
output:
201893603
result:
ok "201893603"
Test #35:
score: 0
Accepted
time: 10ms
memory: 8764kb
input:
729455 262034
output:
521537323
result:
ok "521537323"
Test #36:
score: 0
Accepted
time: 12ms
memory: 10484kb
input:
915061 381221
output:
361349035
result:
ok "361349035"
Test #37:
score: 0
Accepted
time: 6ms
memory: 6596kb
input:
426669 32501
output:
206011209
result:
ok "206011209"
Test #38:
score: 0
Accepted
time: 4ms
memory: 5116kb
input:
256786 708325
output:
287335753
result:
ok "287335753"
Extra Test:
score: 0
Extra Test Passed