Submission #362552

# Submission time Handle Problem Language Result Execution time Memory
362552 2021-02-03T16:08:55 Z Tenis0206 Subway (info1cup19_subway) C++11
100 / 100
12 ms 1128 KB
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

vector < int > parents;

int computeMaxH(int x) {
    int h = 0;
    while (h * (h + 1) / 2 <= x)
        h++;
    return h - 1;
}

void generateTree(int maxH) {
    parents.push_back(-1);
    for (int i = 1; i <= maxH; ++i)
        parents.push_back(i-1);
}

void printTree() {
    printf("%d\n", (int)parents.size());
    for (int i = 0; i < (int)parents.size(); ++i)
        printf("%d %d\n", i, (int)parents[i]);
}

int main() {
    //freopen("input","r",stdin);
    //freopen("output","w",stdout);

    int k; cin >> k;
    int maxH = computeMaxH(k);
    generateTree(maxH);

    k -= maxH * (maxH + 1) / 2;
    if (k > 0)
        parents.push_back(k-1);

    printTree();

    return 0;
}
# 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 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
# 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 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 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
# 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 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 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 3 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 4 ms 492 KB Output is correct
16 Correct 9 ms 1128 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 12 ms 1128 KB Output is correct
19 Correct 7 ms 896 KB Output is correct
20 Correct 7 ms 876 KB Output is correct