結果
| 問題 |
No.1651 Removing Cards
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-25 13:57:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,911 bytes |
| コンパイル時間 | 1,120 ms |
| コンパイル使用メモリ | 105,472 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-14 02:18:12 |
| 合計ジャッジ時間 | 6,029 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 1 -- * 19 |
ソースコード
#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;
}