Submission #160616

# Submission time Handle Problem Language Result Execution time Memory
160616 2019-10-28T20:12:24 Z SpaimaCarpatilor Subway (info1cup19_subway) C++17
20 / 100
2 ms 376 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <cassert>

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);

    assert(0 <= k && k <= 50);

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

    printTree();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -