QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107982#6406. Stage Clear2024zllWA 0ms2976kbC++143.1kb2023-05-23 12:50:562023-05-23 12:51:00

Judging History

This is the latest submission verdict.

  • [2024-08-15 21:05:17]
  • hack成功,自动添加数据
  • (/hack/778)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 12:51:00]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 2976kb
  • [2023-05-23 12:50:56]
  • Submitted

answer

#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
namespace IO{
	const int ARR_SIZE=1<<15;
	#define gc() ((IO::si!=IO::ti||(IO::ti=(IO::si=IO::input)+fread(IO::input,1,IO::ARR_SIZE,stdin))),IO::si!=IO::ti?*(IO::si++):EOF)
	char input[ARR_SIZE],*si=input,*ti=input;
	template<typename T>
	void read(T&num){
		int ch=gc();
		num=0;
		while(ch<48||ch>57)ch=gc();
		while(ch>=48&&ch<=57)num=(num<<3)+(num<<1)+(ch^48),ch=gc();
	}
}
using IO::read;
template<typename T>
inline void chkmin(T&a,const T b){
	a>b&&(a=b);
}
typedef unsigned int uint;
typedef unsigned long long ull;
const uint maxn=36,maxm=70;
uint n,m;
ull a[maxn+1],b[maxn+1];
struct Monster{
	uint id;
	bool f;
	ull a,b;
	Monster(){}
	Monster(const uint id,const ull a,const ull b):id(id),f(a>b),a(a),b(b){}
	friend bool operator<(const Monster&X,const Monster&Y){
		if(X.f!=Y.f)return X.f>Y.f;
		if(!X.f)return X.a>Y.a;
		return X.b<Y.b;
	}
}M[maxn+1];
std::priority_queue<Monster>q;
std::vector<uint>G1[maxn+1];
template<const uint maxnode,const uint maxedge>
struct Graph{
	uint head[maxnode+1],total,fa[maxnode+1];
	struct Edge{
		uint to,next;
	}e[maxedge+1];
	void add(const uint u,const uint v){
		fa[v]=u;
		e[++total]=Edge{v,head[u]};
		head[u]=total;
	}
	void clear(){
		memset(head+1,0,sizeof(uint)*n);
		total=0;
	}
};
Graph<maxn,maxn-1>G2;
template<const uint maxsize>
struct DSU{
	uint fa[maxsize+1];
	ull a[maxsize+1],b[maxsize+1];
	void init(const uint n,ull*_a,ull*_b){
		for(uint i=1;i<=n;i++)fa[i]=i;
		memcpy(a+1,_a+1,sizeof(ull)*n);
		memcpy(b+1,_b+1,sizeof(ull)*n);
	}
	uint find(const uint x){
		return x==fa[x]?x:fa[x]=find(fa[x]);
	}
	void merge(uint x,uint y){
		x=find(x),y=find(y);
		if(x==y)return;
		fa[x]=y;
		const uint tmp=a[y]-b[y]+a[x];
		if(a[y]>tmp)b[y]=b[y]-a[x]+b[x];
		else a[y]=tmp,b[y]=b[x];
		a[x]=b[x]=0;
		
		/*
		const uint tmp=a[x]-b[x]+a[y];
		if(a[x]>tmp)b[y]=b[x]-a[y]+b[y],a[y]=a[x];
		else a[y]=tmp;
		a[x]=b[x]=0;
		*/
	}
};
DSU<maxn>dsu;
ull solve_1(){
	dsu.init(n,a,b);
	for(uint i=2;i<=n;i++)q.emplace(i,dsu.a[i],dsu.b[i]);
	while(!q.empty()){
		const Monster u=q.top();
		q.pop();
		if(u.a!=dsu.a[u.id]||u.b!=dsu.b[u.id])continue;
		const uint fa=dsu.find(G2.fa[u.id]);
		dsu.merge(u.id,fa);
		if(fa>1)q.emplace(fa,dsu.a[fa],dsu.b[fa]);
	}
	return dsu.a[1];
}
ull ans=0x7fffffffffffffff;
uint choice[maxn+1];
void dfs(const uint cur){
	if(cur==n+1){
		G2.clear();
		for(uint u=2;u<=n;u++)G2.add(choice[u],u);
		chkmin(ans,solve_1());
		return;
	}
	for(uint i=0;i<G1[cur].size();i++){
		choice[cur]=G1[cur][i];
		dfs(cur+1);
	}
}
void method_1_func(){
	dfs(2);
}
ull f[1<<25];
uint lim;
void method_2_func(){
	
}
int main(){
	read(n),read(m);
	for(uint i=2;i<=n;i++)read(a[i]),read(b[i]);
	for(uint i=1,u,v;i<=m;i++){
		read(u),read(v);
		G1[v].emplace_back(u);
	}
	ull method_1=n,method_2=(ull)n<<n;
	for(uint u=2;u<=n;u++)method_1*=G1[u].size()-1ull;
	method_1*=log2(n);
	if(method_1<method_2||n>26||true)method_1_func();//for debugging
	else method_2_func();
	printf("%llu\n",ans);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 2976kb

input:

4 4
4 2
5 3
2 6
1 2
1 3
2 4
3 4

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 2896kb

input:

15 14
254040392438309 117083115436273
500005748229691 557255157630172
821034233718230 865199673774998
659892147898798 987564141425694
81172575487567 811635577877255
751768357864605 341103322647288
454926350150218 140191090713900
921608121471585 659295670987251
223751724062143 505619245326640
8907765...

output:

3421731263

result:

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