QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745098#8166. Almost Largeucup-team3215WA 3ms6732kbC++201.2kb2024-11-14 04:10:462024-11-14 04:10:47

Judging History

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

  • [2024-11-14 04:10:47]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6732kb
  • [2024-11-14 04:10:46]
  • 提交

answer

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

using namespace std;

constexpr int L = 12, H = 2, 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 u, int k, auto f) {
  if (!p) return f(v, k);
  if (c && vis2[k][(p > 1) + (p > 3) + (p > 9) + (p > 27) + (p > 81) + (p > 243) + (p > 729) + (p > 2187)][v + u]++) return;
  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, u, 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, -1, 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, tmp * (N / 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: 3ms
memory: 6732kb

input:

2
21 14

output:

No

result:

wrong answer expected YES, found NO