QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#162732 | #5209. King's Puzzle | karuna# | WA | 1ms | 3872kb | C++17 | 945b | 2023-09-03 16:09:06 | 2023-09-03 16:09:07 |
Judging History
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';
}
详细
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