QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395432#3090. Inverse ProblemSamponYWWA 1ms5724kbC++141.7kb2024-04-21 14:36:512024-04-21 14:36:51

Judging History

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

  • [2024-04-21 14:36:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5724kb
  • [2024-04-21 14:36:51]
  • 提交

answer

#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
using poly = vector<int> ;
using Fp = pair<poly, poly> ;
#define N (1 << 20)
#define P 998244353
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
  int s = 1;
  while(n) {
    if(n & 1) s = 1ll * s * p % P;
    p = 1ll * p * p % P, n >>= 1;
  }
  return s;
}
int n, m, a[N]; bool u[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  if(n == m) {cout << 1; return 0;}
  FOR(i, 1, m) cin >> a[i], u[a[i]] = 1; bool F = 0;
  FOR(i, 1, m - 1) if(a[i] > a[i + 1]) F = 1;
  if(!F) {
    int cnt = 0, ans = 1;
    FOR(i, 1, n) {
      if(u[i]) {++cnt, --m; if(!m) ++cnt; continue;}
      ans = 1ll * ans * cnt % P, ++cnt;
    }
    cout << ans; return 0;
  }
  reverse(a + 1, a + 1 + m);
  FOR(i, 1, m) if(a[i] != i) {cout << 0; return 0;}
  int ans = 1, cnt = n - 1;
  FOR(i, m + 1, n) ans = 1ll * cnt * ans % P, --cnt;
  cout << ans;
  cerr << 1.0 * clock() / CLOCKS_PER_SEC;
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3808kb

input:

7 2
2 1

output:

720

result:

ok single line: '720'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

8 5
2 3 4 5 8

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5640kb

input:

498 121
20 35 40 72 79 92 113 117 154 231 243 244 264 268 304 337 362 378 463 477 56 494 495 1 342 395 183 423 291 475 82 422 96 265 83 283 242 34 187 75 74 47 208 380 400 17 202 50 418 73 233 307 181 344 48 149 107 435 365 459 280 55 375 391 403 241 64 374 10 386 322 308 186 136 277 497 332 262 165...

output:

0

result:

ok single line: '0'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 5724kb

input:

499 396
2 3 6 8 11 13 14 15 16 19 22 23 24 32 36 37 40 41 44 51 53 56 57 58 61 62 66 68 74 75 76 79 80 85 86 87 89 90 91 92 96 98 101 102 109 110 111 113 114 115 117 119 122 123 127 129 130 135 140 141 145 149 150 160 163 166 167 171 173 176 177 183 185 195 197 200 204 207 210 216 217 229 230 235 23...

output:

0

result:

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