結果
問題 | No.1651 Removing Cards |
ユーザー |
![]() |
提出日時 | 2021-08-20 22:54:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,156 bytes |
コンパイル時間 | 2,305 ms |
コンパイル使用メモリ | 110,300 KB |
最終ジャッジ日時 | 2025-01-24 00:12:46 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 TLE * 14 |
ソースコード
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } void solve() { ll K; int Q; cin >> K >> Q; vector<ll> X(Q); rep(q, Q) cin >> X[q]; map<ll, ll> m_dp; auto rec = [&](auto &&rec, ll n) -> ll { if (n <= K) return n; if (m_dp.count(n)) return m_dp[n]; ll removed = 1 + (n - 1) / K; ll val = rec(rec, n - removed); ll res = val + 1 + (val - 1) / (K - 1); return m_dp[n] = res; }; for (auto N : X) { ll ans = rec(rec, N); cout << ans << "\n"; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }