Submission #395351

# Submission time Handle Problem Language Result Execution time Memory
395351 2021-04-28T08:59:19 Z syl123456 Fun Tour (APIO20_fun) C++17
26 / 100
124 ms 15460 KB
#include "fun.h"
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
using namespace std;
typedef pair<int, int> pi;
std::vector<int> createFunTour(int N, int Q) {
    if (N == 2) {
        vector<int> ans(1, 0);
        ans.push_back(1);
        return ans;
    }
    vector<int> dep(N), sz(N);
    dep[0] = 0, sz[0] = N;
    int cen = 0;
    for (int i = 1; i < N; ++i) {
        dep[i] = hoursRequired(0, i);
        sz[i] = attractionsBehind(0, i);
        if (dep[i] > dep[cen] && sz[i] > N / 2) cen = i;
    }
    vector<int> v[3], ch;
    if (cen != 0) for (int i = 0; i < N; ++i) dep[i] = i == cen ? 0 : hoursRequired(cen, i);
    for (int i = 0; i < N; ++i) if (dep[i] == 1) ch.push_back(i);
    for (int j = 0; j < ch.size(); ++j) v[j].push_back(ch[j]);
    for (int i = 0; i < N; ++i) if (dep[i] > 1) {
        bool b = false;
        for (int j = 0; j < ch.size() - 1; ++j) if (dep[i] == 1 + hoursRequired(ch[j], i)) {
            v[j].push_back(i);
            b = true;
            break;
        }
        if (!b) v[ch.size() - 1].push_back(i);
    }
    for (int i = 0; i < 3; ++i) sort(all(v[i]), [&](int x, int y) {
        return dep[x] < dep[y];
    });
    vector<int> ans;
    bool vis[N]{};
    int pre = -1;
    for (int i = 0; i < N - 1; ++i) {
        int tmp = -1;
        for (int j = 0; j < 3; ++j) if (j != pre && !v[j].empty() && (tmp == -1 || dep[v[j].back()] > dep[v[tmp].back()] || (dep[v[j].back()] == dep[v[tmp].back()] && v[j].size() > v[tmp].size())))
            tmp = j;
        if (ch.size() == 2 && i == 0) tmp = v[0].size() < v[1].size();
        assert(tmp != -1);
        ans.push_back(v[tmp].back());
        v[tmp].pop_back();
        pre = tmp;
    }
    ans.push_back(cen);
    return ans;
}
/*
 * n depth
 * n sz
 * cen = max dep && sz > n/2
 * rt != cen ? n dis cen + n two ch
 *           : n first ch + n second ch
 *
 */

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int j = 0; j < ch.size(); ++j) v[j].push_back(ch[j]);
      |                     ~~^~~~~~~~~~~
fun.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int j = 0; j < ch.size() - 1; ++j) if (dep[i] == 1 + hoursRequired(ch[j], i)) {
      |                         ~~^~~~~~~~~~~~~~~
fun.cpp:37:10: warning: unused variable 'vis' [-Wunused-variable]
   37 |     bool vis[N]{};
      |          ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 204 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 204 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 292 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Incorrect 112 ms 15036 KB Too many queries
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 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 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 428 KB Output is correct
14 Correct 12 ms 1816 KB Output is correct
15 Incorrect 124 ms 15460 KB Too many queries
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 204 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 204 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 292 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Incorrect 112 ms 15036 KB Too many queries
45 Halted 0 ms 0 KB -