QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645307#8285. Shell SortOIer_kzc#WA 0ms1644kbC++201.9kb2024-10-16 17:39:112024-10-16 17:39:13

Judging History

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

  • [2024-10-16 17:39:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1644kb
  • [2024-10-16 17:39:11]
  • 提交

answer

#include <stdio.h>
#include <string.h>
#include <assert.h>

#include <cmath>
#include <vector>

#define LOG(FMT...) fprintf(stderr, FMT)

#define eb emplace_back

using namespace std;

typedef long long LL;
constexpr int N = 16, NS = 2097152, mod = 1e9 + 7;

int n, m, d[N], pr[N], c[N];

void Add(int &x, int y) {
	if ((x += y) >= mod) {
		x -= mod;
	}
}

struct Pair {
	int x, y;
	void operator += (const Pair &t) {
		if (x < t.x) {
			x = t.x, y = t.y;
		} else if (x == t.x) {
			Add(y, t.y);
		}
	}
} f[NS];

int sz;
int ns;
int xs[N], szx;

int cost(int k) {
	static char v[32];
	for (int i = 0; i < sz; ++i) {
		for (int j = 0; j < xs[i]; ++j) {
			v[j * sz + i] = -1;
		}
		for (int j = xs[i]; j < c[i]; ++j) {
			v[j * sz + i] = 1;
		}
	}
	/* for (int i = 0; i < n; ++i) {
		LOG("%d ", v[i]);
	}
	LOG("\n"); */
	v[xs[k] * sz + k] = 0;
	int ret = 0;
	for (int i = 1; i < m; ++i) {
		int D = d[i];
		for (int r = 0; r < D; ++r) {
			for (int x = r; x < n; x += D) {
				for (int y = x; y >= D && v[y] < v[y - D]; --y) {
					ret += (v[y] == 0);
					swap(v[y], v[y - D]);
				}
			}
		}
	}
	return ret;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		scanf("%d", d + i);
	}
	sz = d[0];
	int extra = 0;
	pr[0] = 1;
	for (int i = 0; i < sz; ++i) {
		c[i] = n / sz + (i < n % sz);
		extra += c[i] * (c[i] - 1) / 2;
		pr[i + 1] = pr[i] * (1 + c[i]);
	}
	ns = pr[sz];
	for (int i = 1; i < ns; ++i) {
		f[i].x = -1, f[i].y = 0;
	}
	f[0] = (Pair){0, 1};
	for (int i = 0; i < ns; ++i) {
		if (f[i].x < 0) {
			continue;
		}
		for (int j = 0; j < sz; ++j) {
			xs[j] = i % pr[j + 1] / pr[j];
		}
		for (int j = 0; j < sz; ++j) {
			int x = xs[j];
			if (x == c[j]) {
				continue;
			}
			Pair t = f[i];
			t.x += cost(j);
			f[i + pr[j]] += t;
		}
	}
	int res1 = extra + f[ns - 1].x;
	int res2 = f[ns - 1].y;
	printf("%d %d\n", res1, res2);
	return 0;
}


詳細信息

Test #1:

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

input:

2 2
2 1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #2:

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

input:

5 4
5 4 2 1

output:

6 4

result:

ok 2 number(s): "6 4"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 1616kb

input:

8 4
6 3 2 1

output:

16 4

result:

wrong answer 1st numbers differ - expected: '15', found: '16'