Submission #245850

# Submission time Handle Problem Language Result Execution time Memory
245850 2020-07-07T15:16:12 Z LittleFlowers__ Simurgh (IOI17_simurgh) C++17
30 / 100
265 ms 3964 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define gg exit(0);

#include "simurgh.h"


const int N=510;

int mode,it,asked=1;
int dd[N],fa[N],st[N],ed[N];
int id[N][N];
int asking[1000000];
int yes[1000000];
int no[1000000];
int tested[1000000];
vector<int> ask;
vector<int> ad[N];

void dfs(int u){
    st[u]=++it;
    dd[u]=1;
    //cerr<<u<<" "<<fa[u]<<"\n";
    forv(v,ad[u]){
        if(!dd[v]){
            if(mode && !asking[id[u][v]]) continue;
            if(!mode){
                ask.push_back(id[u][v]);
                asking[id[u][v]]=1;
            }
            fa[v]=u;
            dfs(v);
        }
    }
    ed[u]=it;
}

int anc(int u,int v){
    return st[u]<=st[v] && ed[u]>=ed[v];
}

vector<int> find_roads(int n,vector<int> u,vector<int> v){
    int m=u.size();
    forinc(i,0,m-1){
        ad[u[i]].pb(v[i]);
        ad[v[i]].pb(u[i]);
        id[u[i]][v[i]]=id[v[i]][u[i]]=i;
    }
    forinc(i,0,n-1){
        //shuffle(all(ad[i]),rng);
    }
    dfs(0);
    //cerr<<"\n";
    int tmp=count_common_roads(ask);
    if(tmp==n-1) return ask;

    vector<int> pos;
    forinc(i,0,m-1) if(!asking[i])
        pos.push_back(i);

    mode=1;
    int tot=0;
    vector<int> eq;
    auto tim=[&](int i,int rep){
        if(no[i]) return 1;
        if(yes[rep]){
            //if(tested[i])
                //return 0;
            //tested[i]=1;
        }
        int suc=0;
        if(yes[rep] || no[i]) suc=1;
        int j=0; while(ask[j]!=rep) j++;
        ask[j]=i;
        asked++;
        //if(asked>30000) gg
        int to=count_common_roads(ask);
        if(to>tmp){
            tmp=to;
            asking[rep]=0;
            no[rep]=yes[i]=asking[i]=1;
            tot++;
            reset(dd,0);
            dfs(it=0);
            return 1;
        }
        ask[j]=rep;
        if(to<tmp){
            no[i]=yes[rep]=1;
            return 1;
        }
        eq.push_back(rep);
        if(no[rep]){
            yes[i]=0;
            no[i]=1;
        }
        return no[rep];
    };
    forv(i,pos){
        int x=u[i], y=v[i], found=0;
        while(!anc(x,y)){
            int rep=id[x][fa[x]];
            if(tim(i,rep)){
                found=1;
                break;
            }
            x=fa[x];
        }
        while(y!=x && !found){
            int rep=id[y][fa[y]];
            if(tim(i,rep)) break;
            y=fa[y];
        }
        if(no[i])
        forv(j,eq){
            no[j]=1;
            yes[j]=0;
        }
        eq.clear();
    }
    cerr<<asked<<"\n";
    return ask;
}

Compilation message

simurgh.cpp: In lambda function:
simurgh.cpp:85:13: warning: variable 'suc' set but not used [-Wunused-but-set-variable]
         int suc=0;
             ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB correct
2 Correct 5 ms 384 KB correct
3 Correct 5 ms 384 KB correct
4 Correct 5 ms 384 KB correct
5 Correct 5 ms 384 KB correct
6 Correct 5 ms 384 KB correct
7 Correct 5 ms 384 KB correct
8 Correct 4 ms 384 KB correct
9 Correct 4 ms 384 KB correct
10 Correct 4 ms 384 KB correct
11 Correct 4 ms 384 KB correct
12 Correct 5 ms 384 KB correct
13 Correct 5 ms 384 KB correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB correct
2 Correct 5 ms 384 KB correct
3 Correct 5 ms 384 KB correct
4 Correct 5 ms 384 KB correct
5 Correct 5 ms 384 KB correct
6 Correct 5 ms 384 KB correct
7 Correct 5 ms 384 KB correct
8 Correct 4 ms 384 KB correct
9 Correct 4 ms 384 KB correct
10 Correct 4 ms 384 KB correct
11 Correct 4 ms 384 KB correct
12 Correct 5 ms 384 KB correct
13 Correct 5 ms 384 KB correct
14 Correct 7 ms 512 KB correct
15 Correct 7 ms 512 KB correct
16 Correct 7 ms 564 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 6 ms 512 KB correct
19 Correct 7 ms 512 KB correct
20 Correct 7 ms 512 KB correct
21 Correct 6 ms 512 KB correct
22 Correct 6 ms 512 KB correct
23 Correct 6 ms 512 KB correct
24 Correct 6 ms 512 KB correct
25 Correct 5 ms 512 KB correct
26 Correct 6 ms 512 KB correct
27 Correct 5 ms 512 KB correct
28 Correct 5 ms 512 KB correct
29 Correct 5 ms 512 KB correct
30 Correct 5 ms 512 KB correct
31 Correct 6 ms 512 KB correct
32 Correct 5 ms 512 KB correct
33 Correct 6 ms 512 KB correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB correct
2 Correct 5 ms 384 KB correct
3 Correct 5 ms 384 KB correct
4 Correct 5 ms 384 KB correct
5 Correct 5 ms 384 KB correct
6 Correct 5 ms 384 KB correct
7 Correct 5 ms 384 KB correct
8 Correct 4 ms 384 KB correct
9 Correct 4 ms 384 KB correct
10 Correct 4 ms 384 KB correct
11 Correct 4 ms 384 KB correct
12 Correct 5 ms 384 KB correct
13 Correct 5 ms 384 KB correct
14 Correct 7 ms 512 KB correct
15 Correct 7 ms 512 KB correct
16 Correct 7 ms 564 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 6 ms 512 KB correct
19 Correct 7 ms 512 KB correct
20 Correct 7 ms 512 KB correct
21 Correct 6 ms 512 KB correct
22 Correct 6 ms 512 KB correct
23 Correct 6 ms 512 KB correct
24 Correct 6 ms 512 KB correct
25 Correct 5 ms 512 KB correct
26 Correct 6 ms 512 KB correct
27 Correct 5 ms 512 KB correct
28 Correct 5 ms 512 KB correct
29 Correct 5 ms 512 KB correct
30 Correct 5 ms 512 KB correct
31 Correct 6 ms 512 KB correct
32 Correct 5 ms 512 KB correct
33 Correct 6 ms 512 KB correct
34 Correct 265 ms 2300 KB correct
35 Correct 244 ms 2168 KB correct
36 Correct 173 ms 1912 KB correct
37 Correct 17 ms 896 KB correct
38 Correct 247 ms 2188 KB correct
39 Correct 227 ms 2040 KB correct
40 Correct 175 ms 1912 KB correct
41 Incorrect 214 ms 2040 KB WA in grader: NO
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB correct
2 Correct 5 ms 384 KB correct
3 Incorrect 139 ms 3964 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB correct
2 Correct 5 ms 384 KB correct
3 Correct 5 ms 384 KB correct
4 Correct 5 ms 384 KB correct
5 Correct 5 ms 384 KB correct
6 Correct 5 ms 384 KB correct
7 Correct 5 ms 384 KB correct
8 Correct 4 ms 384 KB correct
9 Correct 4 ms 384 KB correct
10 Correct 4 ms 384 KB correct
11 Correct 4 ms 384 KB correct
12 Correct 5 ms 384 KB correct
13 Correct 5 ms 384 KB correct
14 Correct 7 ms 512 KB correct
15 Correct 7 ms 512 KB correct
16 Correct 7 ms 564 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 6 ms 512 KB correct
19 Correct 7 ms 512 KB correct
20 Correct 7 ms 512 KB correct
21 Correct 6 ms 512 KB correct
22 Correct 6 ms 512 KB correct
23 Correct 6 ms 512 KB correct
24 Correct 6 ms 512 KB correct
25 Correct 5 ms 512 KB correct
26 Correct 6 ms 512 KB correct
27 Correct 5 ms 512 KB correct
28 Correct 5 ms 512 KB correct
29 Correct 5 ms 512 KB correct
30 Correct 5 ms 512 KB correct
31 Correct 6 ms 512 KB correct
32 Correct 5 ms 512 KB correct
33 Correct 6 ms 512 KB correct
34 Correct 265 ms 2300 KB correct
35 Correct 244 ms 2168 KB correct
36 Correct 173 ms 1912 KB correct
37 Correct 17 ms 896 KB correct
38 Correct 247 ms 2188 KB correct
39 Correct 227 ms 2040 KB correct
40 Correct 175 ms 1912 KB correct
41 Incorrect 214 ms 2040 KB WA in grader: NO
42 Halted 0 ms 0 KB -