Submission #292813

# Submission time Handle Problem Language Result Execution time Memory
292813 2020-09-07T13:42:47 Z muhammad_hokimiyon Fun Tour (APIO20_fun) C++14
31 / 100
190 ms 18380 KB
#include "fun.h"
#include <bits/stdc++.h>
 
#define fi first
#define se second
 
using namespace std;
 
const int NN = 1e5 + 7;
 
 
 
vector<int> createFunTour(int N, int Q)
{
    if( N == 2 ){
        vector < int > res;
        res.push_back(0);
        res.push_back(1);
        return res;
    }
    set < pair < int , int > > s[3];
    int cntr = 0;
    for( int i = 1 , y = N; i < N; i++ ){
        int x = attractionsBehind(0 , i);
        if( x * 2 >= N && x < y ){
            cntr = i;
            y = x;
        }
    }
    vector < int > d(N , 0);
    for( int i = 0; i < N; i++ ){
        if( i == cntr )continue;
        d[i] = hoursRequired( i , cntr );
    }
    vector < int > gr;
    for( int i = 0; i < N; i++ ){
        if( d[i] == 1 ){
            gr.push_back(i);
            s[(int)gr.size() - 1].insert({ d[i] , i });
        }
    }
    for( int i = 0; i < N; i++ ){
        bool f = false;
        if( i == cntr )continue;
        for( auto x : gr )f |= (i == x);
        if( f )continue;
        for( int j = 0; j < (int)gr.size() - 1; j++ ){
            if( hoursRequired( gr[j] , i ) + 1 == d[i] ){
                f = true;
                s[j].insert({ d[i] , i });
                break;
            }
        }
        if( !f ){
            s[(int)gr.size() - 1].insert({ d[i] , i });
        }
    }
    if( (int)s[0].size() + (int)s[1].size() == (int)s[2].size() ){
        for( auto x : s[1] ){
            s[0].insert(x);
        }
        s[1].clear();
        s[1] = s[2];
        s[2].clear();
    }
    else if( (int)s[0].size() + (int)s[2].size() == (int)s[1].size() ){
        for( auto x : s[2] ){
            s[0].insert(x);
        }
        s[2].clear();
    }
    else if( (int)s[1].size() + (int)s[2].size() == (int)s[0].size() ){
        for( auto x : s[2] ){
            s[1].insert(x);
        }
        s[2].clear();
    }
    auto x = *(--s[0].end());
    auto y = *(--s[1].end());
    if( !s[2].empty() && (--s[2].end())->fi > x.fi ){
        if( x.fi > y.fi ){
            y = x;
        }
        x = *(--s[2].end());
    }
    else if( !s[2].empty() && (--s[2].end())->fi > y.fi ){
        if( y.fi > x.fi ){
            x = y;
        }
        y = *(--s[2].end());
    }
    vector < int > res;
    res.push_back(x.se);
    int cnt = 0;
    for( int i = 0; i < 3; i++ ){
        if( s[i].find(x) != s[i].end() ){
            s[i].erase(x);
            cnt += 1;
        }
    }
    for( int i = 0; i < N - 2; i++ ){
        x = {0 , 0};
        int tp = 0;
        for( int j = 0; j < 3; j++ ){
            if( s[j].find(y) != s[j].end() ){
                tp = j;
            }
        }
        if( tp == 0 ){
            if( (int)s[0].size() + (int)s[1].size() == (int)s[2].size() ){
                x = *(--s[2].end());
            }else if( (int)s[0].size() + (int)s[2].size() == (int)s[1].size() ){
                x = *(--s[1].end());
            }else{
                for( int j = 0; j < 3; j++ ){
                    if( tp == j || s[j].empty() )continue;
                    x = max( x , *(--s[j].end()) );
                }
            }
        }else{
            if( tp == 1 ){
                if( (int)s[1].size() + (int)s[2].size() == (int)s[0].size() ){
                    x = *(--s[0].end());
                }else if( (int)s[1].size() + (int)s[0].size() == (int)s[2].size() ){
                    x = *(--s[2].end());
                }else{
                    for( int j = 0; j < 3; j++ ){
                        if( tp == j || s[j].empty() )continue;
                        x = max( x , *(--s[j].end()) );
                    }
                }
            }else{
                if( (int)s[2].size() + (int)s[1].size() == (int)s[0].size() ){
                    x = *(--s[0].end());
                }else if( (int)s[2].size() + (int)s[0].size() == (int)s[1].size() ){
                    x = *(--s[1].end());
                }else{
                    for( int j = 0; j < 3; j++ ){
                        if( tp == j || s[j].empty() )continue;
                        x = max( x , *(--s[j].end()) );
                    }
                }
            }
        }
        int f = 0;
        res.push_back( y.se );
        assert( s[tp].find(y) != s[tp].end() );
        s[tp].erase(y);
        y = x;
    }
    res.push_back(cntr);
    return res;
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:145:13: warning: unused variable 'f' [-Wunused-variable]
  145 |         int f = 0;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Runtime error 2 ms 640 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 190 ms 18380 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 616 KB Output is correct
21 Correct 5 ms 768 KB Output is correct
22 Correct 9 ms 1408 KB Output is correct
23 Correct 19 ms 2560 KB Output is correct
24 Correct 29 ms 3476 KB Output is correct
25 Correct 109 ms 10768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Incorrect 2 ms 512 KB Tour is not fun
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Runtime error 2 ms 640 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -