제출 #570627

#제출 시각아이디문제언어결과실행 시간메모리
570627NekoRollyKonstrukcija (COCI20_konstrukcija)C++17
110 / 110
1 ms352 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3+4;

ll k,n,m;
map<ll,vector<int>> anc;
pair<int,int> Ed[N];

int new_1(){ Ed[++m] = {1, ++n};
	return n;
}

int Get(ll k){
	if (anc.count(k)){ ++n;
		for (int x : anc[k]) Ed[++m] = {x, n};
		return n;
	}
	if (k < 0) anc[k] = {Get(-k), Get(-k)}; 
	if (k > 0){
		if (k == 1) anc[k] = {new_1(), new_1()};
		else{ ll x = k/2;
			anc[k] = {Get(-x), Get(-x), Get(-x)};
			if (k%2 == 1) anc[k].push_back(new_1());
		} 
	}
	return Get(k);
}

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

	cin >> k; n = 1;

	if (k == 0){
		cout << "3 2\n1 2\n2 3\n"; return 0;
	}

	Get(k);

	cout << n << " " << m << "\n";

	for (int i=1; i<=m; i++)
		cout << Ed[i].first << " " << Ed[i].second << "\n";

    return 0;
}
//576,460,752,303,423,488
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...