QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745089#8166. Almost Largeucup-team3215WA 2ms5736kbC++201.2kb2024-11-14 04:04:472024-11-14 04:04:47

Judging History

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

  • [2024-11-14 04:04:47]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5736kb
  • [2024-11-14 04:04:47]
  • 提交

answer

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

constexpr int L = 12, H = L / 2 - 1, N = pow(3, L), M = pow(3, H);

int vis[N], vis2[2][L][N];
vector<int> s[2][N];

template <int p, bool c>
inline void iter(int v, int k, auto f) {
  if (c && vis2[k][(p > 1) + (p > 3) + (p > 9) + (p > 27) + (p > 81) + (p > 243) + (p > 729) + (p > 2187)][v]++) return;
  if (!p) return f(v, k);
  for (int t = 3; t--; ) if (int d = (v / p % 3 < t) + k; d < 2) iter<p / 3, c>(v - (v / p % 3 - t) * p, d, f);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n; cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    iter<M / 3, 0>(v[i] % M, 0, [&](int u, int k) { s[k][v[i] / M * M + u].push_back(i); });
  }
  vector<int> q{0};
  vis[0] = 1;
  for (int i = 0; i < q.size() && !vis[n - 1]; ++i) if (auto tmp = v[q[i]] % M; 1) iter<N / M / 3, 1>(N / M - 1 - v[q[i]] / M, 0, [&](int u, int k) {
    u = (N / M - 1 - u) * M + tmp;
    for (int d = 0; d + k < 2; ++d) while (s[d][u].size()) {
      auto j = s[d][u].back();
      s[d][u].pop_back();
      if (!vis[j]) vis[j] = 1, q.push_back(j);
    }
  });
  cout << (vis[n - 1]? "Yes": "No");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5736kb

input:

2
21 14

output:

No

result:

wrong answer expected YES, found NO