QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402549#4274. $2x + 2$I_Love_Sonechka#WA 1ms4100kbC++173.0kb2024-04-30 21:15:142024-04-30 21:15:14

Judging History

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

  • [2024-04-30 21:15:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4100kb
  • [2024-04-30 21:15:14]
  • 提交

answer

#include <bits/stdc++.h>
#include <math.h>

using namespace std;

// c++ short types
#define vt vector
typedef long long ll;
typedef long double ld;

void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }

const ll inf = 1e18;

const int base = 1e9;

typedef vt<int> lnum;
void print(lnum a) {
	printf("%d", a.empty() ? 0 : a.back());
	for(int i = a.size()-2; i >= 0; --i) {
		printf("%9d", a[i]);
	}
}
lnum read() {
	string s; cin >> s;
	lnum a;
	for(int i = s.length(); i > 0; i -= 9) {
		if(i < 9) {
			a.push_back(atoi(s.substr(0, i).c_str()));
		} else {
			a.push_back(atoi(s.substr(i-9, 9).c_str()));
		}
	}
	return a;
}
void add(lnum &a, lnum b) {
	int carry = 0;
	for(int i = 0; i < max(a.size(), b.size()) || carry; ++i) {
		if(i == a.size()) {
			a.push_back(0);
		}
		a[i] += carry + (i < b.size() ? b[i] : 0);
		carry = a[i] >= base;
		if(carry) {
			a[i] -= base;
		}
	}
}
void subtract(lnum &a, lnum b) {
	int carry = 0;
	for (size_t i=0; i<b.size() || carry; ++i) {
		a[i] -= carry + (i < b.size() ? b[i] : 0);
		carry = a[i] < 0;
		if (carry)  a[i] += base;
	}
	while (a.size() > 1 && a.back() == 0)
		a.pop_back();
}
void divide(lnum &a, int b) {
	int carry = 0;
	for(int i = a.size() - 1; i >= 0; --i) {
		long long cur = a[i] + carry * 1ll * base;
		a[i] = (int)(cur / b);
		carry = (int)(cur % b);
	}
	while(not a.empty() && a.back() == 0) {
		a.pop_back();
	}
}
bool comp(lnum a, int b) {
	// ? a >= b
	if(a.size() == 0) {
		return b == 0;
	} else if(a.size() == 1) {
		return a[0] >= b;
	}
	return true;
}
bool comp(lnum a, lnum b) {
	if(a.size() < b.size()) {
		return false;
	} else if(a.size() > b.size()) {
		return true;
	}
	for(int i = a.size() - 1; i >= 0; --i) {
		if(a[i] > b[i]) {
			return true;
		} else if(a[i] < b[i]) {
			return false;
		}
	}
	return true;
}

void solve() {
	lnum n = read();
	if(n == vt<int>(1)) {
		cout << "1\n";
		return ;
	} else if(n == vt<int>(2)) {
		cout << "2\n";
		return ;
	} else if(n == vt<int>(3)) {
		cout << "3\n";
		return ;
	} else if(n == vt<int>(4)) {
		cout << 3 << "\n";
		return ;
	}
	lnum value = n;
	add(value, {2});
	vt<lnum> cnt;
	for(int k = 0; k <= 350; ++k) {
		if(not comp(value, 3)) {
			break;
		}
		cnt.push_back(value);
		// value >= 3
		subtract(cnt.back(), {3});
		divide(cnt.back(), 2);
		divide(value, 2);
	}
	lnum res = {};
	for(int i = cnt.size() - 1; i >= 0; --i) {
		lnum delta = cnt[i];
		if(i + 1 < cnt.size()) {
			subtract(delta, cnt[i+1]);
		} else {
			add(delta, {+1});
		}
		for(int j = 1; j <= (i+2) / 2; ++j) {
			add(res, delta);
		}
	}
	{
		value = n;
		add(value, {2});
		lnum power = {4};
		for(int k = 0; k <= 350; ++k) {
			if(not comp(value, power)) {
				// (k-1) / 2
				add(res, {(k-1+2) / 2});
				break;
			}
			add(power, power);
		}
	}
	print(res);
}

int main()
{
	int tt = 1;
	for(int t = 0; t < tt; ++t) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

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

input:

4

output:

3

result:

ok answer is '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

10000000000

output:

6666666667

result:

ok answer is '6666666667'

Test #3:

score: 0
Accepted
time: 0ms
memory: 4100kb

input:

11537

output:

7692

result:

ok answer is '7692'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

41309

output:

27540

result:

ok answer is '27540'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3772kb

input:

8191927142339937565554845978095081242540169480073285738552305926582959325059543812213073905385467089

output:

5461284761559958377 36563985396720828360112986715523825701537284388639550 39695874808715936923644727

result:

wrong answer expected '546128476155995837703656398539...9550039695874808715936923644727', found '5461284761559958377'