QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607882#9353. Interesting Permutationcatwine#WA 69ms20056kbC++141.1kb2024-10-03 16:51:112024-10-03 16:51:11

Judging History

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

  • [2024-10-03 16:51:11]
  • 评测
  • 测评结果:WA
  • 用时:69ms
  • 内存:20056kb
  • [2024-10-03 16:51:11]
  • 提交

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] || a[i] < 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];
    } else {
      cur = a[i], cnt = 0;
      while (i < n && a[i] == cur) {
        ++cnt, ++i;
      }
      ans = ans * A[cnt] % MOD;
    }
  }
  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: 7ms
memory: 19148kb

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: 69ms
memory: 20056kb

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
0
393216
2048
0
0
0
0
132462073
643978532
0
65536
8
442450902
512
2
0
377487360
0
0
2
0
0
0
4
122880
0
0
2048
8
0
768
0
0
0
327352699
65536
2
0
256
0
0
2
0
2
442450902
0
0
49152
0
4
0
663676353
2
3145728
0
0
12582912
4
1
2097152
0
0
0
0
0
0
0
2
0
0
9216
402653184
192
0
0
768
256
251658240
2
...

result:

wrong answer 6th lines differ - expected: '0', found: '393216'