提交记录 3733
| 用户 | 题目 | 状态 | 得分 | 用时 | 内存 | 语言 | 代码长度 |
|---|---|---|---|---|---|---|---|
| jhdjames37 | noi18b. 【NOI2018】冒泡排序 | Runtime Error | 44 | 124.216 ms | 10576 KB | C++ | 2.30 KB |
| 提交时间 | 评测时间 |
|---|---|
| 2018-07-18 16:01:14 | 2020-07-31 21:25:21 |
#include <cstdio>
#include <cstring>
#include <algorithm>
const int MAXN = 6e5 + 10;
const int MOD = 998244353;
int n;
int a[MAXN];
namespace solver1 {
void main() {
static int p[MAXN];
for (int i = 1; i <= n; i++) p[i] = a[i];
int ans = 0;
while(std::next_permutation(p + 1, p + n + 1)) {
static int tmp[MAXN];
int c = 0, x = 0;
for (int i = 1; i <= n; i++) tmp[i] = p[i], x += std::abs(i - p[i]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
if (tmp[j] > tmp[j + 1]) {
std::swap(tmp[j], tmp[j + 1]);
c++;
}
}
}
if (c == x / 2) ans++;
}
printf("%d\n", ans);
}
}
namespace {
inline int add(int x) { return x >= MOD ? x - MOD : x; }
inline int sub(int x) { return x < 0 ? x + MOD : x; }
inline int mul(int x, int y) { return (long long) x * y % MOD; }
inline void add(int &x, int y) { x = add(x + y); }
inline int pwr(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = mul(x, x)) {
if (y & 1) ans = mul(ans, x);
}
return ans;
}
}
namespace solver2 {
int f[1 << 20 | 1][2];
int bitcount(int x) { return x ? bitcount(x >> 1) + (x & 1) : 0; }
void main() {
memset(f, 0, sizeof f);
f[0][0] = 1;
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j < 2; j++) {
if (f[i][j]) {
int cur = bitcount(i) + 1;
for (int k = 1; k <= n; k++) {
if (!j && k < a[cur]) continue;
if (i & (1 << (k - 1))) continue;
if (cur == k) {
if (bitcount(i >> k)) continue;
if (bitcount(~(i | (1 << (k - 1))) & ((1 << k) - 1))) continue;
} else if (cur < k) {
if (bitcount(i >> k)) continue;
} else {
if (bitcount(~(i | (1 << (k - 1))) & ((1 << k) - 1))) continue;
}
add(f[i | (1 << (k - 1))][j || (k > a[cur])], f[i][j]);
}
}
}
}
printf("%d\n", f[(1 << n) - 1][1]);
}
}
int main() {
#ifndef LOCAL
freopen("inverse.in", "r", stdin);
freopen("inverse.out", "w", stdout);
#endif
int t;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
if (n <= 9) solver1::main();
else solver2::main();
}
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 13.095 ms | 32 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #2 | 124.216 ms | 32 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #3 | 1.939 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #4 | 2.65 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #5 | 2.88 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #6 | 5.284 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #7 | 12.422 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #8 | 12.44 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #9 | 25.976 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #10 | 64.497 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #11 | 87.703 ms | 8 MB + 24 KB | Accepted | Score: 4 | 显示更多 |
| Testcase #12 | 673.21 us | 8 MB + 44 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #13 | 673.68 us | 8 MB + 44 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #14 | 673.78 us | 8 MB + 44 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #15 | 675.24 us | 8 MB + 44 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #16 | 675.41 us | 8 MB + 44 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #17 | 688.31 us | 8 MB + 44 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #18 | 692.1 us | 8 MB + 48 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #19 | 693.51 us | 8 MB + 48 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #20 | 693.9 us | 8 MB + 48 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #21 | 7.877 ms | 9 MB + 60 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #22 | 9.734 ms | 9 MB + 320 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #23 | 12.78 ms | 9 MB + 756 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #24 | 15.839 ms | 10 MB + 164 KB | Runtime Error | Score: 0 | 显示更多 |
| Testcase #25 | 17.103 ms | 10 MB + 336 KB | Runtime Error | Score: 0 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-04-18 02:42:00 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠