Submission #478461

# Submission time Handle Problem Language Result Execution time Memory
478461 2021-10-07T15:55:09 Z inksamurai Konstrukcija (COCI20_konstrukcija) C++17
0 / 110
1 ms 972 KB
#include <bits/stdc++.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end());
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define vec(...) vector<__VA_ARGS__>
#define _3ioVv0Q ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vec(int);
const int mxn=12000;

vi adj[mxn];

int main(){
_3ioVv0Q;
	ll k;
	cin>>k;
	assert(k<300);
	ll u=abs(k);
	vi candies;
	for(ll j=0;j<=60;j++){
		if(u&(1ll<<j)){
			candies.pb(j);
		}
	}
	int nodes=1,root=0;
	int magicalnode=0,additional_node=0;
	auto push=[&](int u,int v){
		adj[u].pb(v);
	};
	vec(pii) parent_candies;
	vec(pii) additional_candies;
	auto f=[&](int x){
		pii parent={-1,-1};
		bool pok=(x%2==0);
		while(x>0){
			if(parent.fi==-1){
				push(root,nodes);
				push(root,nodes+1);
			}else{
				push(parent.fi,nodes);
				push(parent.fi,nodes+1);
				push(parent.se,nodes);
				push(parent.se,nodes+1);
			}
			parent={nodes,nodes+1};
			nodes+=2;
			x=x-1;
		}
		if(pok) additional_candies.pb(parent);
		else parent_candies.pb(parent);
	};
	for(auto x : candies){
		if(x==0) continue;
		f(x);
	}
	magicalnode=nodes+1;
	additional_node=nodes;
	if(candies.front()==0){
		push(root,additional_node);	
	}
	for(auto p : additional_candies){
		push(p.fi,additional_node);
		push(p.se,additional_node);
	}
	push(additional_node,magicalnode);
	for(auto p : parent_candies){
		push(p.fi,magicalnode);
		push(p.se,magicalnode);
	}
	cout<<nodes+2<<"\n";
	rep(v,nodes+1){
		for(auto u : adj[v]){
			cout<<v+1<<" "<<u+1<<"\n";
		}
	}
//	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 972 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 588 KB Wrong answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 972 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 972 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -