Submission #395292

# Submission time Handle Problem Language Result Execution time Memory
395292 2021-04-28T06:05:48 Z syl123456 Fun Tour (APIO20_fun) C++17
10 / 100
1 ms 460 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;
    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()]))
            tmp = j;
        assert(tmp != -1);
        ans.push_back(v[tmp].back());
        v[tmp].pop_back();
        pre = tmp;
    }
    ans.push_back(cen);
    //vector<int> chk(all(ans));
    //sort(all(chk));
    //for (int i = 0; i < N; ++i) assert(chk[i] == i);
    return ans;
}

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)) {
      |                         ~~^~~~~~~~~~~~~~~
# 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 204 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 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 208 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 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 204 KB Output is correct
8 Correct 1 ms 204 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 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 208 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 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 Runtime error 1 ms 460 KB Execution killed with signal 6
30 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 204 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 Runtime error 1 ms 460 KB Execution killed with signal 6
17 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 Runtime error 1 ms 460 KB Execution killed with signal 6
9 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 204 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 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 208 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 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 Runtime error 1 ms 460 KB Execution killed with signal 6
30 Halted 0 ms 0 KB -