Submission #234406

#TimeUsernameProblemLanguageResultExecution timeMemory
234406dooweyKonstrukcija (COCI20_konstrukcija)C++14
110 / 110
5 ms384 KiB
#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)

konstrukcija.cpp: In function 'int main()':
konstrukcija.cpp:99:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < tt.size(); i ++ ){
                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...