QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649129 | #5407. 基础图论练习题 | lifan | 0 | 12ms | 4336kb | C++14 | 1.7kb | 2024-10-17 21:45:34 | 2024-10-17 21:45:35 |
Judging History
answer
//
/*
由兰道定理得,竞赛图的强连通分量个数为 $\sum_{i=1}^{n}[\sum_{j=1}^i out_j=C(i,2)]$。
每次反转一条边可以做到 O(1) 修改。
*/
#include<bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;
const int N = 5005;
const ll mod = 1e9 + 7;
bool flg[N][N];
int n;
char s[N];
int out[N], sum[N], nxt[N];
int cnt1[N], cnt2[N];
int turn(char x) {return (x >= '0' && x <= '9' ? (x - '0') : (10 + (x - 'A')));}
void solve() {
scanf("%lld", &n);
for(int i = 1; i <= n; i++) out[i] = 0;
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) flg[i][j] = false;
for(int i = 2, l; i <= n; i++) { l = (i - 1) / 4 + 1;
cin>>(s + 1);
for(int j = 1; j <= l; j++) for(int k = 4 * j - 3, x = turn(s[j]); k <= 4 * j && k < i; k++, x >>= 1)
if(x & 1) flg[i][k] = true, flg[k][i] = false, out[i]++;
else flg[k][i] = true, flg[i][k] = false, out[k]++;
}
for(int i = 1; i <= n; i++) sum[i] = out[i], nxt[i] = 0;
for(int i = 1; i <= n; i++) nxt[sum[i]]++;
sort(sum + 1, sum + n + 1);
for(int i = 1; i <= n; i++) nxt[i] += nxt[i - 1];
for(int i = 1; i <= n; i++) {
int p = i * (i - 1) / 2; sum[i] += sum[i - 1];
cnt1[i] = cnt1[i - 1], cnt2[i] = cnt2[i - 1];
if(sum[i] == p) cnt1[i]++;
else if(sum[i] - 1 == p) cnt2[i]++;
}
ll ans = 0;
for(int i = n; i >= 1; i--) for(int j = i - 1; j >= 1; j--) {
int sum = cnt1[n], x = i, y = j;
if(flg[x][y]) swap(x, y);
if(out[x] >= out[y]) sum += (cnt2[nxt[out[x]] - 1] - cnt2[nxt[out[y] - 1]]);
if(out[x] + 1 < out[y]) sum -= (cnt1[nxt[out[y] - 1]] - cnt1[nxt[out[x]] - 1]);
ans = (ans * 2 + sum) % mod;
}
printf("%lld\n", ans);
}
signed main() {
int t; cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 4336kb
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 266795052 371842543 67 0 7359 2 274305004 266338303 901107579 28174 2 699555017 63 1447744 2726 0 482956837 371842543 2093940 34687 7466 4262014 360656728 308924428 989705702 923440739 718165604 86033 285220919 542113286 32032 3899391 624478288 371842543 63 63 115 2097151 268435455 25 4...
result:
wrong answer 3rd numbers differ - expected: '285212672', found: '266795052'
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%