QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#804841 | #5209. King's Puzzle | Raghayev17889 | WA | 0ms | 3684kb | C++17 | 2.0kb | 2024-12-08 06:46:54 | 2024-12-08 06:46:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void _()
{
int n, k;
cin >> n >> k;
if(k >= n)
{
cout << "NO\n";
return;
}
else
{
if(k == 1)
{
cout << "YES\n";
cout << n << endl;
for(int i = 0; i < n; i++)
{
cout << i+1 << " " << (i+1)% n +1<<endl;
}
return;
}
else
{
int deg = 1;
vector<int> a(n, 1);
vector<vector<int>> e(n);
int ans = 0;
deg++;
for(int i = 1; i < n; i++)
{
e[0].push_back(i);
ans++;
}
if(k == 2)
{
cout << "YES\n"<<n-1 << endl;
for(int i = 1; i < n; i++)
{
cout << 1 << " " << i+1 << endl;
}
return;
}
a[0] = n-1;
a[1] = 2;
a[2] = 2;
e[1].push_back(2);
ans++;
deg = 3;
int ind = 2;
int i = 1;
while(deg < k)
{
deg++;
i = 1;
while(a[ind] < a[ind-1])
{
a[ind]++;
a[ind+i]++;
e[ind].push_back(ind+i);
ans++;
i++;
}
}
cout << "YES\n" << ans << endl;
for(int i = 0; i < n; i++)
{
int p = e[i].size();
for(int j = 0; j < p; j++)
{
cout << i+1 << " " << e[i][j]+1 << endl;
}
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while(t--) _();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
5 2
output:
YES 4 1 2 1 3 1 4 1 5
result:
ok n = 5, k = 2: nice job dude
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 1
output:
YES 4 1 2 2 3 3 4 4 1
result:
ok n = 4, k = 1: nice job dude
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
11 1
output:
YES 11 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 1
result:
ok n = 11, k = 1: nice job dude
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
11 2
output:
YES 10 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11
result:
ok n = 11, k = 2: nice job dude
Test #5:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
11 3
output:
YES 11 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 2 3
result:
ok n = 11, k = 3: nice job dude
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3684kb
input:
11 9
output:
YES 11 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 2 3
result:
wrong answer There should be 9 distinct degrees, not 3