QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#583073#9353. Interesting Permutationshift#WA 0ms3524kbC++201.2kb2024-09-22 18:12:572024-09-22 18:12:57

Judging History

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

  • [2024-09-22 18:12:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3524kb
  • [2024-09-22 18:12:57]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int P = 1e9 + 7;

const int N = 1e5;
std::vector<int> fac(N + 1);

i64 power(i64 a, int b, int P) {
    i64 res = 1;
    while(b) {
        if(b & 1) res = res * a % P;
        a = a * a % P;
        b >>= 1;
    }
    return res;
}

void solve() {
    int n;
    std::cin >> n;

    int s = 0, ok = true;
    std::vector<int> h(n);
    for(int i = 0; i < n; i ++ ) {
        std::cin >> h[i];
        if(i) {
            s += h[i] != h[i - 1];
            ok &= h[i] >= h[i - 1];
        }
        ok &= h[i] <= n - 1;
    }

    if(not ok) {
        std::cout << 0 << '\n';
        return;
    }

    int r = 0;
    i64 ans = power(2, s, P);
    
    for(int i = 1; i < n; i ++ ) {
        if(h[i] == h[i - 1]) {
            ans = ans * r % P;
            r --;
        } else {
            r += h[i] - h[i - 1] - 1;
        }
    }
    
    std::cout << ans << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    fac[0] = 1;
    for(int i = 1; i <= N; i ++ ) {
        fac[i] = fac[i - 1] * i % P;
    }

    int T = 1;
    // std::cin >> T;
    while(T -- ) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3524kb

input:

3
3
0 2 2
3
0 1 2
3
0 2 3

output:

0

result:

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