QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103781#6397. Master of Both IIIskyline#WA 572ms21416kbC++172.0kb2023-05-07 15:33:252023-05-07 15:33:27

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-07 15:33:27]
  • 评测
  • 测评结果:WA
  • 用时:572ms
  • 内存:21416kb
  • [2023-05-07 15:33:25]
  • 提交

answer

#include<bits/stdc++.h>
#define ll   long long
#define pb   emplace_back
#define mp   make_pair
#define orz  1000000007
#define fi   first
#define se   second
#pragma GCC optimize("O2")
typedef unsigned int uint;
typedef long long int int64;
typedef long long unsigned int uint64;



constexpr uint Max_N = 4200005;

int64 Dist[Max_N];

struct A_Wonderful_Heap
{
	int size;
	int cur[Max_N];
	int val[Max_N * 2];
	
	void _set(const int i, const int x)
	{
		val[i] = x, cur[x] = i;
	}
	
	int _min(const int x, const int y)
	{
		return Dist[x] < Dist[y] ? x : y;
	}
	
	void _update(int i, int flag = 0)
	{
		const int x = val[i];
		const int64 d = Dist[x];
		while ((i >>= 1) && Dist[val[i]] >= d)
			val[i] = x;
	}
	
	void insert(int x)
	{
		_set(size * 2 + 1, x);
		if (size)
			_set(size * 2, val[size]), _update(size * 2 + 1, 1);
		++size;
	}
	
	void decrease(int x)
	{
		_update(cur[x]);
	}
	
	void erase()
	{
		int i = cur[val[1]];
		if (--size)
		{
			if ((i >> 1) == size)
				_set(size, val[i ^ 1]), i = size;
			else
				_set(i, val[size] != val[size * 2] ? val[size * 2] : val[size * 2 + 1]), cur[val[size]] = size;
			for (int x; i != 1; val[i >>= 1] = x)
				x = _min(val[i], val[i ^ 1]);
		}
	}
	
	int top()
	{
		return val[1];
	}
};
A_Wonderful_Heap pq;

int n;
int64 w[25];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i)scanf("%lld",w+i);
	pq.insert(1);
	while(pq.size){
		int _=pq.top();
		int64 d=Dist[_];
		pq.erase();
		for(int i=0;i<n;++i)if(_&(1<<i)){
			int __=_^(1<<i);
			if(pq.cur[__]==0){
				Dist[__]=d;
				pq.insert(__);
			}
			else if(Dist[__]>d){
				Dist[__]=d;
				pq.decrease(__);
			}
		}
		int ___=_;
		for(int i=1;i<n;++i){
			if(___&1)___|=(1<<n);
			___>>=1;
			int __=___|_;
			if(pq.cur[__]==0){
				Dist[__]=d+w[i];
				pq.insert(__);
			}
			else if(Dist[__]>d+w[i]){
				Dist[__]=d+w[i];
				pq.decrease(__);
			}
		}
	}
	int64 ans=0;
	for(int _=1;_<(1<<n);++_)ans+=Dist[_]*_;
	printf("%lld\n",ans%998244353);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 5544kb

input:

3
2 1 2

output:

45

result:

ok 1 number(s): "45"

Test #2:

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

input:

4
1919810 999999998 999999997 114114514

output:

152175989

result:

ok 1 number(s): "152175989"

Test #3:

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

input:

3
842160586 705327547 868243944

output:

78597628

result:

ok 1 number(s): "78597628"

Test #4:

score: 0
Accepted
time: 3ms
memory: 5592kb

input:

5
198327434 147392532 760837755 771109105 676721155

output:

751568230

result:

ok 1 number(s): "751568230"

Test #5:

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

input:

10
831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703

output:

308170104

result:

ok 1 number(s): "308170104"

Test #6:

score: 0
Accepted
time: 0ms
memory: 5824kb

input:

12
892965903 35291219 261557729 131390943 457251874 944586973 724767219 190756777 658923976 587806068 793999675 378390067

output:

964920873

result:

ok 1 number(s): "964920873"

Test #7:

score: 0
Accepted
time: 5ms
memory: 5712kb

input:

14
249132751 477356204 594343028 32906794 270726189 883801423 329535378 877124753 100792287 152414432 142520554 196476850 924736849 383197276

output:

796031217

result:

ok 1 number(s): "796031217"

Test #8:

score: -100
Wrong Answer
time: 572ms
memory: 21416kb

input:

20
627365465 726842612 947302944 649244156 293375951 318148820 237155023 981487641 688151803 844901013 430309799 733877736 520864483 720366437 28746495 143052089 306590290 18586578 662663479 375430013

output:

-289300055

result:

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