QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266633#7618. Pattern Searchucup-team173#WA 1ms7700kbC++201.7kb2023-11-26 16:06:402023-11-26 16:06:40

Judging History

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

  • [2023-11-26 16:06:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7700kb
  • [2023-11-26 16:06:40]
  • 提交

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'