結果

問題 No.1528 Not 1
ユーザー icchiposticchipost
提出日時 2021-06-04 21:18:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 900 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 167,244 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 11:18:22
合計ジャッジ時間 3,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 10 ms
4,380 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 6 ms
4,384 KB
testcase_09 AC 3 ms
4,384 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 13 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  int n;
  cin >> n;
  
  if (n < 6) {
    if (n == 1) cout << 1 << endl;
    if (n == 2) cout << 1 << endl;
    if (n == 3) cout << -1 << endl;
    if (n == 4) cout << 2 << " " << 4 << endl;
    if (n == 5) cout << -1 << endl;
    return 0;
  }
  
  vector<int> a, b, c;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 0 && i % 3 == 0) c.push_back(i);
    else if (i % 2 == 0) a.push_back(i);
    else if (i % 3 == 0) b.push_back(i);
  }
  int m = (n + 1) / 2;
  rep(i, m) {
    if (!a.empty()) {
      cout << a.back() << " ";
      a.pop_back();
    }
    else if (!c.empty()) {
      cout << c.back() << " ";
      c.pop_back();
    }
    else {
      cout << b.back() << " ";
      b.pop_back();
    }
  }
  cout << endl;
  return 0;
}
0