Submission #33270633


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
template<typename A> inline void rd(A &a) {
  cin >> a;
}
template<typename A, typename ...B> inline void rd(A &a, B &...b) {
  cin >> a;
  rd(b...);
}
template<typename A> inline void O(const A &a) {
  cout << a << '\n';
}
template<typename A, typename ...B> inline void O(const A &a, const B &...b) {
  cout << a << ' ';
  O(b...);
}
template<typename T> inline void ckmin(T &x, const T &a) {
  x = min(x, a);
}
template<typename T> inline void ckmax(T &x, const T &a) {
  x = max(x, a);
}
#ifdef MISAKA
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...)
#endif
#define FOR(i,j,k) for (int i = (j); i <= (k); ++i)
#define ROF(i,j,k) for (int i = (k); i >= (j); --i)
typedef unsigned u32;
typedef long long i64;
typedef unsigned long long u64;
typedef pair<int ,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define IOFILE "filename"
// #define MULTI
const int N = 3e5+5;
int p[N];
int vis[N];

inline void sol() {
  int n, k;
  rd(n, k);
  if (2*k>n) {
    O(-1);
    return;
  }
  int i = 0;
  for (; n - i >= 4 * k; i += 2*k) {
    FOR(j,k,2*k-1) cout << i+j+1 <<' ';
    FOR(j,0,k-1) cout << i + j + 1 << ' ';
  }
  if (n-i < 3 * k) {
  FOR(j,i+k,n-1) cout << j+1 << ' ';
  FOR(j,i,i+k-1) cout << j+1 << ' ';
  } else {
    FOR(j,i,i+k-1) p[j] = j + k, vis[j+k]=1;
    FOR(j,n-2*k,n-k-1) p[j] = j + k, vis[j+k]=1;
    int r = i;
    FOR(j,i,n-1) {
      if (!p[j]) {
        while (vis[r]) ++r;
        p[j] = r++;
      }
    }
    FOR(j,i,n-1) cout << p[j]+1 << ' ';
  }
  cout << '\n';
}

int main() {
#ifndef MISAKA
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef IOFILE
  freopen(IOFILE ".in", "r", stdin);
  freopen(IOFILE ".out", "w", stdout);
#endif
#endif
#ifdef MULTI
  int T;
  rd(T);
  while (T--)
#endif
  sol();
  return 0;
}

Submission Info

Submission Time
Task C - K Derangement
User misaka18931
Language C++ (GCC 9.2.1)
Score 600
Code Size 1941 Byte
Status AC
Exec Time 28 ms
Memory 4596 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 97
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 02_small_11.txt, 02_small_12.txt, 02_small_13.txt, 02_small_14.txt, 02_small_15.txt, 02_small_16.txt, 02_small_17.txt, 02_small_18.txt, 02_small_19.txt, 02_small_20.txt, 02_small_21.txt, 02_small_22.txt, 02_small_23.txt, 02_small_24.txt, 02_small_25.txt, 02_small_26.txt, 02_small_27.txt, 02_small_28.txt, 02_small_29.txt, 02_small_30.txt, 02_small_31.txt, 02_small_32.txt, 02_small_33.txt, 02_small_34.txt, 02_small_35.txt, 02_small_36.txt, 02_small_37.txt, 02_small_38.txt, 02_small_39.txt, 02_small_40.txt, 02_small_41.txt, 02_small_42.txt, 02_small_43.txt, 02_small_44.txt, 02_small_45.txt, 02_small_46.txt, 02_small_47.txt, 02_small_48.txt, 02_small_49.txt, 02_small_50.txt, 02_small_51.txt, 02_small_52.txt, 02_small_53.txt, 02_small_54.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 03_rand_11.txt, 03_rand_12.txt, 03_rand_13.txt, 03_rand_14.txt, 03_rand_15.txt, 03_rand_16.txt, 03_rand_17.txt, 03_rand_18.txt, 03_rand_19.txt, 03_rand_20.txt, 03_rand_21.txt, 03_rand_22.txt, 03_rand_23.txt, 03_rand_24.txt, 03_rand_25.txt, 03_rand_26.txt, 03_rand_27.txt, 03_rand_28.txt, 03_rand_29.txt, 03_rand_30.txt, 03_rand_31.txt, 03_rand_32.txt, 03_rand_33.txt, 03_rand_34.txt, 03_rand_35.txt, 03_rand_36.txt, 03_rand_37.txt, 03_rand_38.txt, 03_rand_39.txt, 03_rand_40.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 7 ms 3420 KiB
01_sample_02.txt AC 2 ms 3452 KiB
01_sample_03.txt AC 2 ms 3456 KiB
02_small_01.txt AC 2 ms 3488 KiB
02_small_02.txt AC 2 ms 3464 KiB
02_small_03.txt AC 2 ms 3504 KiB
02_small_04.txt AC 2 ms 3452 KiB
02_small_05.txt AC 2 ms 3492 KiB
02_small_06.txt AC 2 ms 3448 KiB
02_small_07.txt AC 2 ms 3480 KiB
02_small_08.txt AC 2 ms 3460 KiB
02_small_09.txt AC 5 ms 3516 KiB
02_small_10.txt AC 1 ms 3500 KiB
02_small_11.txt AC 2 ms 3392 KiB
02_small_12.txt AC 2 ms 3452 KiB
02_small_13.txt AC 2 ms 3496 KiB
02_small_14.txt AC 2 ms 3512 KiB
02_small_15.txt AC 3 ms 3448 KiB
02_small_16.txt AC 2 ms 3496 KiB
02_small_17.txt AC 2 ms 3496 KiB
02_small_18.txt AC 2 ms 3456 KiB
02_small_19.txt AC 2 ms 3568 KiB
02_small_20.txt AC 2 ms 3476 KiB
02_small_21.txt AC 2 ms 3464 KiB
02_small_22.txt AC 2 ms 3512 KiB
02_small_23.txt AC 2 ms 3464 KiB
02_small_24.txt AC 2 ms 3412 KiB
02_small_25.txt AC 2 ms 3440 KiB
02_small_26.txt AC 2 ms 3504 KiB
02_small_27.txt AC 2 ms 3516 KiB
02_small_28.txt AC 2 ms 3416 KiB
02_small_29.txt AC 2 ms 3420 KiB
02_small_30.txt AC 2 ms 3440 KiB
02_small_31.txt AC 2 ms 3436 KiB
02_small_32.txt AC 2 ms 3508 KiB
02_small_33.txt AC 2 ms 3572 KiB
02_small_34.txt AC 1 ms 3448 KiB
02_small_35.txt AC 2 ms 3512 KiB
02_small_36.txt AC 2 ms 3460 KiB
02_small_37.txt AC 2 ms 3504 KiB
02_small_38.txt AC 2 ms 3512 KiB
02_small_39.txt AC 2 ms 3512 KiB
02_small_40.txt AC 2 ms 3464 KiB
02_small_41.txt AC 2 ms 3508 KiB
02_small_42.txt AC 2 ms 3496 KiB
02_small_43.txt AC 2 ms 3508 KiB
02_small_44.txt AC 2 ms 3488 KiB
02_small_45.txt AC 2 ms 3448 KiB
02_small_46.txt AC 2 ms 3504 KiB
02_small_47.txt AC 2 ms 3416 KiB
02_small_48.txt AC 2 ms 3464 KiB
02_small_49.txt AC 2 ms 3396 KiB
02_small_50.txt AC 2 ms 3460 KiB
02_small_51.txt AC 2 ms 3516 KiB
02_small_52.txt AC 2 ms 3488 KiB
02_small_53.txt AC 2 ms 3500 KiB
02_small_54.txt AC 2 ms 3460 KiB
03_rand_01.txt AC 22 ms 3872 KiB
03_rand_02.txt AC 3 ms 3564 KiB
03_rand_03.txt AC 5 ms 3668 KiB
03_rand_04.txt AC 25 ms 3516 KiB
03_rand_05.txt AC 6 ms 3504 KiB
03_rand_06.txt AC 2 ms 3456 KiB
03_rand_07.txt AC 2 ms 3448 KiB
03_rand_08.txt AC 28 ms 3808 KiB
03_rand_09.txt AC 6 ms 3576 KiB
03_rand_10.txt AC 22 ms 3448 KiB
03_rand_11.txt AC 16 ms 3516 KiB
03_rand_12.txt AC 14 ms 3456 KiB
03_rand_13.txt AC 2 ms 3448 KiB
03_rand_14.txt AC 15 ms 3496 KiB
03_rand_15.txt AC 7 ms 3452 KiB
03_rand_16.txt AC 9 ms 3480 KiB
03_rand_17.txt AC 12 ms 3500 KiB
03_rand_18.txt AC 5 ms 3460 KiB
03_rand_19.txt AC 10 ms 3456 KiB
03_rand_20.txt AC 2 ms 3412 KiB
03_rand_21.txt AC 2 ms 3436 KiB
03_rand_22.txt AC 2 ms 3512 KiB
03_rand_23.txt AC 2 ms 3448 KiB
03_rand_24.txt AC 23 ms 3464 KiB
03_rand_25.txt AC 10 ms 3492 KiB
03_rand_26.txt AC 4 ms 3460 KiB
03_rand_27.txt AC 19 ms 4384 KiB
03_rand_28.txt AC 6 ms 3460 KiB
03_rand_29.txt AC 2 ms 3476 KiB
03_rand_30.txt AC 17 ms 3664 KiB
03_rand_31.txt AC 9 ms 3412 KiB
03_rand_32.txt AC 14 ms 4148 KiB
03_rand_33.txt AC 2 ms 3504 KiB
03_rand_34.txt AC 20 ms 4596 KiB
03_rand_35.txt AC 3 ms 3388 KiB
03_rand_36.txt AC 21 ms 3512 KiB
03_rand_37.txt AC 20 ms 3444 KiB
03_rand_38.txt AC 18 ms 4268 KiB
03_rand_39.txt AC 7 ms 3456 KiB
03_rand_40.txt AC 2 ms 3448 KiB