QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298828#559. 原力DanielDingDang30 150ms15640kbC++141.6kb2024-01-06 15:01:452024-01-06 15:01:45

Judging History

This is the latest submission verdict.

  • [2024-01-06 15:01:45]
  • Judged
  • Verdict: 30
  • Time: 150ms
  • Memory: 15640kb
  • [2024-01-06 15:01:45]
  • Submitted

answer

#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

typedef long long LL;

const int N = 50010, M = 200010, mod = 1000000007;

int n, m;
int h[N], w[M], e[M], ne[M], tp[M], idx;
int d[N], a[N];
int cnt;
bool st[N];
map<int, LL> dis[N][3];

inline void add(int a, int b, int c, int d)
{
	e[idx] = b, w[idx] = c, tp[idx] = d;
	ne[idx] = h[a], h[a] = idx ++ ;
}

int main()
{
	scanf("%d%d", &n, &m);
	int S = sqrt(n);
	for (int i = 1; i <= m; i ++ )
	{
		int x, y, z, typ;
		char op[5];
		scanf("%d%d%d%s", &x, &y, &z, op);
		if (*op == 'R') typ = 0;
		else if (*op == 'G') typ = 1;
		else typ = 2;
		dis[x][typ][y] += z, dis[y][typ][x] += z;
		add(x, y, z, typ);
		add(y, x, z, typ);
		d[x] ++ , d[y] ++ ;
	}
	
	LL ans = 0;
	for (int i = 1; i <= n; i ++ )
		if (d[i] > S) a[ ++ cnt] = i;
	
	for (int i = 1; i <= cnt; i ++ )
	{
		int x = a[i];
		for (int j = 1; j <= cnt; j ++ )
			if (dis[x][0][a[j]])
			{
				int y = a[j];
				LL t1 = dis[x][0][y];
				for (int k = 1; k <= cnt; k ++ )
					if (dis[y][1][a[k]])
					{
						int z = a[k];
						ans = (ans + t1 * dis[y][1][z] % mod * dis[z][2][x]) % mod;
					}
			}
	}
	
	for (int x = 1; x <= n; x ++ )
		if (d[x] <= S)
		{
			st[x] = true;
			for (int i = h[x]; ~i; i = ne[i])
			{
				int j = e[i];
				if (!st[j])
				{
					LL t = w[i];
					for (int k = ne[i]; ~k; k = ne[k])
					{
						int v = e[k];
						if (!st[v] && tp[i] != tp[k] && j != v)
							ans = (ans + t * w[j] % mod * dis[j][3 - tp[i] - tp[k]][v]) % mod; 
					}
				}
			}
		}
	
	printf("%lld\n", ans);
	return 0;
}

详细

Test #1:

score: 10
Accepted
time: 3ms
memory: 12108kb

input:

85 1024
26 70 3 B
75 47 7 G
23 81 7 R
70 68 7 B
51 26 9 R
41 72 8 R
31 46 2 G
82 7 5 G
6 15 2 B
50 44 4 R
41 17 3 G
58 41 8 B
82 22 4 R
9 39 8 B
54 61 7 R
23 29 6 G
68 52 5 R
28 57 7 G
36 39 4 G
74 83 2 B
58 14 4 G
30 39 1 R
38 76 5 G
19 8 3 R
36 48 5 B
71 76 4 B
33 65 8 R
53 81 10 B
28 72 8 G
21 52...

output:

90693

result:

ok 1 number(s): "90693"

Test #2:

score: 10
Accepted
time: 68ms
memory: 12904kb

input:

95 16384
73 45 5 B
57 95 31 G
52 94 52 R
54 45 98 G
81 40 96 R
37 1 15 R
81 91 13 B
66 4 81 B
89 93 43 R
40 23 27 G
30 68 24 G
85 32 98 G
82 86 21 B
24 18 39 R
60 39 29 R
62 74 32 B
77 15 59 R
77 13 59 G
10 53 98 R
24 32 99 G
80 70 52 R
77 49 29 G
19 76 88 G
25 2 55 B
61 92 18 B
44 50 53 R
70 75 1 B...

output:

34773089

result:

ok 1 number(s): "34773089"

Test #3:

score: 10
Accepted
time: 150ms
memory: 15640kb

input:

99 100000
14 25 53839 G
6 22 555681 G
14 58 127533 B
93 30 685857 G
86 68 720946 G
14 59 657691 B
40 57 159703 R
59 83 309777 G
7 99 151251 B
57 77 769566 G
11 4 406698 R
14 60 739074 G
18 51 934158 R
39 14 237859 B
59 70 810047 G
14 35 733152 R
38 19 549269 R
37 79 413532 B
87 7 30363 B
83 7 795910...

output:

300572702

result:

ok 1 number(s): "300572702"

Test #4:

score: 0
Time Limit Exceeded

input:

4999 50000
3515 625 2 G
1458 3602 1 G
2400 3744 8 R
625 4677 10 G
3602 4385 5 B
4716 2535 7 B
1057 1829 7 R
3691 3073 7 R
1583 1852 7 G
4427 153 10 G
4774 1298 6 R
836 2610 3 G
2022 2207 4 G
3481 4450 6 R
1477 3602 3 G
2399 4851 7 G
3073 3532 9 G
795 2764 9 B
3053 2908 6 G
3979 3239 8 R
4877 863 4 G...

output:


result:


Test #5:

score: 0
Time Limit Exceeded

input:

9999 50000
8342 1822 1 R
2454 7542 91 R
4747 6417 54 G
6114 790 56 G
2423 3828 71 G
9534 6417 66 G
6907 9508 93 B
7593 2449 100 B
7037 6417 73 B
8149 1505 10 G
728 5819 91 R
6417 5132 58 B
8046 5108 25 G
9320 4005 13 G
2577 6417 92 G
1154 5596 45 B
3115 8046 61 G
6417 3191 14 B
6417 2556 92 R
6417 6...

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

39999 50000
711 20333 781142 R
23113 14256 146398 G
36974 20333 525277 R
36111 33004 752115 B
8782 20662 280729 G
25188 9984 379947 B
20333 35283 24241 R
29867 20333 316858 G
17063 20333 204821 B
32466 11296 757600 G
18780 39492 833820 R
20333 32132 963038 G
6250 38375 764880 R
11296 35435 774020 G
...

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

20000 100000
16355 4798 940 G
13008 13907 349 G
4798 17727 621 R
13008 5194 836 G
13008 18776 111 G
4739 13008 599 B
4798 7237 850 G
13008 6737 228 G
13008 14079 199 B
2532 208 645 B
4798 15196 267 B
8734 18039 668 G
17823 17093 141 G
16325 15294 171 R
13008 15936 950 G
13806 13008 855 R
4104 11188 ...

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

30000 100000
3757 12254 1505 B
7935 28786 71 B
15119 2468 960 G
12418 15335 468 G
3378 220 534 B
14160 5855 494 B
20502 10202 284 G
1655 11330 36 R
11744 14165 388 R
10444 6281 1463 R
18863 14050 847 G
5311 511 1317 B
6734 75 1224 B
21061 7652 1846 R
22703 14160 1073 B
11890 6592 1002 B
25235 21600 ...

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

40000 100000
677 7952 47133 B
26245 25217 20330 B
27073 5097 79391 B
24358 23616 90279 G
32570 33531 95478 B
11357 21106 34680 R
11974 27868 17701 R
12937 16890 53472 G
6967 7513 35198 G
27987 11357 58966 B
35641 7203 95467 G
11357 19348 86505 R
27597 34548 53863 R
31334 11357 28148 G
11303 23560 83...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

50000 100000
6823 20867 761119 R
15633 41381 594787 G
15521 17722 827117 B
22016 5255 111472 G
33162 21404 102291 G
20232 39357 226738 G
31698 23330 668274 R
41381 11664 404107 B
4517 4277 115972 B
185 719 279579 G
16463 47896 310079 B
3434 32893 16111 B
44769 6560 943760 G
44874 41381 183542 B
1996...

output:


result: