QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#266633 | #7618. Pattern Search | ucup-team173# | WA | 1ms | 7700kb | C++20 | 1.7kb | 2023-11-26 16:06:40 | 2023-11-26 16:06:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define Mp make_pair
#define SZ(x) ((int)(x).size())
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define int ll
const int MAXN = 1.1e5 + 5;
pair<int, ll> s[MAXN * 60];
int f[MAXN * 60][2];
unordered_map<ll, int> mp[61];
int Son[MAXN * 60][2];
ll n, a[MAXN];
int m, tot, rt;
void dfs(int x) {
if(!x) {
f[x][0] = 0, f[x][1] = 1;
return ;
}
if(s[x].first == 0) {
f[x][0] = 1, f[x][1] = 0;
return ;
}
int ls = Son[x][0];
int rs = Son[x][1];
dfs(ls), dfs(rs);
f[x][0] = f[ls][0] + f[rs][0];
f[x][1] = f[ls][1] + f[rs][1];
f[x][0] = min(f[x][0], f[x][1] + 1);
f[x][1] = min(f[x][1], f[x][0] + 1);
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= m; i++) {
cin >> a[i];
s[++tot] = Mp(0, a[i]), mp[0][a[i]] = tot;
ll now = (a[i] > (n >> 1) ? n - a[i] + 1 : a[i]), last = tot;
for(ll t = n >> 1, j = 1; t; t >>= 1, j++) {
if(!mp[j].count(now)) s[++tot] = Mp(j, now), mp[j][now] = tot;
int x = mp[j][now];
if(Son[x][0] != last && Son[x][1] != last) {
Son[x][Son[x][0] != 0] = last;
}
last = x, now = (now > (t >> 1) ? t - now + 1 : now);
}
}
rt = max_element(s + 1, s + tot + 1) - s, dfs(rt);
cout << min(f[rt][0], f[rt][1]) << '\n';
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7700kb
input:
2 bajkaaall aal abca cba
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'