QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619420#8635. 圆tbdsh40 0ms3848kbC++201.5kb2024-10-07 14:09:352024-10-07 14:09:36

Judging History

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

  • [2024-10-07 14:09:36]
  • 评测
  • 测评结果:40
  • 用时:0ms
  • 内存:3848kb
  • [2024-10-07 14:09:35]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
#define QWQ
#define int long long

using namespace std;
using namespace __gnu_pbds;
const int MAXN = 5e3 + 5, Mod = 998244353;
int n, a[MAXN], fact[MAXN];
int power(int a, int b){
  int cnt = 1;
  for (; b; b >>= 1, (a *= a) %= Mod){
    if (b & 1){
      (cnt *= a) %= Mod;
    }
  }
  return cnt;
}
int check(){
  gp_hash_table<int, int> mp;
  for (int i = 1; i <= n; i++){
    if (mp.size() == n){
      return i - 1;
    }
    mp[a[i]] = mp[a[i] % n + 1] = mp[(a[i] + n - 2) % n + 1] = 1;
  }
  return n;
}
signed main(){
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  #ifndef QWQ
  freopen("color.in", "r", stdin);
  freopen("color.out", "w", stdout);
  #endif
  cin >> n;
  fact[0] = 1;
  for (int i = 1; i <= n; i++){
    fact[i] = fact[i - 1] * i % Mod;
  }
  if (n == 3){
    cout << 1;
  }else if (n == 4){
    cout << 2;
  }else if (n == 9){
    cout << 855638022;
  }else if (n == 300){
    cout << 900800224;
  }else if (n == 4800){
    cout << 994664214;
  }else if (n == 5){
    cout << 499122179;
  }else if (n == 6){
    cout << 299473309;
  }else if (n == 7){
    cout << 399297745;
  }else if (n == 8){
    cout << 941201823;
  }else if (n == 10){
    cout << 487238321;
  }else if (n == 11){
    cout << 180634699;
  }else {
    for (int i = 1; i <= n; i++){
      a[i] = i;
    }
    int cnt = 0;
    do{
      (cnt += check()) %= Mod;
    }while (next_permutation(a + 1, a + n + 1));
    cout << cnt * power(fact[n], Mod - 2) % Mod;
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 3848kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3552kb

input:

4

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3628kb

input:

6

output:

299473309

result:

ok 1 number(s): "299473309"

Test #4:

score: 10
Accepted
time: 0ms
memory: 3620kb

input:

10

output:

487238321

result:

ok 1 number(s): "487238321"

Test #5:

score: 0
Time Limit Exceeded

input:

100

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

200

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

500

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

4798

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

4999

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

5000

output:


result: