QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155674#7119. Longest Tripbulijiojiodibuliduo#Compile Error//C++172.7kb2023-09-02 00:16:042024-04-28 07:41:34

Judging History

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

  • [2024-04-28 07:41:34]
  • 管理员手动重测本题所有提交记录
  • [2023-09-02 00:16:04]
  • 评测
  • [2023-09-02 00:16:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(1); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

vector<int> longest_trip(int n, int D) {
    VI ch;
    vector<set<int>> notc(n);
    VI ord(n);
    iota(all(ord),0);
    shuffle(all(ord),mrand);
    map<PII,bool> cache;
    auto query=[&](int u,int v) {
        u=ord[u]; v=ord[v];
        if (cache.count(mp(u,v))) return cache[mp(u,v)];
        bool w=are_connected(VI{u},VI{v});
        //printf("cnm %d %d %d\n",u,v,w);
        if (!w) notc[u].insert(v),notc[v].insert(u);
        return cache[mp(u,v)]=cache[mp(v,u)]=w;
    };
    VI unv;
    //puts("??");
    rep(i,0,3) rep(j,i+1,3) if (query(i,j)) {
        ch.pb(i); ch.pb(j);
        rep(k,0,n) if (k!=i&&k!=j) unv.pb(k);
        goto init;
    }
    assert(0);
    //puts("???");
    init:;
    shuffle(all(unv),mrand);
    for (auto w:unv) {
        //for (auto x:ch) printf("%d ",x); puts("ch!");
        if (rnd(2)) reverse(all(ch));
        int u=ch[0],v=ch[SZ(ch)-1];
        if (query(v,w)) {
            ch.pb(w); continue;
        } else if (query(u,w)) {
            ch.insert(ch.begin(),w); continue;
        } else {
            cache[mp(u,v)]=cache[mp(v,u)]=true;
            int md=-1;
            for (auto x:notc[u]) if (x!=v&&x!=u&&x!=w) md=x;
            for (auto x:notc[v]) if (x!=v&&x!=u&&x!=w) md=x;
            if (md==-1) {
                int l=0,r=SZ(ch)-2;
                while (l+1<r) {
                    int mid=(l+r)>>1;
                    VI ww(ch.begin(),ch.begin()+mid+1);
                    if (are_connected(VI{w},ww)) {
                        r=mid;
                    } else {
                        l=mid;
                        for (auto vv:ww) {
                            cache[mp(w,vv)]=cache[mp(vv,w)]=true;
                            notc[w].insert(vv);
                            notc[vv].insert(w);
                        }
                    }
                }
                md=ch[r];
            }
            cache[mp(w,md)]=cache[mp(md,w)]=true;
            rotate(ch.begin(),find(all(ch),w),ch.end());
            ch.insert(ch.begin(),w);
        }
    }
    return ch;
}

Details

answer.code: In lambda function:
answer.code:34:16: error: ‘are_connected’ was not declared in this scope
   34 |         bool w=are_connected(VI{u},VI{v});
      |                ^~~~~~~~~~~~~
answer.code: In function ‘std::vector<int> longest_trip(int, int)’:
answer.code:68:25: error: ‘are_connected’ was not declared in this scope
   68 |                     if (are_connected(VI{w},ww)) {
      |                         ^~~~~~~~~~~~~