結果

問題 No.1651 Removing Cards
ユーザー startcppstartcpp
提出日時 2021-08-20 21:57:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 568 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 8,532 KB
最終ジャッジ日時 2024-04-22 04:29:00
合計ジャッジ時間 13,664 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 122 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 199 ms
5,376 KB
testcase_10 AC 184 ms
5,376 KB
testcase_11 AC 180 ms
5,376 KB
testcase_12 AC 186 ms
5,376 KB
testcase_13 AC 197 ms
5,376 KB
testcase_14 AC 182 ms
5,376 KB
testcase_15 AC 568 ms
8,280 KB
testcase_16 AC 552 ms
8,280 KB
testcase_17 AC 558 ms
8,152 KB
testcase_18 AC 550 ms
8,280 KB
testcase_19 AC 550 ms
8,284 KB
testcase_20 AC 536 ms
8,408 KB
testcase_21 AC 549 ms
8,408 KB
testcase_22 AC 558 ms
8,280 KB
testcase_23 AC 197 ms
5,376 KB
testcase_24 AC 150 ms
5,376 KB
testcase_25 AC 523 ms
8,180 KB
testcase_26 AC 502 ms
8,280 KB
testcase_27 AC 564 ms
8,408 KB
testcase_28 AC 557 ms
8,408 KB
testcase_29 AC 551 ms
8,284 KB
testcase_30 AC 557 ms
8,532 KB
testcase_31 AC 552 ms
8,408 KB
testcase_32 AC 165 ms
5,376 KB
testcase_33 AC 165 ms
5,376 KB
testcase_34 AC 166 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int K, q;
int ns[100000];
vector<int> a;

int f(int pos) {
	int ng = 0, ok = 3 * (1e+18), mid;
	while (ok - ng >= 2) {
		mid = (ng + ok) / 2;
		//前のフェーズで人0~mid-1がいるとき、rem人生き残る
		int rem = mid - (mid + K - 1) / K;
		if (rem >= pos + 1) ok = mid;
		else ng = mid;
	}
	return ok - 1;
}

signed main() {
	int i;
	
	cin >> K >> q;
	rep(i, q) cin >> ns[i];
	
	int pos = 0;
	while (pos <= (int)(1e+18)) {
		a.push_back(pos);
		pos = f(pos);
	}
	
	rep(i, q) {
		int iter = lower_bound(a.begin(), a.end(), ns[i]) - a.begin();
		cout << a[iter - 1] + 1 << endl;
	}
	return 0;
}
0