QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#523749#6771. K-skip Permutationzzz111WA 0ms3700kbC++201.2kb2024-08-18 17:25:352024-08-18 17:25:35

Judging History

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

  • [2024-08-18 17:25:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3700kb
  • [2024-08-18 17:25:35]
  • 提交

answer

#include <bits/stdc++.h>
//#define int long long
#define endl '\n'
#define fr(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define br(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
using namespace std;
const int N = 1e6 + 10 ;
int a[N];
int ans[N];
int cnt;
inline void solve()
{
    int n, k;
    cin >> n >> k;
    if (k == 1)
    {
        for (int i = 1; i <= n - 1; i++)
            cout << i << " ";
        cout << n;
        return;
    }
    fr(i, 1, n)
    {
        if(cnt >= n)
            break;
        if (a[i])
            continue;
        ans[++cnt] = i;
        a[i] = 1;
        int tem = i;
        while (tem + k <= n)
        {
            if(a[tem + k])
            {
                tem += k;
                continue;
            }
            ans[++cnt] = tem + k;
            tem += k;
            a[tem + k] = 1;
        }
    }
    for (int i = 1; i <= n - 1; i++)
    {
        cout << ans[i] << ' ';
    }
    cout << ans[n];
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //   cin >> T;
    while (T--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 1

output:

1 2 3

result:

ok ok

Test #2:

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

input:

7 3

output:

1 4 2 5 3 6 4

result:

wrong answer not perm