QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#583073 | #9353. Interesting Permutation | shift# | WA | 0ms | 3524kb | C++20 | 1.2kb | 2024-09-22 18:12:57 | 2024-09-22 18:12:57 |
Judging History
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'