QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#477407#9116. DRD Stringucup-team3099#AC ✓43ms7128kbC++205.5kb2024-07-14 03:02:382024-07-14 03:02:38

Judging History

你现在查看的是最新测评结果

  • [2024-07-14 03:02:38]
  • 评测
  • 测评结果:AC
  • 用时:43ms
  • 内存:7128kb
  • [2024-07-14 03:02:38]
  • 提交

answer

#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

#if 0
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
 
    template<class T>
    using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag,
        __gnu_pbds::tree_order_statistics_node_update>;
#endif

#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <queue>
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <ctime> 
#include <cstring>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)

#define each(a,x) for (auto& a: x)
#define tcT template<class T
#define tcTU tcT, class U
#define tcTUU tcT, class ...U
template<class T> using V = vector<T>; 
template<class T, size_t SZ> using AR = array<T,SZ>;

typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
 
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
 
mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
 
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.first)+", "+ts(p.second)+")"; }
 
template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }
 
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }

tcTU> void re(pair<T,U>& p);
tcT> void re(V<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(double& d) { str t; re(t); d = stod(t); }
void re(long double& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcTU> void re(pair<T,U>& p) { re(p.first,p.second); }
tcT> void re(V<T>& x) { each(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { each(a,x) re(a); }
tcT> void rv(int n, V<T>& x) { x.rsz(n); re(x); }

constexpr bool multitest() {return 0;}
void solve();
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int t = 1;
	if (multitest()) cin >> t;
	for (; t; t--) solve();
}




















template<int MOD> struct mint {
	static const int mod = MOD;
	int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
	mint():v(0) {}
	mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
		if (v < 0) v += MOD; }
	bool operator==(const mint& o) const {
		return v == o.v; }
	friend bool operator!=(const mint& a, const mint& b) { 
		return !(a == b); }
	friend bool operator<(const mint& a, const mint& b) { 
		return a.v < b.v; }
	friend str ts(mint a) { return ts(a.v); }
   
	mint& operator+=(const mint& o) { 
		if ((v += o.v) >= MOD) v -= MOD; 
		return *this; }
	mint& operator-=(const mint& o) { 
		if ((v -= o.v) < 0) v += MOD; 
		return *this; }
	mint& operator*=(const mint& o) { 
		v = int((ll)v*o.v%MOD); return *this; }
	mint& operator/=(const mint& o) { return (*this) *= inv(o); }
	friend mint pow(mint a, ll p) {
		mint ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans; }
	friend mint inv(const mint& a) { assert(a.v != 0); 
		return pow(a,MOD-2); }
		
	mint operator-() const { return mint(-v); }
	mint& operator++() { return *this += 1; }
	mint& operator--() { return *this -= 1; }
	friend mint operator+(mint a, const mint& b) { return a += b; }
	friend mint operator-(mint a, const mint& b) { return a -= b; }
	friend mint operator*(mint a, const mint& b) { return a *= b; }
	friend mint operator/(mint a, const mint& b) { return a /= b; }
};

using mi = mint<998244353>;



void solve() {
	int n, m; re(n,m);

	vector<mi> dp(n+1);

	dp[1] = 0;
	mi sdp = 0;
	mi pm = 0;

	for (int i = 2; i <= n; i++) {
		sdp *= m;
		pm *= m;
		if (i % 2 == 0) {
			sdp += dp[i/2];
			pm += pow(mi(m), i/2);
		}
		dp[i] = pm - sdp;
	}

	if (n % 2 == 0) dp[n] -= pow(mi(m), n/2) - dp[n/2];
	ps(dp[n]);
}


















































	







这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

input:

6 2

output:

40

result:

ok "40"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3017 7801

output:

515391664

result:

ok "515391664"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

3 1

output:

1

result:

ok "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

4 7

output:

343

result:

ok "343"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

5 4

output:

304

result:

ok "304"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

8 8

output:

2355200

result:

ok "2355200"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

7 6

output:

54216

result:

ok "54216"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

1330 3031

output:

139921223

result:

ok "139921223"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4946 3837

output:

64102067

result:

ok "64102067"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4236 3305

output:

78581604

result:

ok "78581604"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

399 3245

output:

714500544

result:

ok "714500544"

Test #12:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

4881 2346

output:

28365995

result:

ok "28365995"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

4647 3069

output:

798067847

result:

ok "798067847"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

3414 4280

output:

669878613

result:

ok "669878613"

Test #15:

score: 0
Accepted
time: 43ms
memory: 7128kb

input:

1000000 1000000

output:

469217978

result:

ok "469217978"

Test #16:

score: 0
Accepted
time: 43ms
memory: 7052kb

input:

1000000 1

output:

1

result:

ok "1"

Test #17:

score: 0
Accepted
time: 17ms
memory: 4816kb

input:

418909 302156

output:

189551565

result:

ok "189551565"

Test #18:

score: 0
Accepted
time: 43ms
memory: 6996kb

input:

984572 895728

output:

567020798

result:

ok "567020798"

Test #19:

score: 0
Accepted
time: 2ms
memory: 3628kb

input:

50545 723857

output:

651400574

result:

ok "651400574"

Test #20:

score: 0
Accepted
time: 28ms
memory: 5732kb

input:

668791 286918

output:

27505324

result:

ok "27505324"

Test #21:

score: 0
Accepted
time: 38ms
memory: 6704kb

input:

898539 238506

output:

9072376

result:

ok "9072376"

Test #22:

score: 0
Accepted
time: 27ms
memory: 6136kb

input:

711024 686568

output:

221989803

result:

ok "221989803"

Test #23:

score: 0
Accepted
time: 41ms
memory: 7100kb

input:

970385 660016

output:

104842944

result:

ok "104842944"

Test #24:

score: 0
Accepted
time: 36ms
memory: 6796kb

input:

943632 224593

output:

631779281

result:

ok "631779281"

Test #25:

score: 0
Accepted
time: 1ms
memory: 3708kb

input:

26758 836991

output:

860673946

result:

ok "860673946"

Test #26:

score: 0
Accepted
time: 32ms
memory: 6520kb

input:

838661 823355

output:

34634389

result:

ok "34634389"

Test #27:

score: 0
Accepted
time: 39ms
memory: 6784kb

input:

923587 8580

output:

549615557

result:

ok "549615557"

Test #28:

score: 0
Accepted
time: 11ms
memory: 4164kb

input:

275456 449218

output:

745638801

result:

ok "745638801"

Test #29:

score: 0
Accepted
time: 4ms
memory: 3692kb

input:

96512 594328

output:

159367796

result:

ok "159367796"

Test #30:

score: 0
Accepted
time: 39ms
memory: 7012kb

input:

995445 996221

output:

785170205

result:

ok "785170205"

Test #31:

score: 0
Accepted
time: 31ms
memory: 6520kb

input:

821123 195922

output:

950462887

result:

ok "950462887"

Test #32:

score: 0
Accepted
time: 30ms
memory: 5956kb

input:

715365 748511

output:

571984302

result:

ok "571984302"

Test #33:

score: 0
Accepted
time: 37ms
memory: 6592kb

input:

867858 338674

output:

698272834

result:

ok "698272834"

Test #34:

score: 0
Accepted
time: 17ms
memory: 4688kb

input:

406213 206504

output:

201893603

result:

ok "201893603"

Test #35:

score: 0
Accepted
time: 31ms
memory: 6008kb

input:

729455 262034

output:

521537323

result:

ok "521537323"

Test #36:

score: 0
Accepted
time: 39ms
memory: 6728kb

input:

915061 381221

output:

361349035

result:

ok "361349035"

Test #37:

score: 0
Accepted
time: 14ms
memory: 5012kb

input:

426669 32501

output:

206011209

result:

ok "206011209"

Test #38:

score: 0
Accepted
time: 7ms
memory: 4292kb

input:

256786 708325

output:

287335753

result:

ok "287335753"

Extra Test:

score: 0
Extra Test Passed