QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749540 | #8166. Almost Large | ucup-team3215 | TL | 0ms | 3620kb | C++20 | 1.8kb | 2024-11-15 03:29:46 | 2024-11-15 03:29:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int K = 12;
struct node {
map<int, int> go;
int sz{0};
int who{-1};
};
vector<node> all;
int create() {
all.emplace_back();
return all.size() - 1;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
mt19937 rng{1000-7};
vector<int> p(K);
iota(p.begin(),p.end(),0);
shuffle(p.begin(),p.end(),rng);
int n;
cin >> n;
vector<array<int, K>> a(n);
int root = create();
queue<int> q;
q.push(0);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
int cur = root;
if (i)all[cur].sz++;
for (int j = 0; j < K; ++j, x /= 3) a[i][j] = x % 3;
{
array<int,K> z;
for(int j = 0;j < K;++j)z[j]=a[i][p[j]];
swap(a[i],z);
}
for (int j = 0; j < K; ++j) {
if (!all[cur].go.count(a[i][j])) {
all[cur].go[a[i][j]] = create();
}
cur = all[cur].go[a[i][j]];
if (i)all[cur].sz++;
}
all[cur].who = i;
}
vector<char> done(n); done[0] = 1;
while (q.size() && !done[n - 1]) {
int p = q.front();
q.pop();
auto dfs = [&](auto &&dfs, int v = 0, int bal = 0, int d = 0) -> int {
if (!all[v].sz || bal > 1)return 0;
if (d == K) {
--all[v].sz;
q.push(all[v].who);
done[all[v].who] = 1;
return 1;
}
int z = 0;
for (auto [x, to]: all[v].go) {
z += dfs(dfs,to,bal + (x < a[p][d]),d + 1);
}
all[v].sz-=z;
return z;
};
dfs(dfs);
}
cout << (done[n-1]?"Yes":"No");
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
2 21 14
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 12 1
output:
No
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
5 5 15 45 135 405
output:
Yes
result:
ok answer is YES
Test #4:
score: -100
Time Limit Exceeded
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...