QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#860873#9678. 网友小 Z 的树XY_Eleven0 3ms10180kbC++234.8kb2025-01-18 15:22:062025-01-18 15:24:33

Judging History

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

  • [2025-01-18 15:24:33]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:10180kb
  • [2025-01-18 15:22:06]
  • 提交

answer

#include <bits/stdc++.h>
#include "diameter.h"
// #include <windows.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<long long,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }

void main_init()
{

}
map <array<int,3>,int> mp;
int qry(vct <int> w)
{
    sort(all(w));
    if(mp.count({w[0],w[1],w[2]})) return mp[{w[0],w[1],w[2]}];
    return (mp[{w[0],w[1],w[2]}]=query(w[0],w[1],w[2]));
}
void operator += (array <int,3> &w1,array <int,3> w2)
{
    vct <int> h={w1[0],w1[1],w1[2],w2[0],w2[1],w2[2]};
    sort(all(h)); h.erase(unique(all(h)));
    int len=sz(h),mx=0;
    For_(i,0,len) For_(j,i+1,len) For_(k,j+1,len)
    {
        int t=qry({h[i],h[j],h[k]});
        if(t>=mx)
            w1={h[i],h[j],h[k]},mx=t;
    }
}
std::pair<int, int> find_diameter(int task_id, int n)
{
    if(n==1) return {1,1};
    if(n==2) return {1,2};
    mp.clear();
    vct <int> a(n);
    For_(i,0,n) a[i]=i+1;
    shuffle(all(a),gen);
    vct <array<int,3> > g;
    for(int i=0;i<n;i+=3)
    {
        if(i+2<n) g.pb({a[i],a[i+1],a[i+2]});
        else g.pb({a[n-1],a[n-2],a[n-3]});
    }
    int m=sz(g);
    For_(i,1,m) g[0]+=g[i];
    auto [w1,w2,w3]=g[0];
    auto dis=[&](int x,int y)->array<int,2>
    {
        array <int,2> mn={n<<2|11,0};
        For(i,1,n) if(i!=x&&i!=y)
            get_min(mn,{qry({x,y,i}),i});
        return mn;
    };
    auto t1=dis(w1,w2),t2=dis(w2,w3),t3=dis(w1,w3),t=max({t1,t2,t3});
    if(t2==t) w1=w3;
    else if(t3==t) w2=w3;
    w3=t[1];
    // printf("%d,%d,%d\n",w1,w2,w3);
    if(in(w1,w2,w3)) return {w2,w3};
    if(in(w2,w1,w3)) return {w1,w3};
    return {w1,w2};
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 10180kb

input:

1 100
25
1 3
2 18
3 8
4 18
5 14
6 22
7 18
8 10
9 11
10 12
11 25
12 16
13 11
14 17
15 17
16 25
17 2
18 20
19 18
20 12
21 1
22 17
23 14
24 1
50
1 37
2 27
3 10
4 25
5 16
6 17
7 10
8 36
9 16
10 6
11 48
12 2
13 28
14 30
15 10
16 44
17 31
18 1
19 6
20 7
21 30
22 42
23 45
24 23
25 27
26 39
27 45
28 48
29 4...

output:

WA

result:

wrong answer Wrong Answer

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #7:

0%

Subtask #9:

score: 0
Skipped

Dependency #8:

0%

Subtask #10:

score: 0
Skipped

Dependency #9:

0%

Subtask #11:

score: 0
Skipped

Dependency #1:

0%