QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607860 | #9353. Interesting Permutation | catwine# | WA | 71ms | 20228kb | C++14 | 1.2kb | 2024-10-03 16:46:52 | 2024-10-03 16:46:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#ifdef DEBUG
#define debug(x) cerr << #x << ": " << x << endl;
#else
#define debug(x)
#endif
const int MOD = 1e9 + 7;
int n, m, t;
const int N = 2e6 + 5;
int A[N];
void solve() {
cin >> n;
vector<int> a(n);
int pre = 0;
for (int &it : a) {
cin >> it;
}
if (a[0] != 0 || a[n - 1] != n - 1) {
cout << "0\n";
return;
}
for (int i = 1; i < n; ++i) {
if (a[i] < a[i - 1]) {
cout << "0\n";
return;
}
}
int cur = a[0], cnt = 1, ans = 1;
for (int i = 1; i < n; ++i) {
if (a[i] > cur) {
ans = 2 * ans % MOD;
cur = a[i];
// cout << "*=2\n";
} else {
cur = a[i], cnt = 0;
while (i < n && a[i] == cur) {
++cnt, ++i;
}
ans = ans * A[cnt] % MOD;
// cout << "ans *= " << A[cnt] << endl;
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0), cerr.tie(0);
int tmp = 1;
for (int i = 1; i <= (int)2e6; ++i) {
tmp = tmp * i % MOD;
A[i] = tmp;
}
// cerr << A[4];
cin >> t;
while (t--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 12ms
memory: 19240kb
input:
3 3 0 2 2 3 0 1 2 3 0 2 3
output:
2 4 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 71ms
memory: 20228kb
input:
10039 14 5 6 7 8 9 10 11 12 13 13 13 13 13 13 14 0 5 6 7 8 9 10 11 12 13 14 14 14 14 1 1 14 0 5 4 8 9 10 11 12 13 13 13 13 13 13 45 0 1 1 2 2 3 5 5 6 6 8 9 11 13 15 17 18 18 20 22 22 24 26 26 26 26 27 27 27 28 30 32 32 33 34 34 34 36 36 38 38 38 39 39 44 24 0 2 3 5 7 9 9 10 11 12 13 14 14 14 14 15 1...
output:
0 0 0 0 100663296 393216 2048 768 16777216 6291456 393216 132462073 643978532 424508992 65536 8 442450902 512 2 786432 377487360 8388608 268435456 2 50331648 18874368 3145728 4 122880 134217728 65536 2048 8 663676353 768 16384 159190872 12 327352699 65536 2 16384 256 1048576 32 2 207959545 2 4424509...
result:
wrong answer 5th lines differ - expected: '0', found: '100663296'