Submission #392138

# Submission time Handle Problem Language Result Execution time Memory
392138 2021-04-20T14:40:07 Z phathnv Konstrukcija (COCI20_konstrukcija) C++11
110 / 110
1 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, neg;
ll k;
vector<int> lastLayer;
vector<pair<int, int>> edges;

void AddLayer(int sz){
    vector<int> nxtLayer;
    for(int i = 1; i <= sz; i++)
        nxtLayer.push_back(++n);
    for(int u : lastLayer)
        for(int v : nxtLayer)
            edges.push_back({u, v});
    lastLayer = nxtLayer;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> k;
    if (k == 0){
        cout << "3 2\n";
        cout << "1 2\n";
        cout << "2 3\n";
        return 0;
    }
    if (k < 0){
        neg = 1;
        k *= -1;
    }

    n = 1;
    lastLayer = {1};
    int p = 0;
    for(int i = 0; i < 60; i++)
        if ((k >> i) & 1)
            p = i;
    for(int i = p - 1; i >= 0; i--){
        AddLayer(3);
        if ((k >> i) & 1){
            lastLayer.push_back(++n);
            edges.push_back({1, n});
        }
        AddLayer(2);
    }
    if (!neg)
        AddLayer(2);
    AddLayer(1);

    cout << n << ' ' << edges.size() << '\n';
    for(auto p : edges)
        cout << p.first << ' ' << p.second << '\n';

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct.
2 Correct 1 ms 204 KB Correct.
3 Correct 1 ms 204 KB Correct.
4 Correct 1 ms 204 KB Correct.
5 Correct 1 ms 204 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct.
2 Correct 1 ms 204 KB Correct.
3 Correct 1 ms 204 KB Correct.
4 Correct 1 ms 204 KB Correct.
5 Correct 1 ms 204 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct.
2 Correct 1 ms 204 KB Correct.
3 Correct 1 ms 204 KB Correct.
4 Correct 1 ms 204 KB Correct.
5 Correct 1 ms 204 KB Correct.
6 Correct 1 ms 204 KB Correct.
7 Correct 1 ms 204 KB Correct.
8 Correct 1 ms 204 KB Correct.
9 Correct 1 ms 204 KB Correct.
10 Correct 1 ms 204 KB Correct.
11 Correct 1 ms 204 KB Correct.
12 Correct 1 ms 316 KB Correct.
13 Correct 1 ms 204 KB Correct.
14 Correct 1 ms 204 KB Correct.
15 Correct 1 ms 204 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Correct.
2 Correct 1 ms 204 KB Correct.
3 Correct 1 ms 204 KB Correct.
4 Correct 1 ms 204 KB Correct.
5 Correct 1 ms 204 KB Correct.
6 Correct 1 ms 204 KB Correct.
7 Correct 1 ms 204 KB Correct.
8 Correct 1 ms 204 KB Correct.
9 Correct 1 ms 204 KB Correct.
10 Correct 1 ms 204 KB Correct.
11 Correct 1 ms 204 KB Correct.
12 Correct 1 ms 316 KB Correct.
13 Correct 1 ms 204 KB Correct.
14 Correct 1 ms 204 KB Correct.
15 Correct 1 ms 204 KB Correct.
16 Correct 1 ms 332 KB Correct.
17 Correct 1 ms 332 KB Correct.
18 Correct 1 ms 332 KB Correct.
19 Correct 1 ms 332 KB Correct.
20 Correct 1 ms 332 KB Correct.
21 Correct 1 ms 332 KB Correct.
22 Correct 1 ms 332 KB Correct.
23 Correct 1 ms 332 KB Correct.
24 Correct 1 ms 332 KB Correct.
25 Correct 1 ms 332 KB Correct.
26 Correct 1 ms 332 KB Correct.
27 Correct 1 ms 332 KB Correct.