Submission #394191

# Submission time Handle Problem Language Result Execution time Memory
394191 2021-04-26T04:59:22 Z BJoozz Fun Tour (APIO20_fun) C++14
66 / 100
350 ms 20308 KB
#include<bits/stdc++.h>
using namespace std;
#include "fun.h"
#define X first
#define Y second
#define pb push_back
#define getdis hoursRequired
#define getsz attractionsBehind
const int MAX=100005,mod=1e9+7,M=2000,inf=1e9;
void maxx(int &a,int b){if(b>a) a=b;}
using ii = pair < int ,int > ;
void minn(int &a,int b){if(b<a) a=b;}
void maxp(ii &a,ii b){if(b>a) a=b;}
void minp(ii &a,ii b){if(b<a) a=b;}
bool cp(ii &a,ii b){if(b>a) {a=b;return 1;}else return 0;}
void PL(int &a,int b){a+=b;if(a>=mod) a-=mod;}


///+++++++++++++++++++++++++++++
int a[MAX],sz[4],h[MAX];
bool vs[MAX];
int D[4];
short bel[MAX];
int L[4][MAX];
int getdeep(int v){
    ii u = ii (0,0);
    int r;
    for(int i=1;i<=3;i++) if(i!=v && sz[i]!=0)
        if( cp(u,ii(h[L[i][sz[i]]],sz[i])) ) r=i;
    return r;
}
bool cmp(int u,int v){
return h[u]<h[v];}
std::vector<int> createFunTour(int n,int Q){
    vector < int > vec;
    a[0]=n;
    if(n==2){
        vec.pb(0);vec.pb(1);return vec;
    }
    int r=0;
    for(int i=1;i<n;i++){
        a[i]=getsz(0,i);
        if(a[i]>n/2 && a[i]<a[r]) {
            r=i;
        }
    }
    int cn=0;
    for(int i=0;i<n;i++)if(r!=i){
        h[i]=getdis(r,i);
        if(h[i]==1) D[++cn]=i;
    }
    vs[r]=1;
    for(int i=1,u;i<=cn;i++){
        u=D[i];
        bel[u]=i;
        L[i][1]=u;
        vs[u]=1;
        sz[i]=getsz(r,u);
        ///co the toi uu
    }
    int top[4]={1,1,1,1};
    for(int i=0;i<n;i++) if(!vs[i]){
        if(getdis(D[1],i)==h[i]-1){
            bel[i]=1;
        }
        else{
            if(getdis(D[2],i)==h[i]-1)
            bel[i]=2;
            else bel[i]=3;
        }
        L[bel[i]][++top[bel[i]]]=i;
        //cout<<i<<' '<<bel[i]<<'\n';
    }

    for(int i=1;i<=cn;i++){
        sort(L[i]+1,L[i]+1+sz[i],cmp);
    }
    int las=0;
    int allsz=n;
    bool okk=1;
    for(int i=1;i<n && okk;i++){
        int z=getdeep(las);
        int v=L[z][sz[z]];
        vec.pb(v);
        sz[z]--;
        allsz--;
        las=z;

        for(int i=1;i<=cn;i++)
            if(sz[i]>=allsz/2){
                okk=0;break;
            }
    }
    if(!okk && allsz>1){
        int sp;
        for(int i=1;i<=cn;i++)
            if(sz[i]>=allsz/2){
                sp=i;break;
            }
            int z=getdeep(0);
            if(z!=las && z!=sp){
                int v=L[z][sz[z]];
                vec.pb(v);
                sz[z]--;
                allsz--;
                las=z;
            }
        bool turn=(las!=sp);
        //for ( int u:vec) cout<<u<<' ';cout<<'\n';
        //cout<<las<<' '<<sp<<'\n';
        //cout<<allsz;return vec;
        //cout<<sz[sp]<<' '<<allsz<<'\n';
        while(allsz>1){
            if(turn){
                int z=sp;
                if(sz[z]==0) {turn^=1;continue;}
                int v=L[z][sz[z]];
                vec.pb(v);
                sz[z]--;
                allsz--;
                las=z;
            }
            else{
                int z=getdeep(sp);
                int v=L[z][sz[z]];
                vec.pb(v);
                sz[z]--;
                allsz--;
                las=z;
            }
            turn^=1;
        }
    }
    vec.pb(r);
    //cout<<allsz<<'\n';
    return vec;
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:96:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   96 |         for(int i=1;i<=cn;i++)
      |         ^~~
fun.cpp:100:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  100 |             int z=getdeep(0);
      |             ^~~
fun.cpp: In function 'int getdeep(int)':
fun.cpp:30:12: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |     return r;
      |            ^
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:127:22: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
  127 |                 sz[z]--;
      |                 ~~~~~^~
fun.cpp:104:22: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
  104 |                 sz[z]--;
      |                 ~~~~~^~
fun.cpp:28:27: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |     for(int i=1;i<=3;i++) if(i!=v && sz[i]!=0)
      |                           ^~
fun.cpp:27:9: note: 'r' was declared here
   27 |     int r;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 155 ms 15400 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 588 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 7 ms 1228 KB Output is correct
23 Correct 14 ms 2188 KB Output is correct
24 Correct 18 ms 2996 KB Output is correct
25 Correct 90 ms 8924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 10 ms 1740 KB Output is correct
15 Correct 145 ms 15528 KB Output is correct
16 Correct 153 ms 15288 KB Output is correct
17 Correct 27 ms 3788 KB Output is correct
18 Correct 65 ms 7180 KB Output is correct
19 Correct 126 ms 12100 KB Output is correct
20 Correct 7 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 155 ms 15400 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 2 ms 588 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 7 ms 1228 KB Output is correct
49 Correct 14 ms 2188 KB Output is correct
50 Correct 18 ms 2996 KB Output is correct
51 Correct 90 ms 8924 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 10 ms 1740 KB Output is correct
54 Correct 145 ms 15528 KB Output is correct
55 Correct 153 ms 15288 KB Output is correct
56 Correct 27 ms 3788 KB Output is correct
57 Correct 65 ms 7180 KB Output is correct
58 Correct 126 ms 12100 KB Output is correct
59 Correct 7 ms 880 KB Output is correct
60 Correct 198 ms 15536 KB Output is correct
61 Correct 212 ms 17880 KB Output is correct
62 Correct 187 ms 15532 KB Output is correct
63 Correct 250 ms 19388 KB Output is correct
64 Correct 268 ms 19436 KB Output is correct
65 Correct 213 ms 15420 KB Output is correct
66 Correct 261 ms 17804 KB Output is correct
67 Correct 217 ms 19444 KB Output is correct
68 Correct 320 ms 18664 KB Output is correct
69 Correct 338 ms 20308 KB Output is correct
70 Correct 227 ms 15456 KB Output is correct
71 Correct 221 ms 19460 KB Output is correct
72 Correct 245 ms 18100 KB Output is correct
73 Correct 277 ms 18664 KB Output is correct
74 Correct 350 ms 20228 KB Output is correct
75 Correct 219 ms 15532 KB Output is correct
76 Correct 229 ms 19428 KB Output is correct
77 Correct 262 ms 19392 KB Output is correct
78 Incorrect 223 ms 18668 KB Repeated index
79 Halted 0 ms 0 KB -