# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
234406 | doowey | Konstrukcija (COCI20_konstrukcija) | C++14 | 5 ms | 384 KiB |
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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 100;
vector<int> T[N];
bool vis[N];
int dp[N][2];
void dfs(int u){
vis[u]=true;
for(auto x : T[u])
if(!vis[x])dfs(x);
}
ll calc(int n, vector<pii> edg){
dp[1][0]=1;
for(auto x : edg)
T[x.se].push_back(x.fi);
for(int i = 2; i <= n; i ++ ){
for(int j = 1; j <= n; j ++ )
vis[j]=false;
dfs(i);
for(int j = 1 ; j < i ; j ++ ){
if(!vis[j]) continue;
dp[i][0]+=dp[j][1];
dp[i][1]+=dp[j][0];
}
}
return dp[n][0]-dp[n][1];
}
int main(){
fastIO;
ll k;
cin >> k;
if(k == 0){
cout << "3 2\n"<< "1 2\n2 3\n";
return 0;
}
if(k == 1){
cout << "1 0\n";
return 0;
}
ll go = abs(k);
vector<int> di;
di.push_back(1);
vector<int> tt;
int sig = 0;
ll cur = -1;
for(int i = 0 ; i <= 60 ; i ++ ){
if((go&(1ll<<i)))
sig=i;
}
for(int i = sig; i >= 0 ; i -- ){
if(i < sig && (go&(1ll<<i))){
di.push_back(2);
cur *= -1ll;
if(cur > 0){
di.push_back(2);
cur *= -1ll;
}
tt.push_back(di.size() - 1);
cur -- ;
}
if(i > 0){
di.push_back(3);
cur *= -2ll;
}
}
if(cur != k){
di.push_back(2);
cur *= -1;
}
di.push_back(1);
int nn = tt.size();
for(auto x : di)
nn += x;
int m = di.size();
vector<int> p[m];
p[m-1].push_back(nn);
int c = 1;
for(int i = 0 ; i + 1 < m ; i ++ ){
for(int x = 0; x < di[i]; x ++ ){
p[i].push_back(c);
c++;
}
}
vector<pii> sol;
for(int i = 0 ; i < tt.size(); i ++ ){
sol.push_back(mp(1, c));
for(auto x : p[tt[i]])
sol.push_back(mp(c, x));
c ++ ;
}
for(int i = 0 ; i + 1 < m; i ++ ){
for(auto x : p[i]){
for(auto y : p[i + 1]){
sol.push_back(mp(x,y));
}
}
}
cout << nn << " " << sol.size() << "\n";
for(auto x : sol)
cout << x.fi << " " << x.se << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |