QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#754593#5407. 基础图论练习题HildaHu0 7ms8432kbC++141.5kb2024-11-16 15:22:552024-11-16 15:23:00

Judging History

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

  • [2024-11-16 15:23:00]
  • 评测
  • 测评结果:0
  • 用时:7ms
  • 内存:8432kb
  • [2024-11-16 15:22:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 5010, mod = 1e9 + 7;
int T, n, a[N], d[N], fir[N * N], lst[N * N];
char str[N];
bool mp[N][N];

int s[3][N];
void init() {
	for (int i=1; i<=n; ++i) a[i] = d[i];
	sort(a + 1, a + n + 1);
	for (int i=1; i<=n; ++i) lst[a[i]] = i;
	for (int i=n; i; --i) fir[a[i]] = i;
	for (int i=1; i<=n; ++i) {
		a[i] += a[i - 1];
		int num = i * (i - 1) / 2;
		for (int j=0; j<3; ++j)
			s[j][i] = s[j][i - 1] + (a[i] == num + j - 1);
	}
}
int query(int i, int l, int r) {
	return s[i][r] - s[i][l - 1];
}
int work(int u, int v) {
	if (!mp[u][v]) swap(u, v);
	if (d[u] + 1 == d[v]) return query(1, 1, n);
	int l = lst[d[u]], r = fir[d[v]], sgn = 2;
	if (l > r) swap(l, r), sgn = 0;
	return query(1, 1, l - 1) + query(sgn, l, r - 1) + query(1, r, n);
}

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		for (int i=1; i<=n; ++i) d[i] = 0;
		for (int i=2; i<=n; ++i) {
			scanf("%s", str + 1);
			int len = strlen(str + 1);
			for (int j=1; j<=len; ++j) {
				int num = isdigit(str[j]) ? (str[j] - '0') : (10 + str[j] - 'A');
				for (int k=0; k<=3; ++k) {
					int x = 4 * j + k - 3;
					if (x < i) {
						mp[i][x] = ((num >> k) & 1);
						mp[x][i] = mp[i][x] ^ 1;
						d[x] += mp[i][x], d[i] += mp[x][i];
					}
				}
			}
		}
		init();
		int ans = 0;
		for (int i=n; i; --i)
			for (int j=i-1; j; --j)
				ans = ((ans << 1) + work(i, j)) % mod;
		printf("%d\n", ans);
	}
	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: 7ms
memory: 8432kb

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%