結果

問題 No.1651 Removing Cards
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-07-25 13:57:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,911 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 105,288 KB
実行使用メモリ 110,664 KB
最終ジャッジ日時 2024-04-22 03:26:24
合計ジャッジ時間 6,181 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 34 ms
5,376 KB
testcase_10 AC 56 ms
5,376 KB
testcase_11 AC 68 ms
5,376 KB
testcase_12 AC 76 ms
5,376 KB
testcase_13 AC 88 ms
5,376 KB
testcase_14 AC 99 ms
5,376 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }



int main() {
  unsigned long long K;
  int Q;
  scanf("%llu%d", &K, &Q);
  --K;
  
  const unsigned __int128 invK = ~0ULL / K + 1;
  
  if (K == 1) {
    for (; Q--; ) {
      unsigned long long N;
      scanf("%llu", &N);
      
      unsigned long long x = 0;
      for (; ; ) {
        const unsigned long long xx = x + x + 1;
        if (xx >= N) {
          break;
        }
        x = xx;
      }
      printf("%lld\n", x + 1);
    }
  } else {
    for (; Q--; ) {
      unsigned long long N;
      scanf("%llu", &N);
      
      if (N <= K + 1) {
        printf("%llu\n", N);
      } else {
        unsigned long long x = K;
        for (; ; ) {
          const unsigned long long y = (invK * x) >> 64;
          const unsigned long long xx = x + y + (K * y <= x);
          if (xx >= N) {
            break;
          }
          x = xx;
        }
        printf("%lld\n", x + 1);
      }
    }
  }
  return 0;
}
0