Submission #846604

# Submission time Handle Problem Language Result Execution time Memory
846604 2023-09-08T06:42:07 Z serifefedartar Konstrukcija (COCI20_konstrukcija) C++17
110 / 110
1 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 3e5 + 5;

ll now = 0;
int N = 1;
vector<int> curr;
vector<pair<int,int>> edges;

void addEdge(int cnt) {
	vector<int> new_nodes;
	for (int i = N+1; i <= N+cnt; i++)
		new_nodes.push_back(i);
	N += cnt;

	for (auto from : curr) {
		for (auto to : new_nodes)
			edges.push_back({from, to});
	}
	curr = new_nodes;
}

void addNode() {
	N++;
	edges.push_back({1, N});
	curr.push_back(N);
}

int main() {
	fast
	ll K;
	cin >> K;

	bool flip = K < 0;
	curr.push_back(1);
	if (flip)
		addEdge(2);
	K = abs(K);
	addEdge(1);
	for (ll i = 60; i >= 0; i--) {
		if ((1ll<<i) & K) {
			addEdge(2);
			addNode();
			if (i == 0)
				addEdge(2);
			else
				addEdge(3);
		} else if (i != 0) {
			addEdge(3);
			addEdge(2);
		}
	}

	if (flip)
		addEdge(1);
	else {
		addEdge(2);
		addEdge(1);
	}
	

	cout << N << " " << edges.size() << "\n";
	for (auto u : edges)
		cout << u.f << " " << u.s << "\n"; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct.
2 Correct 0 ms 344 KB Correct.
3 Correct 0 ms 460 KB Correct.
4 Correct 0 ms 348 KB Correct.
5 Correct 0 ms 348 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct.
2 Correct 0 ms 348 KB Correct.
3 Correct 1 ms 348 KB Correct.
4 Correct 1 ms 344 KB Correct.
5 Correct 0 ms 348 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct.
2 Correct 0 ms 344 KB Correct.
3 Correct 0 ms 460 KB Correct.
4 Correct 0 ms 348 KB Correct.
5 Correct 0 ms 348 KB Correct.
6 Correct 1 ms 348 KB Correct.
7 Correct 0 ms 348 KB Correct.
8 Correct 1 ms 348 KB Correct.
9 Correct 1 ms 344 KB Correct.
10 Correct 0 ms 348 KB Correct.
11 Correct 0 ms 348 KB Correct.
12 Correct 0 ms 348 KB Correct.
13 Correct 0 ms 348 KB Correct.
14 Correct 1 ms 348 KB Correct.
15 Correct 1 ms 348 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct.
2 Correct 0 ms 344 KB Correct.
3 Correct 0 ms 460 KB Correct.
4 Correct 0 ms 348 KB Correct.
5 Correct 0 ms 348 KB Correct.
6 Correct 1 ms 348 KB Correct.
7 Correct 0 ms 348 KB Correct.
8 Correct 1 ms 348 KB Correct.
9 Correct 1 ms 344 KB Correct.
10 Correct 0 ms 348 KB Correct.
11 Correct 0 ms 348 KB Correct.
12 Correct 0 ms 348 KB Correct.
13 Correct 0 ms 348 KB Correct.
14 Correct 1 ms 348 KB Correct.
15 Correct 1 ms 348 KB Correct.
16 Correct 1 ms 348 KB Correct.
17 Correct 1 ms 348 KB Correct.
18 Correct 0 ms 452 KB Correct.
19 Correct 1 ms 344 KB Correct.
20 Correct 1 ms 348 KB Correct.
21 Correct 1 ms 348 KB Correct.
22 Correct 1 ms 348 KB Correct.
23 Correct 1 ms 348 KB Correct.
24 Correct 0 ms 348 KB Correct.
25 Correct 0 ms 348 KB Correct.
26 Correct 0 ms 348 KB Correct.
27 Correct 1 ms 348 KB Correct.