QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225131#7615. Sequence FoldingLainRE 1ms3476kbC++201.4kb2023-10-24 00:28:222023-10-24 00:28:22

Judging History

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

  • [2023-10-24 00:28:22]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3476kb
  • [2023-10-24 00:28:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  auto msb = [&](ll x)->int {
    if (x == 0) return 0;
    return __lg(x) + 1;
  };

  ll n;
  int m;
  cin >> n >> m;
  vi p(m);
  vector<vector<ll>> levels(64);
  for (auto& x : p) {
    cin >> x, x--;
    levels[msb(x)].push_back(x);
  }
  map<ll, array<int, 2>> dp;
  for (auto& x : p) {
    dp[x] = {1, 0};
  }
  for (auto x: p) {
    ll up = ((1LL<<msb(x)) - x - 1) + (1LL<<msb(x));
    if (up < n && !dp.count(up)) {
      levels[msb(up)].push_back(up);
      dp[up] = {0, 1};
    }
  }

  for (int j = sz(levels) - 1; j > 0; j--) {
    if (levels[j].empty()) continue;
    auto& level = levels[j];
    for (auto& x : level) {
      int bit = j - 1;
      ll to = (1LL<<bit) - 1 - (x - (1LL<<bit));
      if (!dp.count(to)) {
        levels[msb(to)].push_back(to);
        dp[to] = {0, 1};
      }

      array<int, 2> ndp;
      ndp[0] = min(dp[to][0] + dp[x][0], dp[to][1] + dp[x][1] + 1);
      ndp[1] = min(dp[to][1] + dp[x][1], dp[to][0] + dp[x][0] + 1);
      dp[to] = ndp;
    }
  }

  cout << min(dp[0][0], dp[0][1]) << '\n';
}

详细

Test #1:

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

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

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

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Runtime Error

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:


result: