QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649101#5407. 基础图论练习题ddxrS0 6ms4376kbC++141.7kb2024-10-17 21:37:082024-10-17 21:37:09

Judging History

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

  • [2024-10-17 21:37:09]
  • 评测
  • 测评结果:0
  • 用时:6ms
  • 内存:4376kb
  • [2024-10-17 21:37:08]
  • 提交

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];
		if(sum[i] == p) cnt1[i] = cnt1[i - 1] + 1;
		else if(sum[i] - 1 == p) cnt2[i] = cnt2[i - 1] + 1;
	} 
	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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 4376kb

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
249478223
372704292
205
0
7359
2
140046316
274726919
451356899
196152
2
171266846
220
14892539
4541
0
764279207
239880604
16983811
243844
146149
14859530
394935724
317960730
225522696
369384022
522465179
340022
298552802
891887445
196602
31195129
240650340
718425409
252
252
241
14680057...

result:

wrong answer 3rd numbers differ - expected: '285212672', found: '249478223'

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%