QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#184878#5407. 基础图论练习题YuJiahe0 15ms3644kbC++231.8kb2023-09-21 13:53:512023-09-21 13:53:52

Judging History

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

  • [2023-09-21 13:53:52]
  • 评测
  • 测评结果:0
  • 用时:15ms
  • 内存:3644kb
  • [2023-09-21 13:53:51]
  • 提交

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];
			for (int j = 1;j < i;j ++) printf("%d", to[i][j]);putchar('\n');
		}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: 15ms
memory: 3644kb

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:

1
01
010
0001
00110
111100
0100111
11100001
010101111
0011000010
10101000100
101100011110
0111111101000
11000001111011
010011100010010
1110110010110000
10110011100111010
111111010100010111
1001001100001000100
10011101001001110000
100110101011001100000
0101111011011001000100
11110010110010101100100
0...

result:

wrong answer 1st numbers differ - expected: '281603732', found: '1'

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%