WA on #2
查看原帖
WA on #2
365751
Mr_罗楼主2024/10/23 15:14

RT,求调/hack。

wrong answer 74175th numbers differ - expected: '375938442', found: '374182788'

CF 记录(但 CF 好像提交记录页面炸了)。

并不是 dp ,而是半乱搞做法。

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ul unsigned ll
#define LL __int128_t
#define db double
#define DB long db
#define pii pair<int, int>
#define fi first
#define se second
#define mkpr make_pair
#define mem(a, x) memset(a, x, sizeof(a));
#define rep(i, l, r) for (int i(l), i##End(r); i <= i##End; i = -~i)
#define per(i, r, l) for (int i(r), i##End(l); i >= i##End; i = ~-i)

template<typename T, typename U> void chkmx(T &_a, U _b) { if (_a < _b) _a = _b; }
template<typename T, typename U> void chkmn(T &_a, U _b) { if (_a > _b) _a = _b; }

constexpr int N = 500005;
constexpr ll mod = 1000000007, INF = 0x3f3f3f3f3f3f3f3f;
int n;
ll ans, pw;
int a[N];
ll f[N], g[N], h[N];
ll p[N], q[N], r[N];

void solve() {
    rep(i, 1, n) f[i] = g[i] = h[i] = 0, p[a[i]] = p[a[i] + 1] = 0, q[a[i]] = q[a[i] + 2] = 0, r[a[i]] = 0, (a[i] >= 2 && (r[a[i] - 2] = 0));
    scanf("%d", &n);
    rep(i, 1, n) scanf("%d", &a[i]);
    ans = 0, pw = 1; per(i, n, 1) {
        f[i] = (1 + p[a[i]] + p[a[i] + 1] + q[a[i] + 2]) % mod, (p[a[i]] += f[i]) %= mod;
        if (a[i] > 1) g[i] = (1 + q[a[i]] + r[a[i] - 2]) % mod, (q[a[i]] += g[i]) %= mod;
        if (a[i] < n) h[i] = (1 + r[a[i]] + q[a[i] + 2]) % mod, (r[a[i]] += h[i]) %= mod;
        if (!a[i]) (ans += f[i]) %= mod; else if (a[i] == 1) (pw <<= 1) %= mod;
    } printf("%lld\n", (ans + pw - 1 + mod) % mod);
    // #ifdef JYR
    // rep(i, 1, n) printf("%d: %lld %lld\n", i, f[i], g[i]);
    // #endif
}

void init() {}

int main() {
    init();
    int _; scanf("%d", &_);
    while (_--) solve();
    return 0;
}
2024/10/23 15:14
加载中...