QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649242 | #5407. 基础图论练习题 | CloudWings | 0 | 3ms | 105832kb | C++14 | 2.8kb | 2024-10-17 22:14:51 | 2024-10-17 22:14:51 |
Judging History
answer
/*
* Time Spent:
0. Expect: min
1. Idea:
2. Code:
* Solution:
Tag:
https://www.cnblogs.com/CloudWings/p/18471311
* Summary:
*/
#include <bits/stdc++.h>
using namespace std;
double _st = clock();
const int N = 5005, mod = 1e9 + 7;
struct mint {
int val;
mint (int x=0) : val(x) {}
inline mint operator + (const mint& x) { return val+x.val >= mod ? val+x.val-mod : val+x.val; }
inline mint operator * (const mint& x) { return 1ll*val*x.val%mod; }
inline mint operator += (const mint& x) { return *this = *this + x; }
friend ostream& operator << (ostream& out, const mint& x) { return out << x.val; }
} qpow[N*N];
int n, out[N];
int L[N], R[N]; // 每一种出度在 p(排序后) 中最先/最后出现的位置
int f0[N][N], f1[N][N], f_1[N][N]; // 区间内前缀和跟 C(i,2) 相差 0/1/-1
bool e[N][N];
int main () {
#ifdef LOCAL
freopen("_1.in", "r", stdin);
freopen("_1.out", "w", stdout);
#else
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#endif
int T; cin >> T;
while (T--) {
cin >> n;
qpow[0] = 1;
for (int i = 1; i <= n*n; i++) qpow[i] = qpow[i-1] * 2;
for (int i = 1; i <= n; i++) out[i] = 0;
for (int i = 1; i < n; i++)
for (int j = 1; j <= (i+3)/4; j++) {
char ch; cin >> ch;
int x = isdigit(ch) ? ch-'0' : ch-'A'+10;
for (int k = 0; k <= 3; k++) {
int u = i+1, v = 4*j+k-3;
if (v >= u) break;
if (!(x>>k&1)) swap(u, v);
// printf("(%d,%d)\n", u, v);
e[u][v] = 1, e[v][u] = 0;
out[u]++;
}
}
static int p[N]; static long long sum[N];
for (int i = 1; i <= n; i++) p[i] = out[i];
sort(p+1, p+n+1);
for (int i = 1; i <= n; i++) R[p[i]] = i, sum[i] = sum[i-1] + p[i];
for (int i = n; i >= 1; i--) L[p[i]] = i;
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
f0[i][j] = f0[i][j-1] + (1ll*j*(j-1)/2 - sum[j] == 0),
f1[i][j] = f1[i][j-1] + (1ll*j*(j-1)/2 - sum[j] == 1),
f_1[i][j] = f_1[i][j-1] + (1ll*j*(j-1)/2 - sum[j] == -1);
// printf("%d\n", f0[1][n]);
mint ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j < i; j++) {
// printf("(%d,%d) ---------\n", i, j);
int x = i, y = j;
if (out[x] > out[y]) swap(x, y);
int res = f0[1][n];
// printf("(%d,%d) %d %d\n", x, y, out[x], out[y]);
if (e[x][y]) {
printf("opt=1\n");
res -= f0[L[out[x]]][R[out[y]]-1];
res += f_1[L[out[x]]][R[out[y]]-1];
} else {
// printf("opt=2\n");
if (out[x] + 1 != out[y]) {
// printf("%d %d\n", out[x], out[y]);
res -= f0[R[out[x]]][L[out[y]]-1];
res += f1[R[out[x]]][L[out[y]]-1];
}
}
// printf("res=%d\n", res);
ans += qpow[(i-2)*(i-1)/2+j-1] * res;
}
cout << ans << '\n';
}
cerr << (clock()-_st)/CLOCKS_PER_SEC << 's';
return 0;
}
/*
g++ _1.cpp -o _1 -O2 -std=c++11 -DLOCAL; ./_1.exe
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 105832kb
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:
opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 opt=1 ...
result:
wrong output format Expected integer, but "opt=1" found
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%