QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#162732#5209. King's Puzzlekaruna#WA 1ms3872kbC++17945b2023-09-03 16:09:062023-09-03 16:09:07

Judging History

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

  • [2023-09-03 16:09:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3872kb
  • [2023-09-03 16:09:06]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	
	int n, k; cin >> n >> k;
	if(k == 1)
	{
		if(n == 1) return !(cout << "YES\n0");
		else if(n == 2) return !(cout << "YES\n1\n1 2");
		else return !(cout << "NO");
	}

	if(n < k + 1) return !(cout << "NO");

	int ord[k + 1];
	int t = (k + 1) / 2;
	for(int i = 0; i < t; ++i) ord[i] = i + 1;
	for(int i = t; i <= k; ++i) ord[i] = i;

	vector<pii> V;
	for(int i = k; i >= 0; --i)
	{
		for(int j = 1; j <= ord[i]; ++j)
		{
			V.push_back({i, i - j});
			--ord[i - j];
		}
		ord[i] = 0;
	}

	int pr = 0;
	for(int i = k + 1; i < n; ++i)
	{
		V.push_back({pr, i});
		pr = i;
	}

	cout << "YES\n";
	cout << V.size() << '\n';
	for(auto [x, y] : V) cout << x + 1 << ' ' << y + 1 << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2

output:

YES
4
3 2
3 1
1 4
4 5

result:

ok n = 5, k = 2: nice job dude

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3872kb

input:

4 1

output:

NO

result:

wrong answer n = 4, k = 1: jury found answer, participant didn't