QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796764#6558. Allergen Testingzeyu#RE 1ms3852kbC++233.3kb2024-12-02 02:21:492024-12-02 02:21:50

Judging History

你现在查看的是最新测评结果

  • [2024-12-02 02:21:50]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3852kb
  • [2024-12-02 02:21:49]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pl pair<ll, ll>
#define pi pair<int, int>
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;

#if 1
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "]";}
void _print() {cerr << endl << flush;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "*["<<__LINE__<<"]\t"<< #x << " = "; _print(x)
#endif

const ll mod = 1e9 + 7;

template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll gcd(ll a, ll b) {if(b == 0){return a;} return gcd(b, a % b);}

__int128 read_int128() {
    string str;
    cin >> str;

    __int128 x = 0, f = 1;
    if (str[0] == '-') {
        f = -1;
        str = str.substr(1);
    }

    for (char c : str) {
        x = x * 10 + (c - '0');
    }
    return x * f;
}

ostream& operator<<(ostream& dest, __int128_t value){
    ostream::sentry s( dest );
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char* d = std::end(buffer);
        do{
            -- d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            -- d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(ios_base::badbit);
        }
    }
    return dest;
}

void solve(){
	__int128 n = read_int128(), d = read_int128();
	__int128 ans = 1ll << 60;
	__int128 lx = 1, rx = n;
	while(rx > lx){
		__int128 mid = (lx + rx + 1) >> 1;
		__int128 cur = 1;
		for (ll i = 0; i < d; i ++){
			cur *= mid;
			if (cur > n) break;
		}
		if (cur > n){
			rx = mid - 1;
		} else{
			lx = mid;
		}
	}

	auto work = [&](__int128 div){
		if (div == 1) return;
		__int128 curd = d, curn = n, cur = 0;
		while(curd && n > 1){
			chkmin(ans, (curn + 1) / 3 * 2 + cur);
			curn = (curn + div - 1) / div;
			curd --; cur += div - 1;
		}
		chkmin(ans, (curn + 1) / 3 * 2 + cur);
	};

	work(lx); work(lx - 1); work(lx + 1);

	cout << ans << '\n';
}
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tc = 1;
	cin >> tc;
	while(tc --){
		solve();
	}
}

/*
Do something instead of nothing!
Print out stuffs / study samples when you cannot find the bug!
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3852kb

input:

1
4 1

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Runtime Error

input:

10000
1 1
1000000000000000000 1
1 1000000000000000000
1000000000000000000 1000000000000000000
26615519354743225 163142634
26615519354743225 163142634
26615519354743224 163142634
26615519354743226 163142634
847997831064072529 920867976
847997831064072529 920867976
847997831064072528 920867976
8479978...

output:


result: