Submission #975254

# Submission time Handle Problem Language Result Execution time Memory
975254 2024-05-04T15:49:34 Z Circling Prize (CEOI22_prize) C++17
10 / 100
838 ms 268648 KB
/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;


int n, k, q, t, p[20][500001], depth[500001], w[20][500001], root, a, b, ans;
pair<int, int> questions[100000];
vector<int> chosen;
vector<vector<int>> children;


int main(){
    //cin.tie(0);
    //ios_base::sync_with_stdio(0);
    cin >> n >> k >> q >> t;
    children.resize(n + 1);
    for (int i = 1; i <= n; i++) cin >> p[0][0];
    for (int i = 1; i <= n; i++){
        cin >> p[0][i];
        if (p[0][i] != -1) children[p[0][i]].push_back(i);
        else root = i;
    }
    chosen = {root};
    depth[root] = 0;
    for (int i = 0; chosen.size() < k; i++){
        for (int c: children[chosen[i]]){
            chosen.push_back(c);
            depth[c] = depth[chosen[i]] + 1;
        }
    }
    chosen.resize(k);
    for (int c: chosen) cout << c << ' ';
    cout << endl;
    cout.flush();
    for (int c: chosen) if (c != root) cout << "? " << p[0][c] << ' ' << c << endl;
    cout << '!' << endl;
    cout.flush();
    for (int c: chosen) if (c != root) cin >> w[0][c] >> w[0][c] >> w[0][c] >> w[0][c];
    w[0][root] = 0;
    for (int i = 1; i < 20; i++){
        for (int j: chosen){
            p[i][j] = p[i - 1][p[i - 1][j]];
            w[i][j] = w[i - 1][j] + w[i - 1][p[i - 1][j]];
        }
    }
    for (int i = 0; i < t; i++) cin >> questions[i].first >> questions[i].second;
    for (int i = 0; i < t; i++){
        a = questions[i].first;
        b = questions[i].second;
        ans = 0;
        if (depth[a] < depth[b]) swap(a, b);
        for (int i = 0; i < 20; i++){
            if (((depth[a] - depth[b]) >> i) % 2 == 1){
                ans += w[i][a];
                a = p[i][a];
            }
        }
        for (int i = 19; i > -1; i--){
            if (p[i][a] != p[i][b]){
                ans += w[i][a] + w[i][b];
                a = p[i][a];
                b = p[i][b];
            }
        }
        if (a != b) ans += w[0][a] + w[0][b];
        cout << ans << ' ' << ans << endl;
    }
    cout.flush();
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:44:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |     for (int i = 0; chosen.size() < k; i++){
      |                     ~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 765 ms 110244 KB Output is correct
2 Correct 777 ms 109804 KB Output is correct
3 Correct 602 ms 102164 KB Output is correct
4 Correct 611 ms 102200 KB Output is correct
5 Correct 617 ms 102256 KB Output is correct
6 Correct 790 ms 104576 KB Output is correct
7 Correct 757 ms 104312 KB Output is correct
8 Correct 764 ms 104568 KB Output is correct
9 Correct 625 ms 101936 KB Output is correct
10 Correct 630 ms 101984 KB Output is correct
11 Correct 593 ms 102412 KB Output is correct
12 Correct 635 ms 102000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 511 ms 109312 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 334 ms 105644 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 838 ms 268648 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 619 ms 61904 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -