QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#227304#7615. Sequence FoldingGiga_Cronos#WA 421ms26880kbC++231.4kb2023-10-27 11:14:032023-10-27 11:14:03

Judging History

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

  • [2023-10-27 11:14:03]
  • 评测
  • 测评结果:WA
  • 用时:421ms
  • 内存:26880kb
  • [2023-10-27 11:14:03]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> pip;
#define MAXN (ll)(1e6 + 5)

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	ll n, m;
	cin >> n >> m;
	vector<pip> dp;
	vector<ll> pos;
	set<ll> pxx;
	for (int i = 0; i < m; i++) {
		ll x;
		cin >> x;
		x--;
		pos.push_back(x);
		pxx.insert(x);
	}
	ll p = 0;
	while ((1ll << p) != n)
		p++;
	for (auto x : pos) {
		dp.push_back(pip(x, pii(1, 0)));
	}
	for (auto x : pos)
		if (!pxx.count(n - x - 1))
			dp.push_back(pip(n - x - 1, pii(0, 1)));
	sort(all(dp));
	auto at = [&](ll x) {
		int pos = lower_bound(all(dp), pip(x, pii(0, 0))) - dp.begin();
		return dp[pos].second;
	};

	for (int i = 0; i < p; i++) {
		vector<pip> tp;
		for (auto p : dp) {
			if (p.first < n / 2) {
				pii xxx = at(n - p.first - 1);
				ll v0 = p.second.first + xxx.first;
				ll v1 = p.second.second + xxx.second;
				v0 = min(v0, v1 + 1);
				v1 = min(v1, v0 + 1);
				tp.push_back(pip(p.first, pii(v0, v1)));
			}
		}
		n /= 2;
		set<ll> pxx;
		for (auto x : tp)
			pxx.insert(x.first);
		for (auto x : pxx)
			if (!pxx.count(n - x - 1))
				tp.push_back(pip(n - x - 1, pii(0, 1)));
		dp.clear();
		dp = tp;
	}

	cout << min(dp[0].second.first, dp[0].second.second) << "\n";

	return 0;
}

詳細信息

Test #1:

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

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

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

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Wrong Answer
time: 421ms
memory: 26880kb

input:

17179869184 100000
138476 774165 993977 1152277 1236393 1244970 1534017 1693701 1763926 1778781 1842066 1874644 1885666 2120429 2485344 2977941 3158255 3340476 3504862 4000117 4066652 4197639 4338723 4389163 4576965 4761601 5097091 5175412 5295902 5810551 5855982 6001770 6111262 6163309 6351547 6582...

output:

0

result:

wrong answer 1st lines differ - expected: '99999', found: '0'