QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#851512#8228. 排序chy_is_a_fish100 ✓4967ms47200kbC++141.1kb2025-01-10 19:37:132025-01-10 19:37:15

Judging History

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

  • [2025-01-10 19:37:15]
  • 评测
  • 测评结果:100
  • 用时:4967ms
  • 内存:47200kb
  • [2025-01-10 19:37:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
int n, m, cnt, s, x, y, p, d[15];
unordered_map <int, pair <int, int>> f;
bitset <30> o, a;
void solve()
{
	o = a; cnt = s = 0; p = y;
	for (int i = 1; i <= m; i++)
    {
		for (int j = p; j < n; j += d[i]) s += !o[j];
		cnt += s; s = 0;
		for (int j = 0; j < d[i]; s = 0, j++)
        {
			for (int k = j; k < n; k += d[i]) s += !o[k];
			if (p % d[i] == j) p = s * d[i] + j;
			for (int k = j, l = 0; k < n; k += d[i], l++) o[k] = (s <= l);
		}
	}
	if (f[x].fi < f[x^1<<y].fi + cnt) f[x] = {f[x^1<<y].fi + cnt, 0};
	if (f[x].fi == f[x^1<<y].fi + cnt) f[x].se += f[x^1<<y].se;
}
void work(int S) {for (y = 0; y < n; y++) if (a[y] && !a[y+d[1]]) x = S, solve();}
void dfs(int p, int S) 
{
	if (p == n) return work(S); a[p] = 0; dfs(p + 1, S);
	if (p < d[1] || a[p-d[1]]) a[p] = 1, dfs(p + 1, S | 1 << p);
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> d[i];
	f[0] = {0, 1}; dfs(0, 0);
	cout << f[(1<<n)-1].fi << " " << f[(1<<n)-1].se;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 18
Accepted

Test #1:

score: 18
Accepted
time: 0ms
memory: 3804kb

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

score: 18
Accepted
time: 0ms
memory: 3584kb

input:

5 4
5 4 2 1

output:

6 4

result:

ok 2 number(s): "6 4"

Test #3:

score: 18
Accepted
time: 1ms
memory: 3584kb

input:

8 4
6 3 2 1

output:

15 4

result:

ok 2 number(s): "15 4"

Test #4:

score: 18
Accepted
time: 1ms
memory: 3588kb

input:

8 6
8 7 5 4 2 1

output:

14 2

result:

ok 2 number(s): "14 2"

Test #5:

score: 18
Accepted
time: 1ms
memory: 3584kb

input:

8 3
8 7 1

output:

22 7

result:

ok 2 number(s): "22 7"

Test #6:

score: 18
Accepted
time: 0ms
memory: 3652kb

input:

8 1
1

output:

28 1

result:

ok 2 number(s): "28 1"

Subtask #2:

score: 27
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 27
Accepted
time: 2ms
memory: 3668kb

input:

16 2
6 1

output:

77 15

result:

ok 2 number(s): "77 15"

Test #8:

score: 27
Accepted
time: 22ms
memory: 4040kb

input:

16 8
10 9 8 7 6 5 4 1

output:

57 5

result:

ok 2 number(s): "57 5"

Test #9:

score: 27
Accepted
time: 22ms
memory: 3972kb

input:

16 10
10 9 8 7 6 5 4 3 2 1

output:

57 3

result:

ok 2 number(s): "57 3"

Test #10:

score: 27
Accepted
time: 19ms
memory: 3976kb

input:

16 7
10 9 8 6 5 4 1

output:

49 1

result:

ok 2 number(s): "49 1"

Test #11:

score: 27
Accepted
time: 4ms
memory: 3736kb

input:

16 4
7 6 2 1

output:

52 9

result:

ok 2 number(s): "52 9"

Subtask #3:

score: 21
Accepted

Dependency #2:

100%
Accepted

Test #12:

score: 21
Accepted
time: 4ms
memory: 3756kb

input:

22 3
5 3 1

output:

100 1

result:

ok 2 number(s): "100 1"

Test #13:

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

input:

22 1
1

output:

231 1

result:

ok 2 number(s): "231 1"

Test #14:

score: 21
Accepted
time: 160ms
memory: 7924kb

input:

22 4
10 8 3 1

output:

97 4

result:

ok 2 number(s): "97 4"

Test #15:

score: 21
Accepted
time: 185ms
memory: 7920kb

input:

22 5
10 7 6 3 1

output:

92 70

result:

ok 2 number(s): "92 70"

Test #16:

score: 21
Accepted
time: 220ms
memory: 7864kb

input:

22 6
10 9 8 7 3 1

output:

97 1

result:

ok 2 number(s): "97 1"

Test #17:

score: 21
Accepted
time: 334ms
memory: 7864kb

input:

22 10
10 9 8 7 6 5 4 3 2 1

output:

109 1

result:

ok 2 number(s): "109 1"

Subtask #4:

score: 10
Accepted

Test #18:

score: 10
Accepted
time: 3ms
memory: 3752kb

input:

14 2
10 1

output:

61 210

result:

ok 2 number(s): "61 210"

Test #19:

score: 10
Accepted
time: 0ms
memory: 3588kb

input:

18 2
2 1

output:

117 1

result:

ok 2 number(s): "117 1"

Test #20:

score: 10
Accepted
time: 635ms
memory: 24880kb

input:

30 2
9 1

output:

264 84

result:

ok 2 number(s): "264 84"

Test #21:

score: 10
Accepted
time: 482ms
memory: 22500kb

input:

29 2
9 1

output:

253 36

result:

ok 2 number(s): "253 36"

Test #22:

score: 10
Accepted
time: 76ms
memory: 6448kb

input:

25 2
8 1

output:

195 8

result:

ok 2 number(s): "195 8"

Subtask #5:

score: 24
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Test #23:

score: 24
Accepted
time: 2395ms
memory: 47112kb

input:

30 4
10 9 5 1

output:

188 40

result:

ok 2 number(s): "188 40"

Test #24:

score: 24
Accepted
time: 4591ms
memory: 47192kb

input:

30 9
10 9 8 7 6 5 4 3 1

output:

184 6

result:

ok 2 number(s): "184 6"

Test #25:

score: 24
Accepted
time: 4179ms
memory: 47152kb

input:

30 8
10 9 8 7 4 3 2 1

output:

154 1

result:

ok 2 number(s): "154 1"

Test #26:

score: 24
Accepted
time: 4124ms
memory: 47200kb

input:

30 8
10 8 7 6 5 4 3 1

output:

155 1

result:

ok 2 number(s): "155 1"

Test #27:

score: 24
Accepted
time: 3297ms
memory: 47196kb

input:

30 6
10 8 6 4 3 1

output:

150 4

result:

ok 2 number(s): "150 4"

Test #28:

score: 24
Accepted
time: 4967ms
memory: 47200kb

input:

30 10
10 9 8 7 6 5 4 3 2 1

output:

184 6

result:

ok 2 number(s): "184 6"

Test #29:

score: 24
Accepted
time: 2416ms
memory: 42376kb

input:

29 6
10 9 7 5 3 1

output:

129 200

result:

ok 2 number(s): "129 200"

Extra Test:

score: 0
Extra Test Passed