This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <int> vi;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli k;
cin>>k;
int s,m=3;
if(k>=0)
s=1;
else
s=-1;
k=abs(k);
vi al[1001];
al[999].pb(1000);
al[998].pb(1000);
al[997].pb(1000);
int c=999;
for(int i=0;i<64;++i)
{
c-=3;
al[c].pb(c+3);
al[c].pb(c+2);
al[c].pb(c+1);
al[c-1].pb(c+3);
al[c-1].pb(c+2);
al[c-1].pb(c+1);
al[c-2].pb(c+3);
al[c-2].pb(c+2);
al[c-2].pb(c+1);
m+=9;
}
c-=3;
int mb=-1,b=0;
while((1LL<<b)<=k)
{
if(bit(k,b))
mb=b;
b++;
}
if(mb%2==0&&mb>=0)
{
int f=(997-(mb*3));
if(s==1)
{
al[1].pb(f);
al[1].pb(f+1);
m+=2;
}
else
{
for(int i=0;i<al[f].size();++i)
al[1].pb(al[f][i]);
m+=al[f].size();
}
}
else if(mb>=0)
{
int f=(997-(mb*3));
if(s==-1)
{
al[1].pb(f);
al[1].pb(f+1);
m+=2;
}
else
{
for(int i=0;i<al[f].size();++i)
al[1].pb(al[f][i]);
m+=al[f].size();
}
}
for(int i=0;i<mb;++i)
{
if(bit(k,i))
{
int f=(997-(i)*3);
if(i%2==0)
{
if(s==1)
{
for(int j=0;j<al[f].size();++j)
al[c].pb(al[f][j]);
al[1].pb(c);
c--;
m+=al[f].size()+1;
}
else
{
al[c].pb(f);
al[c].pb(f+1);
al[1].pb(c);
c--;
m+=3;
}
}
else
{
if(s==-1)
{
for(int j=0;j<al[f].size();++j)
al[c].pb(al[f][j]);
al[1].pb(c);
c--;
m+=al[f].size()+1;
}
else
{
al[c].pb(f);
al[c].pb(f+1);
al[1].pb(c);
c--;
m+=3;
}
}
}
}
cout<<1000<<' '<<m<<endl;
for(int i=1;i<=1000;++i)
{
for(int j=0;j<al[i].size();++j)
cout<<i<<' '<<al[i][j]<<endl;
}
return 0;
}
Compilation message (stderr)
konstrukcija.cpp: In function 'int main()':
konstrukcija.cpp:66:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[f].size();++i)
~^~~~~~~~~~~~~
konstrukcija.cpp:82:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<al[f].size();++i)
~^~~~~~~~~~~~~
konstrukcija.cpp:96:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<al[f].size();++j)
~^~~~~~~~~~~~~
konstrukcija.cpp:115:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<al[f].size();++j)
~^~~~~~~~~~~~~
konstrukcija.cpp:135:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<al[i].size();++j)
~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |