QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745087#8166. Almost Largeucup-team3215TL 1626ms238048kbC++201.0kb2024-11-14 03:57:212024-11-14 03:57:22

Judging History

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

  • [2024-11-14 03:57:22]
  • 评测
  • 测评结果:TL
  • 用时:1626ms
  • 内存:238048kb
  • [2024-11-14 03:57:21]
  • 提交

answer

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

using namespace std;

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

int vis[N];
vector<int> s[2][N];

template <int p>
inline void iter(int v, int k, auto f) {
  if (!p) return f(v, k);
  for (int t = 3; t--; ) if (int d = (v / p % 3 < t) + k; d < 2) iter<p / 3>(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>(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>(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: 100
Accepted
time: 2ms
memory: 5572kb

input:

2
21 14

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 2ms
memory: 5568kb

input:

2
12 1

output:

No

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 2ms
memory: 5580kb

input:

5
5 15 45 135 405

output:

Yes

result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 1626ms
memory: 238048kb

input:

133729
515927 251707 509591 317498 177389 461753 275297 7848 452936 13695 394604 125096 242390 450018 501210 126212 64950 263819 216408 528515 454055 530346 241575 397712 524748 322154 60967 469683 464304 390612 215474 271893 127704 380804 390268 391984 401683 315101 523057 462146 194859 259610 4680...

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Time Limit Exceeded

input:

147249
527398 156678 5013 10368 17399 404399 217450 522971 155321 137708 345490 200329 199022 345117 528603 317293 67005 130459 30924 64105 394479 346479 136837 348286 469655 20584 530096 17403 74005 411855 519402 345524 406285 466066 155362 336093 353489 89402 215173 316455 86564 219312 275911 5142...

output:


result: