結果

問題 No.478 一般門松列列
ユーザー zaichu
提出日時 2018-06-24 22:48:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 170,512 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-30 22:36:09
合計ジャッジ時間 2,978 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(n);
  iota(d.begin(), d.end(), 1000000000 / 2);
  // cout << n - k - 2 << endl;

  if (k == 0)
    d[0] -= 2;

  int cnt = 0;
  for (int i = 0; i < n - 2; i++) {
    if (cnt == n - k - 2) {
      d[i + 2] = d[i + 1];
      break;
    }
    if (cnt % 2 == 0) {
      d[i + 2] = d[i] - 1;
    } else {
      d[i + 2] = d[i] + 1;
    }
    cnt++;
  }
  for (int i = 0; i < n; i++) {
    if (i != 0)
      cout << ' ';
    cout << d[i];
  }
  cout << endl;
}
0