QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184876 | #5407. 基础图论练习题 | YuJiahe | 0 | 7ms | 3908kb | C++23 | 1.8kb | 2023-09-21 13:52:56 | 2023-09-21 13:52:57 |
answer
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#define mod 1000000007
using namespace std;
const int N = 5005;char tp[N];
int t, n, a[N], id[N], rk[N], le[N], ri[N], to[N][N], ans, sm[N], s0[N], s1[N], s2[N];
int main(){scanf("%d", &t);
while (t --){scanf("%d", &n), id[1] = 1, a[1] = 0, ans = 0;
for (int i = 2;i <= n;i ++){scanf("%s", tp), id[i] = i, a[i] = 0;
for (int j = 0;j < i - 1;j ++) a[i] +=
to[i][j + 1] = (tp[j >> 2] >= 'A' ? tp[j >> 2] - 'A' + 10 : tp[j >> 2] - '0') >> (j & 3) & 1;
for (int j = 1;j < i;j ++) a[j] += 1 - to[i][j];
}sort(id + 1, id + n + 1, [&](int x, int y){return a[x] < a[y];});
for (int i = 1;i <= n;i ++) rk[id[i]] = i;
sort(a + 1, a + n + 1);
for (int i = 1;i <= n;i ++){
if (i > 1 && a[i] == a[i - 1])
le[i] = le[i - 1];else le[i] = i;
}
for (int i = n;i >= 1;i --){
if (i < n && a[i] == a[i + 1])
ri[i] = ri[i + 1];else ri[i] = i;
}
for (int i = 1;i <= n;i ++) sm[i] = sm[i - 1] + a[i];
for (int i = 1;i <= n;i ++) sm[i] -= i * (i - 1) >> 1;
for (int i = 1;i <= n;i ++) s0[i] = s0[i - 1] + (sm[i] == 0);
for (int i = 1;i <= n;i ++) s1[i] = s1[i - 1] + (sm[i] == 1);
for (int i = 1;i <= n;i ++) s2[i] = s2[i - 1] + (sm[i] == -1);
for (int i = n, tmp, l, r;i >= 2;i --){
for (int j = i - 1;j >= 1;j --){
if (to[i][j]) swap(i, j);
tmp = s0[n], l = ri[rk[i]], r = le[rk[j]];
if (a[l] + 1 == a[r]) goto Calc;
if (l < r) tmp += s1[r - 1] - s1[l - 1] - s0[r - 1] + s0[l - 1];
else tmp += s2[l - 1] - s2[r - 1] - s0[l - 1] + s0[r - 1];
Calc: ans = (ans * 2ll + tmp) % mod;
if (to[j][i]) swap(i, j);
}
}printf("%d\n", ans);
}
}
// 2 0 1
// 3
// i -> j cd[i] --, cd[j] ++
// j -> i cd[j] --, cd[i] ++ (swap(i, j))
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 3908kb
input:
10000 100 1 2 2 8 C0 F0 27 78 AE1 C01 511 D87 EF20 3873 2742 73D0 DC9B0 FB2A3 9C011 9B4E0 95DC00 A7B980 F43531 6A6245 5347BE0 1A6C8A1 88E46D6 64CF3AE D25F63C1 C894E4C3 1C0AFD73 EC1C3F9A 087CE17C0 22149A380 B28038AF1 B9CA21C7F D78F5307C1 49045489A2 72C4DE6FD1 7713F40D05 EEE8878EEC1 310E62812B1 DA9D5B...
output:
281603732 13 272968235 371842543 63 0 1983 2 408846484 268435455 48539328 33933 2 884007485 63 2656276 2509 0 736524363 371842543 2105903 54291 32916 3147839 723736248 502774846 884008005 719476259 719476259 105360 541412105 377590756 60415 7092655 719476259 371842543 63 63 115 2335281 268435455 13 ...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '272968235'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%