QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#477435#9116. DRD Stringucup-team3695#WA 8ms5752kbC++20967b2024-07-14 03:22:042024-07-14 03:22:05

Judging History

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

  • [2024-07-14 03:22:05]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:5752kb
  • [2024-07-14 03:22:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair

const ll mod = 998244353;

#define MAXN 1'000'010

ll a[MAXN];
ll mpow[MAXN];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	ll n, m;
	cin >> n >> m;
	mpow[0] = 1;
	rep(i, 1, n+1) mpow[i] = (mpow[i-1]*m)%mod;

	a[1] = m;
	//a[2] = m;
	ll sm = 0;
	rep(i, 2, n+1) {
		// number of ways to build previously
		if (i % 2 ==  0) {
			sm += a[i/2];
		}
		rep(j, 1, i+1) {
			if (2*j > i) break;
			if (i == n && 2*j == i) break;

			a[i] += a[j]*mpow[i-2*j];
			a[i] %= mod;
		}

		if (i != n) {
			a[i] = mpow[i]-a[i];
		}
		sm *= m;
		//sm += 
		//cout << i << ' ' << a[i] << endl;
	}
	cout << a[n] << endl;
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5696kb

input:

6 2

output:

40

result:

ok "40"

Test #2:

score: 0
Accepted
time: 8ms
memory: 5688kb

input:

3017 7801

output:

515391664

result:

ok "515391664"

Test #3:

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

input:

3 1

output:

1

result:

ok "1"

Test #4:

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

input:

4 7

output:

343

result:

ok "343"

Test #5:

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

input:

5 4

output:

304

result:

ok "304"

Test #6:

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

input:

8 8

output:

2355200

result:

ok "2355200"

Test #7:

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

input:

7 6

output:

54216

result:

ok "54216"

Test #8:

score: -100
Wrong Answer
time: 2ms
memory: 5708kb

input:

1330 3031

output:

-858323130

result:

wrong answer 1st words differ - expected: '139921223', found: '-858323130'