QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425310#5029. 在路上Estelle_N2 820ms52972kbC++144.6kb2024-05-30 08:21:232024-05-30 08:21:24

Judging History

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

  • [2024-05-30 08:21:24]
  • 评测
  • 测评结果:2
  • 用时:820ms
  • 内存:52972kb
  • [2024-05-30 08:21:23]
  • 提交

answer

#include "path.h"
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int N = 300005;

int n, cnt, tot, a[N], b[N], p[N], q[N];

int solve(int x, int y)
{
    // printf("%d %d\n", x, y);
	cnt = tot = 0;
	for(int i = 1; i <= n; ++ i)
		b[i] = 0;

    for(int i = 1; i <= n; ++ i)
	{
		if(i == x || i == y)
			continue;
		if(a[i] == 0)
			p[++cnt] = i;
		if(a[i] == 1)
            p[++cnt] = i, q[++tot] = i;
	}

	if(!cnt) 
		return -1;

	int z = p[rand() % cnt + 1], u, v = x, w = y;
	for(int i = 1; i <= tot; ++ i)
	{
		if(q[i] == z)
			u = q[i];
		else
		{
			int t1 = ask(z, q[i], v), t2 = ask(z, q[i], w);
			if(t1 == q[i] && t2 == q[i])
				u = q[i];
			else if(t1 == q[i])
				v = q[i];
			else if(t2 == q[i])
				w = q[i];
		}
	}

	int s1 = 1, s2 = 1;
	for(int i = 1; i <= n; ++ i)
    {
		if(i == u)
			continue;
        if(a[i] == 2)
        {
            ++ s1;
            b[i] = 2;
            continue;
        }
        if(a[i] == 3)
        {
            ++ s2;
            b[i] = 3;
            continue;
        }
        if(i == v)
        {
            b[i] = 4;
            continue;
        }
        if(i == w)
        {
            b[i] = 5;
            continue;
        }
        int t1 = ask(i, v, u), t2 = ask(i, w, u);
        if(t1 == v && a[i] == 1)
        {
            ++ s1;
            b[i] = 4;
            continue;
        }
        if(t2 == w && a[i] == 1)
        {
            ++ s2;
            b[i] = 5;
            continue;
        }
        if(t1 == v && a[i] == 0)
        {
            ++ s1;
            b[i] = 6;
            continue;
        }
        if(t2 == w && a[i] == 0)
        {
            ++ s2;
            b[i] = 7;
            continue;
        }
        b[i] = 1;
    }

	if(s1 > n / 2)
	{
        for(int i = 1; i <= n; ++ i)
        {
            if(b[i] == 2)
                a[i] = 2;
            else if(b[i] == 4)
                a[i] = 1;
            else if(b[i] == 6)
                a[i] = 0;
            else
                a[i] = 3;
        }
        a[x] = a[u] = 0;
		return solve(x, u);
	}

	if(s2 > n / 2)
	{
        for(int i = 1; i <= n; ++ i)
        {
            if(b[i] == 3)
                a[i] = 3;
            else if(b[i] == 5)
                a[i] = 1;
            else if(b[i] == 7)
                a[i] = 0;
            else
                a[i] = 2;
        }
        a[u] = a[y] = 0;
		return solve(u, y);
	}

	if(n - s1 - s2 - 1 <= n / 2)
		return u;
	
	int sum = 0, k = 0;
	b[v] = b[w] = 1;
	for(int i = 1; i <= n; ++ i)
	{
		if(b[i] != 1 || i == u)
			continue;
		if(sum == 0)
			k = i, ++ sum;
		else
		{
			if(ask(i, u, k) != u)
				++ sum;
			else
				-- sum;
		}
	}

	sum = 1;
	for(int i = 1; i <= n; ++ i)
		if(b[i] == 1 && i != u && i != k && ask(i, u, k) != u)
			++ sum;
	
	if(sum > n / 2)
		return -1;

	return u;
}

int solveChain()
{
	for(int i = 1; i <= n; ++ i)	
		a[i] = 0;
	p[1] = 1;
	p[2] = 2;
	for(int i = 3; i <= n; ++ i)
	{
		p[3] = i;
		int u = ask(p[1], p[2], p[3]);
		if(u == p[1])
			p[1] = p[3];
		else if(u == p[2])
			p[2] = p[3];
	}

	int u = p[1];
	// printf("%d\n", u);
	for(int i = 1; i <= n; ++ i)
	{
		for(int j = i + 1; j <= n; ++ j)
		{
			if(i != j && i != u && j != u)
			{
				if(ask(u, i, j) == i)
					++ a[j];
				else
					++ a[i];
			}
		}
		if(a[i] + 1 == n / 2)
			return i;
	}
}

int centroid(int id, int N, int M)
{
	n = N;
	if(id == 1)
		return ask(1, 2, 3);
	if(id == 3 || id == 5)
		return solveChain();

	// int x = rand() % n + 1, y = rand() % n + 1;
	// while(x == y)
	// 	y = rand() % n + 1;
    
	// for(int i = 1; i <= n; ++ i)
	// {
	// 	a[i] = 0;
	// 	if(i == x || i == y)
	// 		continue;
	// 	int u = ask(i, x, y);
	// 	if(u == 0)
	// 		a[i] = 0;
	// 	else if(u == i)
	// 		a[i] = 1;
	// 	else if(u == x)	
	// 		a[i] = 2;
	// 	else
	// 		a[i] = 3;
	// }

	// int u = solve(x, y);
	// while(u == -1)
	// {
	// 	x = rand() % n + 1;
	// 	y = rand() % n + 1;
	// 	while(x == y)
	// 		y = rand() % n + 1;
            
    //     for(int i = 1; i <= n; ++ i)
    //     {
	// 		a[i] = 0;
    //         if(i == x || i == y)
    //             continue;
    //         int u = ask(i, x, y);
    //         if(u == 0)
    //             a[i] = 0;
    //         else if(u == i)
    //             a[i] = 1;
    //         else if(u == x)	
    //             a[i] = 2;
    //         else
    //             a[i] = 3;
    //     }
	// 	u = solve(x, y);
	// }

	// // printf("%d\n", u);
	// return u;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

score: 2
Accepted
time: 0ms
memory: 14008kb

input:

1 100 100
3
1 2
3
1 2
3
3 1
3
1 2
3
1 2
3
3 1
3
1 2
3
3 1
3
1 2
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
3 1
3
3 1
3
1 2
3
1 2
3
1 2
3
1 2
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
1 2
3
3 1
3
3 1
3
3 1
3
...

result:

ok correct

Subtask #2:

score: 0
Runtime Error

Test #2:

score: 8
Accepted
time: 55ms
memory: 18212kb

input:

2 10 10000000
999
60 112 98 509 586 175 588 875 861 516 920 370 781 249 999 649 292 308 934 949 437 92 506 752 547 866 869 510 984 228 104 612 202 630 360 809 56 107 566 448 940 726 146 299 941 50 319 794 670 603 365 492 728 872 829 942 451 632 373 106 909 25 306 995 735 99 568 673 75 573 383 407 56...

result:

ok correct

Test #3:

score: 0
Accepted
time: 58ms
memory: 16260kb

input:

2 10 10000000
999
60 112 98 509 586 175 588 875 861 516 920 370 781 249 999 649 292 308 934 949 437 92 506 752 547 866 869 510 984 228 104 612 202 630 360 809 56 107 566 448 940 726 146 299 941 50 319 794 670 603 365 492 728 872 829 942 451 632 373 106 909 25 306 995 735 99 568 673 75 573 383 407 56...

result:

ok correct

Test #4:

score: -8
Runtime Error

input:

2 10 10000000
999
60 112 959 68 586 835 91 836 634 516 272 912 781 249 655 11 466 103 934 816 904 92 576 83 687 435 871 510 758 519 842 882 339 221 2 917 5 605 477 448 323 723 744 494 941 50 668 751 670 336 365 95 877 159 829 957 451 632 591 616 909 83 452 607 735 99 22 570 755 354 172 711 742 870 3...

result:


Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 148ms
memory: 18032kb

input:

3 100 10000000
999
328 852 537 953 554 506 483 192 443 912 989 346 935 232 652 528 261 899 131 531 81 686 815 543 991 810 576 639 670 572 604 842 546 322 916 97 510 160 238 696 882 214 212 194 102 964 719 255 416 260 687 148 225 664 105 100 913 600 921 203 571 406 752 189 929 716 523 809 666 589 235...

result:

wrong answer too many queries

Subtask #4:

score: 0
Wrong Answer

Test #27:

score: 0
Wrong Answer
time: 150ms
memory: 14008kb

input:

4 100 10000000
999
710 227 715 954 623 585 538 236 363 913 540 3 897 998 726 919 976 843 796 69 415 705 647 707 201 696 993 545 325 375 47 260 490 385 828 162 29 278 867 593 395 219 178 518 999 685 307 772 224 187 557 89 575 524 1 157 230 341 708 978 473 995 15 179 743 416 263 640 4 851 520 719 679 ...

result:

wrong answer too many queries

Subtask #5:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 421ms
memory: 52972kb

input:

5 100 25000000
49999
3753 28650 36024 8322 47241 9061 43764 6338 45160 16765 40294 43358 37214 37535 38561 1997 7478 9543 11661 1953 7391 41171 43559 9981 24218 13155 22152 45216 30123 1843 20703 23601 42707 6449 40356 3761 32284 34584 32674 44391 41031 324 14845 6935 37071 38330 48041 1824 41182 46...

result:

wrong answer too many queries

Subtask #6:

score: 0
Wrong Answer

Test #52:

score: 0
Wrong Answer
time: 639ms
memory: 19296kb

input:

6 100 40000000
9999
3929 7460 4617 7377 498 7572 4628 3661 2404 9179 755 4076 8531 6581 1929 9419 1498 4402 6412 712 4918 2628 798 6283 9427 9775 1472 5554 2146 9972 5228 5459 8417 6778 3121 7649 1031 7691 6270 2238 4885 6121 2099 3435 4615 9962 6384 8809 9169 4553 66 1939 8589 2029 4897 7334 2867 8...

result:

wrong answer too many queries

Subtask #7:

score: 0
Wrong Answer

Test #72:

score: 0
Wrong Answer
time: 681ms
memory: 29216kb

input:

7 50 40000000
29999
12447 18709 13054 17585 8337 14953 7985 1930 24383 1787 2543 26860 12198 2842 14256 8665 17034 6429 14773 8646 27093 6362 29357 18001 10667 8445 6671 21435 27163 14604 19875 745 20772 6696 16391 15560 16789 10983 6199 23133 13 13688 14547 8390 4398 21653 14460 690 24385 5358 2213...

result:

wrong answer too many queries

Subtask #8:

score: 0
Wrong Answer

Test #92:

score: 0
Wrong Answer
time: 820ms
memory: 39036kb

input:

8 100 50000000
29999
8375 16777 16700 20953 11899 14682 20874 25860 28858 23241 5089 8044 25448 17746 5605 3087 9145 20179 1080 22944 27383 8384 19943 15371 27572 7882 23028 10474 18744 20202 15687 17001 7543 18709 23165 15713 17032 29011 22353 17455 26045 3484 20330 15159 21274 382 23927 20114 6303...

result:

wrong answer too many queries