QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#333030#7881. Computational Complexitysinsop90WA 24ms7804kbC++141.5kb2024-02-19 16:53:122024-02-19 16:53:14

Judging History

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

  • [2024-02-19 16:53:14]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:7804kb
  • [2024-02-19 16:53:12]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e7 + 5;
map<int, int> mp, bac;
int f[maxn], g[maxn], T, M;
vector<int> vec;
void dfs(int now) {
	if(now > M) return;
	if(mp[now]) return;
	mp[now] = 1;
	if(now > 13) vec.push_back(now);
	dfs(now * 2), dfs(now * 3), dfs(now * 5), dfs(now * 7);
}
void init() {
	for(int i = 1;i <= 13;i++) {
		f[i] = max(i, g[i / 2] + g[i / 3] + g[i / 5] + g[i / 7]);
		g[i] = max(i, f[i / 2] + f[i / 3] + f[i / 4] + f[i / 5]);
	}
	for(int i = 13;i >= 1;i--) f[i] -= f[i - 1], g[i] -= g[i - 1];
	for(int i = 0;i <= 13;i++) vec.push_back(i);
	dfs(1);
	sort(vec.begin(), vec.end());
	for(int i = 0;i < vec.size();i++) bac[vec[i]] = i;
	for(int i = 0;i < vec.size();i++) {
		int X = vec[i];
		if(mp[X * 2] && X * 2 > 13) f[bac[X * 2]] += g[i], g[bac[X * 2]] += f[i];
		if(mp[X * 3] && X * 3 > 13) f[bac[X * 3]] += g[i], g[bac[X * 3]] += f[i];
		if(mp[X * 5] && X * 5 > 13) f[bac[X * 5]] += g[i], g[bac[X * 5]] += f[i];
		if(mp[X * 4] && X * 4 > 13) g[bac[X * 4]] += f[i];
		if(mp[X * 7] && X * 7 > 13) f[bac[X * 7]] += g[i];	
	}
	for(int i = 1;i < vec.size();i++) (f[i] += f[i - 1]) %= M, (g[i] += g[i - 1]) %= M;
}
void solve() {
	int n;
	cin >> n;
	int P = upper_bound(vec.begin(), vec.end(), n) - vec.begin() - 1;
	cout << f[P] % M << " " << g[P] % M << '\n';
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> f[0] >> g[0] >> T >> M;
	init();
	while(T --) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 7276kb

input:

1958 920 10 100000000000
0
1
2
3
10
100
200
1000
19580920
20232023

output:

1958 920
3680 7832
10592 9554
17504 11276
50294 64826
784112 893714
1894550 1905470
12057866 12979424
71481494756 48626708512
28127864908 7251681354

result:

ok 20 numbers

Test #2:

score: 0
Accepted
time: 15ms
memory: 7316kb

input:

0 0 10 100000000000
0
1
2
3
4
10
20
30
40
100

output:

0 0
1 1
2 2
3 3
4 4
11 12
25 26
41 41
55 58
162 172

result:

ok 20 numbers

Test #3:

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

input:

2023 2023 10 2023
0
1
2
3
4
5
6
7
8
9

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

result:

ok 20 numbers

Test #4:

score: -100
Wrong Answer
time: 24ms
memory: 7804kb

input:

36092 30559 2149 729566623185
909730017626
961811467628
978809456383
494310140318
760462959632
726343527430
220697276132
366336227300
456813204361
569783542145
13854148170
51526515764
564416233246
876430686824
862897449267
956440673661
512777546436
728860125927
799238602356
978766770799
47962348351
...

output:

282301231682 706101956054
282301231682 706101956054
282301231682 706101956054
138070013247 301112114677
282301231682 706101956054
630454127249 196841848259
546918129568 526274849982
226761501362 157889210040
135623074930 620463814922
78467045157 602244472172
51639549042 411354142414
329188915935 306...

result:

wrong answer 1st numbers differ - expected: '192287632545', found: '282301231682'