QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#46019#4422. Two PermutationsmiaomiaoziWA 1192ms111084kbC++173.1kb2022-08-24 20:45:572022-08-24 20:46:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-24 20:46:00]
  • 评测
  • 测评结果:WA
  • 用时:1192ms
  • 内存:111084kb
  • [2022-08-24 20:45:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672346917

#ifndef LOCAL
#define LOG(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long LL;
typedef pair <int, int> PII;

constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-8;
const double PI = acos(-1);

int multi_cases = 1;

// constexpr int P = 1000000007;
constexpr int P = 998244353;

// assume -p <= x < 2P
int norm(int x) {
    if (x < 0) { x += P; }
    if (x >= P) { x -= P; }
    return x;
}
template<class T>
T power(T a, int b) {
    T res = 1;
    for (; b; b >>= 1, a *= a)  if (b & 1) res *= a;
    return res;
}
struct Z {
    int x;
    Z(int x = 0) : x(norm(x)) {}
    int val() const { return x; }
    Z operator-() const { return Z(norm(P - x)); }
    Z inv() const { assert(x != 0); return power(*this, P - 2); }
    Z &operator*=(const Z &rhs) { x = (long long)(x) * rhs.x % P; return *this; }
    Z &operator+=(const Z &rhs) { x = norm(x + rhs.x); return *this; }
    Z &operator-=(const Z &rhs) { x = norm(x - rhs.x); return *this; }
    Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
    friend Z operator*(const Z &lhs, const Z &rhs) { Z res = lhs; res *= rhs; return res; }
    friend Z operator+(const Z &lhs, const Z &rhs) { Z res = lhs; res += rhs; return res; }
    friend Z operator-(const Z &lhs, const Z &rhs) { Z res = lhs; res -= rhs; return res; }
    friend Z operator/(const Z &lhs, const Z &rhs) { Z res = lhs; res /= rhs; return res; }
    friend bool operator==(const Z &lhs, const Z &rhs) { return lhs.val() == rhs.val(); }
    friend istream &operator >> (istream &input, Z &o) {  input >> o.x; return input; }
    friend ostream &operator << (ostream &output, const Z &o) { output << o.val(); return output; }
};

void A_SOUL_AvA () {
    int n;
    cin >> n;

    vector <int> a(n + 1), b(n + 1), c(n * 2 + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int j = 1; j <= n; j++) {
        cin >> b[j];
    }
    for (int i = 1; i <= n * 2; i++) {
        cin >> c[i];
    }

    vector <Z> f(n * 2 + 1);
    f[0] = 1;

    vector <set<PII>> g(n * 2 + 1);
    g[0] = {{0, 0}};

    vector pos(n + 1, vector<int>(2));
    for (int i = 1; i <= n; i++) {
        pos[a[i]][0] = i;
        pos[b[i]][1] = i;
    }

    for (int i = 1; i <= n * 2; i++) {
        int a = pos[c[i]][0], b = pos[c[i]][1];
        
        int u = i - a, v = i - b;
        if (u >= 0 && g[i - 1].count({a - 1, u})) {
            f[i] += 1;
            g[i].insert({a, u});
        }
        if (v >= 0 && g[i - 1].count({v, b - 1})) {
            f[i] += 1;
            g[i].insert({v, b});
        }
    }

    cout << f[n * 2] << endl;
}

int main () {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int T = 1;
    for (multi_cases && cin >> T; T; T--) {
        A_SOUL_AvA ();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1192ms
memory: 111084kb

input:

282
1000
434 697 735 906 614 835 227 800 116 98 776 601 110 371 262 452 608 368 719 717 241 572 203 410 440 749 604 457 516 637 488 691 841 493 418 307 745 499 833 789 819 179 357 288 129 954 29 391 80 389 771 613 653 747 928 570 518 1000 547 587 727 778 669 554 426 899 256 681 515 532 409 677 533 3...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st lines differ - expected: '4', found: '1'