QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#311355#5529. Most Annoying Constructive Problemushg8877Compile Error//C++143.4kb2024-01-22 11:13:162024-01-22 11:13:17

Judging History

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

  • [2024-01-22 11:13:17]
  • 评测
  • [2024-01-22 11:13:16]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

int f(int n) {
	return n * (n - 1) / 2 - (n - 1) / 2;
}

std::vector<int> construct(int n, int k) {
	std::vector<int> p(n);
	std::iota(p.begin(), p.end(), 0);
	if (n <= 5) {
		do {
			std::vector a(n, std::vector<int>(n));
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					if (p[i] > p[j]) {
						a[i][j] = 1;
					}
				}
			}
			for (int i = n - 1; i >= 0; i--) {
				for (int j = i + 1; j < n; j++) {
					a[i][j] += a[i + 1][j];
				}
			}
			for (int i = n - 1; i >= 0; i--) {
				for (int j = i + 1; j < n; j++) {
					a[i][j] += a[i][j - 1];
				}
			}
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				for (int j = i; j < n; j++) {
					cnt += (a[i][j] % 2);
				}
			}
			if (cnt == k) {
				return p;
			}
		} while (std::next_permutation(p.begin(), p.end()));
		return {};
	}
	if (k > f(n)) {
		return {};
	}
	if (k == 0) {
		return p;
	}
	if (k <= n - 2) {
		p[k - 1] = k + 1;
		p[k] = k - 1;
		p[k + 1] = k;
		return p;
	}
	if (k <= f(n - 2) + n - 1) {
		auto q = construct(n - 2, k - (n - 1));
		q.push_back(n - 1);
		q.push_back(n - 2);
		return q;
	}
	if (k == f(n)) {
		for (int i = 0; i < n; i += 2) {
			p[i] = i + 3;
		}
		for (int i = 1; i < n; i += 2) {
			p[i] = i - 1;
		}
		std::vector<int> q(n);
		std::iota(q.begin(), q.end(), 0);
		std::sort(q.begin(), q.end(), [&](int i, int j) {
			return p[i] < p[j];
		});
		
		for (int i = 0; i < n; i++) {
			p[q[i]] = i;
		}
		return p;
	}
	
	p = construct(n - 2, f(n - 2));
	
	std::vector a(n - 2, std::vector<int>(n - 2));
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 2; j++) {
			if (p[i] > p[j]) {
				a[i][j] = 1;
			}
		}
	}
	for (int i = n - 2 - 1; i >= 0; i--) {
		for (int j = i + 1; j < n - 2; j++) {
			a[i][j] += a[i + 1][j];
		}
	}
	for (int i = n - 2 - 1; i >= 0; i--) {
		for (int j = i + 1; j < n - 2; j++) {
			a[i][j] += a[i][j - 1];
		}
	}
	for (int i = 0; i < n - 2; i++) {
		p[i] = p[i] * 3 + 2;
	}
	
	int N = 3 * n;
	std::vector<int> fl(N), pl(N), fr(N), pr(N);
	for (int x = 0; x < N; x++) {
		int v = 0, s = 0;
		for (int i = 0; i < n - 2; i++) {
			v += (x > p[i]);
			s += (v + a[0][i]) % 2;
		}
		fl[x] = s;
		pl[x] = v;
	}
	for (int x = 0; x < N; x++) {
		int v = 0, s = 0;
		for (int i = n - 2 - 1; i >= 0; i--) {
			v += (x < p[i]);
			s += (v + a[i][n - 2 - 1]) % 2;
		}
		fr[x] = s;
		pr[x] = v;
	}
	
	for (int x = 0; x < N; x++) {
		for (int y = 0; y < N; y++) {
			if (x % 3 == 2 || y % 3 == 2 || x == y) {
				continue;
			}
			int cnt = f(n - 2) + fl[x] + fr[y] + (a[0][n - 2 - 1] + pl[x] + pr[y] + (x > y)) % 2;
			if (cnt == k) {
				p.insert(p.begin(), x);
				p.push_back(y);
				std::vector<int> q(n);
				std::iota(q.begin(), q.end(), 0);
				std::sort(q.begin(), q.end(), [&](int i, int j) {
					return p[i] < p[j];
				});
				
				for (int i = 0; i < n; i++) {
					p[q[i]] = i;
				}
				return p;
			}
		}
	}
	
	return {};
}

void solve() {
	int n, k;
	std::cin >> n >> k;
	
	auto p = construct(n, k);
	if (p.empty()) {
		std::cout << "NO\n";
	} else {
		std::cout << "YES\n";
		for (int i = 0; i < n; i++) {
			std::cout << p[i] + 1 << " \n"[i == n - 1];
		}
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	int t;
	std::cin >> t;
	
	while (t--) {
		solve();
	}
	
	return 0;
}

詳細信息

answer.code: In function ‘std::vector<int> construct(int, int)’:
answer.code:14:37: error: missing template arguments before ‘a’
   14 |                         std::vector a(n, std::vector<int>(n));
      |                                     ^
answer.code:18:49: error: ‘a’ was not declared in this scope
   18 |                                                 a[i][j] = 1;
      |                                                 ^
answer.code:24:41: error: ‘a’ was not declared in this scope
   24 |                                         a[i][j] += a[i + 1][j];
      |                                         ^
answer.code:29:41: error: ‘a’ was not declared in this scope
   29 |                                         a[i][j] += a[i][j - 1];
      |                                         ^
answer.code:35:49: error: ‘a’ was not declared in this scope
   35 |                                         cnt += (a[i][j] % 2);
      |                                                 ^
answer.code:83:21: error: missing template arguments before ‘a’
   83 |         std::vector a(n - 2, std::vector<int>(n - 2));
      |                     ^
answer.code:87:33: error: ‘a’ was not declared in this scope
   87 |                                 a[i][j] = 1;
      |                                 ^
answer.code:93:25: error: ‘a’ was not declared in this scope
   93 |                         a[i][j] += a[i + 1][j];
      |                         ^
answer.code:98:25: error: ‘a’ was not declared in this scope
   98 |                         a[i][j] += a[i][j - 1];
      |                         ^
answer.code:111:35: error: ‘a’ was not declared in this scope
  111 |                         s += (v + a[0][i]) % 2;
      |                                   ^
answer.code:120:35: error: ‘a’ was not declared in this scope
  120 |                         s += (v + a[i][n - 2 - 1]) % 2;
      |                                   ^
answer.code:131:63: error: ‘a’ was not declared in this scope
  131 |                         int cnt = f(n - 2) + fl[x] + fr[y] + (a[0][n - 2 - 1] + pl[x] + pr[y] + (x > y)) % 2;
      |                                                               ^