QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107979 | #6406. Stage Clear | 2024zll | WA | 2ms | 3048kb | C++14 | 3.0kb | 2023-05-23 12:44:30 | 2023-05-23 12:44:33 |
Judging History
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[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=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=10;i<=15;i++)fprintf(stderr,"%llu %llu\n",a[i],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: 2ms
memory: 3048kb
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: 2904kb
input:
15 14 254040392438309 117083115436273 500005748229691 557255157630172 821034233718230 865199673774998 659892147898798 987564141425694 81172575487567 811635577877255 751768357864605 341103322647288 454926350150218 140191090713900 921608121471585 659295670987251 223751724062143 505619245326640 8907765...
output:
864142884956647
result:
wrong answer 1st numbers differ - expected: '1665396301509143', found: '864142884956647'