Submission #336157

# Submission time Handle Problem Language Result Execution time Memory
336157 2020-12-14T22:49:24 Z duality Fun Tour (APIO20_fun) C++11
100 / 100
371 ms 21732 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "fun.h"

int dist[100000];
int same(int a,int b) {
    return hoursRequired(a,b) < dist[a]+dist[b];
}
vpii cc[3];
int p[3];
vector<int> createFunTour(int N,int Q) {
    if (N == 2) {
        vi v;
        v.pb(0),v.pb(1);
        return v;
    }

    int i;
    int b = N,c = 0,n = 0;
    for (i = 1; i < N; i++) {
        int s = attractionsBehind(0,i);
        if ((2*s >= N) && (s < b)) b = s,c = i;
    }
    for (i = 0; i < N; i++) dist[i] = (c == i) ? 0:hoursRequired(c,i);
    for (i = 0; i < N; i++) {
        if (dist[i] == 1) cc[n++].pb(mp(dist[i],i));
    }
    for (i = 0; i < N; i++) {
        if (dist[i] >= 2) {
            int x = rand() % n;
            if (same(cc[x][0].second,i)) cc[x].pb(mp(dist[i],i));
            else {
                if (n == 2) cc[!x].pb(mp(dist[i],i));
                else if (same(cc[(x+1) % 3][0].second,i)) cc[(x+1) % 3].pb(mp(dist[i],i));
                else cc[(x+2) % 3].pb(mp(dist[i],i));
            }
        }
    }

    b = 0;
    vi ans;
    for (i = 0; i < n; i++) {
        sort(cc[i].begin(),cc[i].end(),greater<pii>());
        if (cc[i].size() < cc[b].size()) b = i;
    }
    cc[b].pb(mp(0,c));
    if (n == 2) {
        int uc = (cc[1].size() > cc[0].size());
        for (i = 0; i < N; i++) ans.pb(cc[uc][p[uc]].second),p[uc]++,uc ^= 1;
        return ans;
    }
    else {
        int uc = 0;
        for (i = 0; i < n; i++) {
            if (cc[i][0] > cc[uc][0]) uc = i;
        }
        for (i = 0; i < N; i++) {
            ans.pb(cc[uc][p[uc]].second),p[uc]++;
            int a = (p[(uc+1) % 3] < cc[(uc+1) % 3].size()) ? cc[(uc+1) % 3][p[(uc+1) % 3]].first:-1;
            int b = (p[(uc+2) % 3] < cc[(uc+2) % 3].size()) ? cc[(uc+2) % 3][p[(uc+2) % 3]].first:-1;
            if ((2*(cc[(uc+1) % 3].size()-p[(uc+1) % 3]) >= N-i-1) && (b <= dist[ans.back()])) uc = (uc+1) % 3;
            else if ((2*(cc[(uc+2) % 3].size()-p[(uc+2) % 3]) >= N-i-1) && (a <= dist[ans.back()])) uc = (uc+2) % 3;
            else if (a > b) uc = (uc+1) % 3;
            else uc = (uc+2) % 3;
        }
        return ans;
    }
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:113:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |             int a = (p[(uc+1) % 3] < cc[(uc+1) % 3].size()) ? cc[(uc+1) % 3][p[(uc+1) % 3]].first:-1;
      |                      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:114:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |             int b = (p[(uc+2) % 3] < cc[(uc+2) % 3].size()) ? cc[(uc+2) % 3][p[(uc+2) % 3]].first:-1;
      |                      ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:115:58: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  115 |             if ((2*(cc[(uc+1) % 3].size()-p[(uc+1) % 3]) >= N-i-1) && (b <= dist[ans.back()])) uc = (uc+1) % 3;
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
fun.cpp:116:63: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  116 |             else if ((2*(cc[(uc+2) % 3].size()-p[(uc+2) % 3]) >= N-i-1) && (a <= dist[ans.back()])) uc = (uc+2) % 3;
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 0 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 138 ms 15716 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 4 ms 748 KB Output is correct
22 Correct 7 ms 1260 KB Output is correct
23 Correct 13 ms 2284 KB Output is correct
24 Correct 18 ms 2924 KB Output is correct
25 Correct 78 ms 9112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 11 ms 1772 KB Output is correct
15 Correct 149 ms 15332 KB Output is correct
16 Correct 150 ms 15208 KB Output is correct
17 Correct 28 ms 4204 KB Output is correct
18 Correct 66 ms 7732 KB Output is correct
19 Correct 119 ms 12988 KB Output is correct
20 Correct 5 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 0 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 138 ms 15716 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 620 KB Output is correct
47 Correct 4 ms 748 KB Output is correct
48 Correct 7 ms 1260 KB Output is correct
49 Correct 13 ms 2284 KB Output is correct
50 Correct 18 ms 2924 KB Output is correct
51 Correct 78 ms 9112 KB Output is correct
52 Correct 1 ms 492 KB Output is correct
53 Correct 11 ms 1772 KB Output is correct
54 Correct 149 ms 15332 KB Output is correct
55 Correct 150 ms 15208 KB Output is correct
56 Correct 28 ms 4204 KB Output is correct
57 Correct 66 ms 7732 KB Output is correct
58 Correct 119 ms 12988 KB Output is correct
59 Correct 5 ms 876 KB Output is correct
60 Correct 199 ms 16868 KB Output is correct
61 Correct 256 ms 18916 KB Output is correct
62 Correct 210 ms 16612 KB Output is correct
63 Correct 233 ms 20580 KB Output is correct
64 Correct 241 ms 20364 KB Output is correct
65 Correct 243 ms 16868 KB Output is correct
66 Correct 277 ms 18916 KB Output is correct
67 Correct 254 ms 20364 KB Output is correct
68 Correct 255 ms 19812 KB Output is correct
69 Correct 371 ms 21220 KB Output is correct
70 Correct 217 ms 16868 KB Output is correct
71 Correct 247 ms 20580 KB Output is correct
72 Correct 285 ms 19172 KB Output is correct
73 Correct 255 ms 19908 KB Output is correct
74 Correct 351 ms 21604 KB Output is correct
75 Correct 242 ms 16868 KB Output is correct
76 Correct 236 ms 20576 KB Output is correct
77 Correct 257 ms 20452 KB Output is correct
78 Correct 255 ms 20008 KB Output is correct
79 Correct 317 ms 21120 KB Output is correct
80 Correct 336 ms 21732 KB Output is correct
81 Correct 223 ms 16484 KB Output is correct
82 Correct 238 ms 16868 KB Output is correct
83 Correct 256 ms 16752 KB Output is correct
84 Correct 82 ms 7108 KB Output is correct