text
stringlengths
49
983k
#include <iostream> #include <string> #include <cmath> #include<algorithm> #include<stack> #include<queue> #include<map> #include<set> #include<iomanip> #define _USE_MATH_DEFINES #include <math.h> #include <functional> #include<complex> using namespace std; #define rep(i,x) for(ll i=0;i<x;i++) #define repn(i,x) for(ll i=1;i<=x;i++) typedef long long ll; const ll INF = 1e17; const ll MOD = 1000000007; const ll MAX = 4000001; const long double eps = 1E-14; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll min(ll a, ll b) { if (a > b) { return b; } return a; } ll gcd(ll a, ll b) { if (b == 0) { return a; } if (a < b) { return gcd(b, a); } return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct edge { ll ind; ll fr; ll to; ll d; }; class mint { long long x; public: mint(long long x = 0) : x((x% MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint& a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint& a) const { mint res(*this); return res += a; } mint operator-(const mint& a) const { mint res(*this); return res -= a; } mint operator*(const mint& a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint& operator/=(const mint& a) { return (*this) *= a.inv(); } mint operator/(const mint& a) const { mint res(*this); return res /= a; } friend ostream& operator<<(ostream& os, const mint& m) { os << m.x; return os; } }; mint pw(mint a, ll b) { if (b == 0) { return 1; } mint ret = pw(a, b >> 1); ret *= ret; if (b & 1) { ret *= a; } return ret; } typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<mint> vmint; typedef vector<vector<mint>> vvmint; typedef vector<vector<vector<mint>>> vvvmint; ///////////////////////////////////// vvll l(11, vll(10, 0)); bool ch(vll v) { ll N = v.size(); vector<bool> c(v[N-1]*2, 0); rep(i,N)for(ll j=i+1;j<N;j++){ if (c[v[i] + v[j]] == 1) { return false; } c[v[i] + v[j]] = 1; } return true; } bool dfs(vll v, ll x, ll M) { if (v.size() == M) { rep(i, M)l[M][i] = v[i]; return true; } else { ll y = v[v.size() - 1]; for (ll z = y + 1; y+z < x; z++) { v.push_back(z); if (ch(v)) { if (dfs(v, x, M)) { return true; } } v.pop_back(); } } return false; } int main() { vll s = { 0,0,2,4,8,12,20,32,44,64,81 }; for(ll i=2;i<=10;i++) { vll v(1, 0); dfs(v, s[i], i); //rep(j, 10)cout << l[i][j]<<" "; //cout << endl; } //return 0; ll N; cin >> N; vvll g(N + 1, vll(N+1, 0)); ll mx = 2; g[2][1] = 1; for (ll i = 3; i <= N; i++) { repn(j, i - 1) { g[i][j] = mx * l[i][j]; } mx = mx + g[i][i - 1] + g[i][i - 2]; } repn(i, N) { repn(j, N) { if (i >= j) { cout << g[i][j]<<" "; } else { cout << g[j][i] << " "; } } cout << endl; } }
#include<bits/stdc++.h> using namespace std; set<int> s; vector<int> v,e; long long int g[10][10]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); v.emplace_back(1); v.emplace_back(2); int now=3; s.insert(1); s.insert(2); s.insert(3); for(int i=2;i<=8;i++){ while(true){ bool sw=0; for(int j=0;j<i;j++) if(s.find(v[j]+now)!=s.end()) sw=true; if(s.find(now)!=s.end()) sw=true; if(!sw){ for(int j=0;j<i;j++) s.insert(v[j]+now); v.emplace_back(now); now++; break; } now++; } } g[0][1]=g[1][0]=1; e.emplace_back(0); e.emplace_back(1); long long int ans=0; for(int i=2;i<10;i++){ long long int M=0; do{ long long int tmp=0; for(int j=0;j<i-1;j++) tmp+=g[e[j]][e[j+1]]; M=max(M,tmp); }while(next_permutation(e.begin(),e.end())); M++; e.emplace_back(i); sort(e.begin(),e.end()); for(int j=0;j<i;j++) g[j][i]=g[i][j]=M*v[j]; } int n; cin>>n; for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cout<<g[i][j]<<' '; cout<<endl; } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; const int N = 10; bool visited[N]; vector<ll> vals; ll cost[N][N]; int n, j; void dfs(int i, ll s) { visited[i] = true; int outs = 0; for (int t = 0; t < n; ++t) { if (! visited[t]) { ++outs; dfs(t, s + cost[i][t]); } } if (outs == 0 && i >= j) vals.push_back(s); visited[i] = false; } ll works() { for (j = 0; j < n; ++j) dfs(j, 0); sort(vals.begin(), vals.end()); ll ans = vals.back(); for (int i = 0; i+1 < vals.size(); ++i) { if (vals[i] == vals[i+1]) return -1; } vals.clear(); return ans; } int main() { vector<vector<int>> xr = { {1}, {1,2}, {1,2,4}, {1,2,4,7}, {1,2,4,7,12}, {1,2,4,8,13,18}, {1,2,4,8,14,19,24}, {1,2,4,8,15,24,29,34}, {1,7,10,13,21,26,41,43,45} }; int m; cin >> m; for (int i = 1; i < m; ++i) { n = i; ll b = works() + 1; if (b == -1) return 1; for (j = 0; j < n; ++j) { cost[i][j] = b * xr[i-1][j]; cost[j][i] = cost[i][j]; } } n = m; ll res = works(); if (res == -1) return 1; cerr << res << '\n'; for (int i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { cout << cost[i][j] << ' '; } cout << '\n'; } }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } struct str { ll dis, x, y; }; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; vector<vector<ll>> ans(10, vector<ll>(10)); ans[0][1] = ans[1][0] = 1; ans[0][2] = ans[2][0] = 2; ans[1][2] = ans[2][1] = 3; vector<str> vec; vec.pb({ 1,0,1 }); vec.pb({ 2,0,2 }); vec.pb({ 3,1,2 }); for (int i = 3; i < 10; i++) { for (int j = 0; j < i; j++) { ll sum = 1; vector<int> check(10); int cnt = i; if (j == 0) cnt--; int small = cnt - 1; int big = cnt; for (int s = 0; s < vec.size(); s++) { if (small == 0) break; sum -= vec[s].dis; check[vec[s].x]++; check[vec[s].y]++; small--; } rep(c, 10) check[c] = 0; for (int s = vec.size() - 1; s >= 0; s--) { if (big == 0) break; if (check[vec[s].x] < 2 && check[vec[s].y] < 2) { sum += vec[s].dis; check[vec[s].x]++; check[vec[s].y]++; big--; } } vec.pb({ sum,i,j }); ans[i][j] = ans[j][i] = sum; } } rep(i, n) { rep(j, n) { cout << ans[i][j] << ' '; } cout << '\n'; } }
// This code wrote by chtholly_micromaker(MicroMaker) #pragma GCC optimize("Ofast,O3,inline") #pragma GCC target("avx,avx2") #include <bits/stdc++.h> #define reg register #define int long long #define ALL(x) (x).begin(),(x).end() #define mem(x,y) memset(x,y,sizeof x) #define sz(x) (int)(x).size() #define ln puts("") #define lsp putchar(32) #define pb push_back #define MP make_pair #define dbg(x) cerr<<">"<<__func__<<"\tLine: "<<__LINE__<<' '<<#x<<": "<<x<<endl using namespace std; template <class t> inline void read(t &s){s=0; reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;} template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);} template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x; int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0; while(top)putchar(buf[top--]^'0');return;} inline void setIn(string s){freopen(s.c_str(),"r",stdin);return;} inline void setOut(string s){freopen(s.c_str(),"w",stdout);return;} inline void setIO(string s=""){setIn(s+".in");setOut(s+".out");return;} template <class t>inline bool checkmin(t&x,t y){if(x>y){x=y;return 1;}return 0;} template <class t>inline bool checkmax(t&x,t y){if(x<y){x=y;return 1;}return 0;} inline int lowbit(int x){return x&(-x);} int f[15]; int w[150][150]; inline void Init() { map<int,int> dr; dr[3]; f[1]=1,f[2]=2; for(int i=3;i<=11;++i) { for(int j=dr[i-1]+1;;++j) { if(dr.count(j)) continue; reg bool flg=true; for(int k=1;k<i;++k) if(dr.count(j+f[k])) { flg=false; break; } if(!flg) continue; f[i]=j; for(int k=1;k<i;++k) dr[j+f[k]]; break; } } return; } int idx[15]; signed main(void) { Init(); int n;read(n); for(int i=2;i<=n;++i) { reg int maxi=0; for(int j=1;j<i;++j) idx[j]=j; do { reg int sum=0; for(int j=1;j<i-1;++j) sum+=w[idx[j]][idx[j+1]]; checkmax(maxi,sum); }while(next_permutation(idx+1,idx+i)); for(int j=1;j<i;++j) w[i][j]=w[j][i]=(maxi+1)*f[j]; } for(int i=1;i<=n;++i,ln) for(int j=1;j<=n;++j) write(w[i][j]),lsp; return 0; } /* * Check List: * 1. Input / Output File (USACO and OI and UVa) * 2. long long * 3. Special Test such as n=1 * 4. Array Size * 5. Memory Limit (OI) int is 4 and longlong is 8 * 6. Mod (a*b%p*c%p not a*b*c%p , (a-b+p)%p not a-b ) * 7. Name ( int k; for(int k...)) * 8. more tests , (T=2 .. more) * 9. blank \n after a case */
#include<bits/stdc++.h> #define ll long long using namespace std; ll a1[13]={1,2,4,7,12,20,33,54,88,143}; ll n,an[15][15],no=1; bool vi[15]; int main(){ cin>>n; for (int i=1;i<=n;i++)an[i][i]=0; for (int i=1;i<=n;i++){ for (int j=i+1;j<=n;j++)an[i][j]=an[j][i]=no*a1[j-i-1]; no*=a1[n-i]; } if (n==10){an[8][10]=an[10][8]=25979230488;an[9][10]=an[10][9]=38734963162;} for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++)cout<<an[i][j]<<' '; cout<<endl; } return 0; }
#include <iostream> #include <string> #include <stdio.h> #include <string.h> #include <vector> #include <ctime> #include <set> #include <map> #include <unordered_map> #include <queue> #include <algorithm> #include <cmath> #include <assert.h> #include <iomanip> #include <bitset> using namespace std; #define vi vector<int> #define pii pair<int,int> #define pb push_back #define mp make_pair #define all(x) x.begin(),x.end() #define SZ(x) (int)(x.size()) #define rep(i,a,b) for(int i=a;i<b;i++) #define per(i,a,b) for(int i=b-1;i>=a;i--) #define inf 1000000007 #define mod 1000000007 #define x first #define y second #define pi acos(-1.0) #define DBG(x) cerr<<(#x)<<"="<<x<<"\n"; #define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++) #define ull unsigned long long #define ll long long #define N 1000005 template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;} template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;} //FILE* outFile; inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;} inline int gcd(int a, int b){if(b == 0)return a; return gcd(b, a%b);} int pow(int a,int b){ int ans=1; while(b){ if(b&1)ans=ans*(ll)a%mod; a=(ll)a*a%mod;b>>=1; } return ans; } const int M = 11; ll a[11][11], f[11]; int id[11]; int main(){ int j,k,i,T,ca=0, m = 0, K = 0, n; scanf("%d", &n); f[0] = 1, f[1] = 2; map<int, int>use; rep(i, 2, M){ rep(j, 0, i){ use[f[j]] = 1; rep(k, 0, j)use[f[j] + f[k]] = 1; } f[i] = 3; while(1){ int ok = !use[f[i]]; rep(j, 0, i)ok &= !use[f[j] + f[i]]; if(ok)break; f[i]++; } } ll mul = 1; rep(i, 1, M){ rep(j, 0, i)a[i][j] = a[j][i] = f[j] * mul; if(i==1)mul <<= 1; else{ mul *= f[i-2] + f[i-1]; mul++; } } /* map<ll, int>cnt; int ok = 0; ll mx = 1e11; rep(i, 0, n)id[i] = i; ok = 1; do{ ll sum = 0; rep(i, 1, n){ sum += a[id[i-1]][id[i]]; } cnt[sum]++; if(cnt[sum] > 2 || sum > mx){ok = 0;break;} }while(next_permutation(id, id+n)); */ rep(i, 0, n){ rep(j, 0, n)printf("%lld ", a[i][j]); puts(""); } }
#include <iostream> #include <vector> #include <algorithm> #include <set> using namespace std; vector<int> gen(int N){ vector<int> res; set<int> S; int last = 1; for(int i=0;i<N;i++){ while(true){ bool ok = !S.count(last); if(ok){ for(auto& t : res){ if(S.count(t + last)){ ok = false; break; } } } if(ok){ S.insert(last); for(auto& t : res) S.insert(t + last); res.push_back(last); ++last; break; } ++last; } } return res; } long long longest(const vector<vector<long long>>& cost, int N){ vector<int> a(N); for(int i=0;i<N;i++) a[i] = i; long long res = 1; do { long long sum = 0; for(int i=0;i+1<N;i++) sum += cost[a[i]][a[i+1]]; res = max(res, sum); } while(next_permutation(a.begin(), a.end())); return res; } vector<vector<long long>> solve(int N){ vector<int> g = gen(N); vector<vector<long long>> res(N, vector<long long>(N, 0)); res[0][1] = res[1][0] = 1; for(int i=2;i<N;i++){ long long l = longest(res, i); for(int j=0;j<i;j++) res[i][j] = res[j][i] = g[j] * (l+1); } return res; } int main(){ int N; while(cin >> N){ auto l = solve(N); for(auto& v : l){ cout << v[0]; for(int i=1;i<v.size();i++) cout << " " << v[i]; cout << endl; } } }
#include<bits/stdc++.h> long long s[][11]={{0,1,2,7,45,512,9925,321381,15870550,1069877351,},{1,0,4,14,90,1024,19850,642762,31741100,2139754702,},{2,4,0,28,180,2048,39700,1285524,63482200,4279509404,},{7,14,28,0,315,3584,69475,2249667,111093850,7489141457,},{45,90,180,315,0,6144,119100,3856572,190446600,12838528212,},{512,1024,2048,3584,6144,0,198500,6427620,317411000,21397547020,},{9925,19850,39700,69475,119100,198500,0,9320049,460245950,31026443179,},{321381,642762,1285524,2249667,3856572,6427620,9320049,0,603080900,40655339338,},{15870550,31741100,63482200,111093850,190446600,317411000,460245950,603080900,0,55633622252,},{1069877351,2139754702,4279509404,7489141457,12838528212,21397547020,31026443179,40655339338,55633622252,0,}}; int main(){ int n;scanf("%d",&n); for(int i=0;i<n;++i){for(int j=0;j<n;++j)printf("%lld ",s[i][j]);puts("");} return 0; }
#define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include <iostream> #include <string> #include <vector> #include <list> #include <utility> #include <algorithm> #include <functional> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <iomanip> #include <sstream> #include <bitset> #include <limits> #include <numeric> #include <valarray> #include <fstream> using namespace std; typedef unsigned int uint; typedef long long LL; typedef unsigned long long ULL; typedef pair<LL, LL> PP; #define REP(i, a, n) for(LL i = (a), i##_max = (n); i < i##_max; ++i) #define REM(i, a, n) for(LL i = (LL)(n) - 1, i##min = (a); i >= i##min; --i) #define ALL(arr) (arr).begin(), (arr).end() #define FLOAT fixed << setprecision(16) #define SPEEDUP {cin.tie(NULL); ios::sync_with_stdio(false);} const int INF = 0x3FFFFFFF; const LL INFLL = 0x3FFFFFFF3FFFFFFF; const double INFD = 1.0e+308; const double EPS = 1.0e-9; void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; } template <class T, class U> ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; } template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); } template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); } template<class T> T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); } istream& Ignore(istream& ist) { string s; ist >> s; return ist; } bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } template <class T> T Next() { T buf; cin >> buf; return buf; } #ifdef ONLY_MY_ENVIR #include "IntMod.h" #include "BinaryMatrix.h" #include "BIT.h" #include "Factorization.h" #include "FlowSolver.h" #include "Graph.h" #include "LazySegmentTree.h" #include "Math.h" #include "Matrix.h" #include "MinMax.h" #include "Position.h" #include "Range.h" #include "Rational.h" #include "SegmentTree.h" #include "SegmentTree2D.h" #include "SuffixArray.h" #include "Tree.h" #include "UnionFind.h" #endif #ifdef __GNUC__ typedef __int128 LLL; istream& operator>> (istream& ist, __int128& val) { LL tmp; ist >> tmp; val = tmp; return ist; } ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; } #endif #if 1234567891 #include <array> #include <random> #include <unordered_set> #include <unordered_map> template<typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >; // template <class T> // auto Is(const T& value) { return [value](const auto& comparand) -> bool { return comparand == value; }; } #endif int N; LL A[10][10] = { {0, 1, 2}, {1, 0, 3}, {2, 3, 0} }; int Judge() { vector<int> v; REP(i, 0, N) v.push_back(i); set<LL> st; do { LL sum = 0; REP(i, 1, N) { sum += A[v[i - 1]][v[i]]; } st.insert(sum); } while (next_permutation(v.begin(), v.end())); return st.size(); } int main() { cin >> N; LL base = 1; LL rem = 0; REP(i, 3, N) { LL base = 0; REP(p, 0, N) { REP(q, 0, p) { if (p < q + 2 || (p == i - 1 && p < q + 3)) { base += A[p][q]; } } } REP(p, 0, i) { base -= A[p][0]; } base += 1; LL a = base; LL b = a * 2; REP(j, 0, i) { LL k = a; A[i][j] = k; A[j][i] = k; LL t = a + b + base; a = b; b = t; } } REP(i, 0, N) { REP(j, 0, N) { cout << A[i][j] << (j == N - 1 ? '\n' : ' '); } } //cerr << Judge() << endl; return 0; }
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <cmath> #include <iomanip> #include <time.h> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) (((x) < 0)?-(x):(x)) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge using cat = long long; #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; vector< vector<cat> > W(N, vector<cat>(N, 0)); int seq[11] = {1, 2}; for(int i = 2; i <= 10; i++) seq[i] = seq[i-1]+seq[i-2]+1; cat prod = 1; int n = N-1; while(n > 0) { for(int i = 0; i < n; i++) W[i][n] = W[n][i] = prod * seq[i]; prod *= seq[n]; n--; } if(N == 10) { W[1][2] = W[2][1] = 6; int P[10]; for(int i = 0; i < 10; i++) P[i] = i; vector<cat> sum_c, sum_l; while(true) { if(P[0] < P[9]) { cat s = 0; int l = 0; for(int i = 0; i < 9; i++) { if(P[i]+P[i+1] == 1) l++; else s += W[P[i]][P[i+1]]; } if(l == 0) sum_c.push_back(s); else sum_l.push_back(s); } if(!next_permutation(P, P+10)) break; } sort(begin(sum_c), end(sum_c)); sort(begin(sum_l), end(sum_l)); cat x = 1; while(true) { bool stop = true; int a = 0; for(int i = 0; i < (int)sum_c.size(); i++) { while(a < (int)sum_l.size() && sum_c[i]-x > sum_l[a]) a++; if(a == (int)sum_l.size()) break; if(sum_c[i]-x == sum_l[a]) { stop = false; break; } } if(stop) break; x++; } W[0][1] = W[1][0] = x; } for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cout << W[i][j] << ((j+1 == N) ? "\n" : " "); return 0; } // look at my code // my code is amazing
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } int n; ll G[12][12],w[11]={0,1,2,4,7,12,20,29,38,53,73},mx; void Get_mx(int n){ static int p[12]; for(int i=1;i<=n;++i){ p[i]=i; } do{ ll tot=0; for(int i=2;i<=n;++i){ tot+=G[p[i-1]][p[i]]; } mx=max(mx,tot); }while(next_permutation(p+1,p+n+1)); } int main(){ n=read(); for(int i=2;i<=n;++i){ for(int j=1;j<i;++j){ G[i][j]=G[j][i]=(mx+1)*w[j]; } Get_mx(i); } for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j){ printf("%lld ",G[i][j]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair #define pb push_back #define space putchar(' ') #define enter putchar('\n') #define eps 1e-10 #define ba 47 #define MAXN 100005 //#define ivorysi using namespace std; typedef long long int64; typedef unsigned int u32; typedef double db; template<class T> void read(T &res) { res = 0;T f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 +c - '0'; c = getchar(); } res *= f; } template<class T> void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); } int N,tot; int64 w[15][15],M,a[] = {0,1,2,4,7,12,20,29,38,53,73}; bool vis[15]; void dfs(int dep,int pre,int64 sum) { if(dep > tot) { M = max(M,sum); return; } for(int i = 1 ; i <= tot ; ++i) { if(!vis[i]) { vis[i] = 1; dfs(dep + 1,i,sum + w[pre][i]); vis[i] = 0; } } } void Solve() { read(N); M = 0; for(int i = 2 ; i <= N ; ++i) { for(int j = 1 ; j < i ; ++j) { w[i][j] = w[j][i] = (M + 1) * a[j]; } tot = i; dfs(1,0,0); } for(int i = 1 ; i <= N ; ++i) { for(int j = 1 ; j <= N ; ++j) { out(w[i][j]);space; } enter; } } int main(){ #ifdef ivorysi freopen("f1.in","r",stdin); #endif Solve(); }
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,b) rng(i,0,b) #define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;} template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; using pi=pair<int,int>; using vi=vc<int>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.a<<","<<p.b<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } #define mp make_pair #define mt make_tuple using uint=unsigned; using ull=unsigned long long; template<int i,class T> void print_tuple(ostream&,const T&){ } template<int i,class T,class H,class ...Args> void print_tuple(ostream&os,const T&t){ if(i)os<<","; os<<get<i>(t); print_tuple<i+1,T,Args...>(os,t); } template<class ...Args> ostream& operator<<(ostream&os,const tuple<Args...>&t){ os<<"{"; print_tuple<0,tuple<Args...>,Args...>(os,t); return os<<"}"; } void print(ll x,int suc=1){ cout<<x; if(suc==1) cout<<endl; if(suc==2) cout<<" "; } ll read(){ ll i; cin>>i; return i; } vi readvi(int n,int off=0){ vi v(n); rep(i,n)v[i]=read()+off; return v; } template<class T> void print(const vector<T>&v,int suc=1){ rep(i,v.size()) print(v[i],i==int(v.size())-1?suc:2); } string readString(){ string s; cin>>s; return s; } template<class T> T sq(const T& t){ return t*t; } //#define CAPITAL void yes(bool ex=true){ #ifdef CAPITAL cout<<"YES"<<endl; #else cout<<"Yes"<<endl; #endif if(ex)exit(0); } void no(bool ex=true){ #ifdef CAPITAL cout<<"NO"<<endl; #else cout<<"No"<<endl; #endif if(ex)exit(0); } constexpr ll ten(int n){ return n==0?1:ten(n-1)*10; } const ll infLL=LLONG_MAX/3; #ifdef int const int inf=infLL; #else const int inf=INT_MAX/2-100; #endif //ayasii int topbit(signed t){ return t==0?-1:31-__builtin_clz(t); } int topbit(ll t){ return t==0?-1:63-__builtin_clzll(t); } int popcount(signed t){ return __builtin_popcount(t); } int popcount(ll t){ return __builtin_popcountll(t); } bool ispow2(int i){ return i&&(i&-i)==i; } bool inc(int a,int b,int c){ return a<=b&&b<=c; } template<class t> void mkuni(vc<t>&v){ sort(all(v)); v.erase(unique(all(v)),v.ed); } void Check(vvc<int> g){ int n=g.size(); vi p(n); iota(all(p),0); vi vals; do{ if(p[0]<p[n-1]){ int a=0; rep(i,n-1) a+=g[p[i]][p[i+1]]; vals.pb(a); } }while(next_permutation(all(p))); int s=vals.size(); mkuni(vals); if((int)vals.size()==s){ cerr<<vals[s-1]<<endl; if(vals[s-1]<=ten(11)){ for(auto v:g) print(v); exit(0); } } } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20); mt19937_64 rnd; int n;cin>>n; vvc<int> g(n,vi(n)); g[0][1]=g[1][0]=1; rng(i,2,n){ vvc<int>(i,vi(i,inf)); rep(_,i){ vi p(i+1); iota(all(p),0); vi mn(i,inf); int mx=0,mx2=0,mn2=inf; do{ int a=-1,b=0; rep(j,i){ if(j==i-2){ if(a==-1) chmin(mn2,b); } if(j==i-1){ if(a==-1) chmax(mx2,b); } b+=g[p[j]][p[j+1]]; if(g[p[j]][p[j+1]]==0){ if(a==-1)a=p[j]+p[j+1]-i; else{ a=-2; break; } } } if(a==-2)continue; if(a==-1)chmax(mx,b); else chmin(mn[a],b); }while(next_permutation(all(p))); dmp(i); dmp(_); dmp(g); dmp(mx); dmp(mx2); dmp(mn); int j=min_element(all(mn))-mn.bg; g[i][j]=g[j][i]=max(mx-mn[j],mx2-mn2)+1; } } cerr<<g<<endl; Check(g); }
#include<bits/stdc++.h> #define ll long long #define maxn 20 using namespace std; ll mp[maxn][maxn], val[maxn], mx, cnt, used[maxn], ch[maxn]; void get_mx(int dep, int n, ll x) { if (dep > n) mx = max(mx, x); else for (int i = 1; i <= n; i++) if (used[i] == 0) { ch[dep] = i; used[i] = 1; if (dep == 1) get_mx(dep + 1, n, x); else get_mx(dep + 1, n, mp[ch[dep - 1]][i] + x); used[i] = 0; } } int main() { int n; scanf("%d", &n); for (int i = 1; i <= 1000; i++) { int flag = 1; for (int j = 1; j <= cnt; j++) for (int k = j + 1; k <= cnt; k++) { if (j == k) continue; if (val[j] + val[k] == i) flag = 0; for (int l = 1; l <= cnt; l++) if (val[j] + val[k] == i + val[l]) flag = 0; } if (flag) { val[++cnt] = i; if (cnt == n) break; } } mp[1][2] = mp[2][1] = 1; for (int i = 3; i <= n; i++) { mx = 0; get_mx(1, i - 1, 0); for (int j = 1; j <= i - 1; j++) mp[j][i] = mp[i][j] = (mx + 1) * val[j]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cout << mp[i][j] << " "; cout << endl; } }
#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) typedef long long int ll; typedef pair<ll, ll> P; typedef pair<ll, P> T; typedef complex<double> com; struct edge { int u, v, cost; }; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll gcd(ll a, ll b) { if (!b)return a; else return gcd(b, a % b); } const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2; int mod = 1e9 + 7; //998244353; struct Mint { int val; Mint inv() const { unsigned tmp, a = val, b = mod; int x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() :val(0) {} Mint(ll x) :val(x >= 0 ? x % mod : x % mod + mod) {} int mtoi() { return this->val; } Mint pow(ll t) { Mint res = 1; while (t > 0) { if (t & 1) res *= *this; *this *= *this; t >>= 1; }return res; } Mint& operator+=(const Mint& x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint& operator-=(const Mint& x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint& operator*=(const Mint& x) { val = (ll)val * x.val % mod; return *this; } Mint& operator/=(const Mint& x) { return *this *= x.inv(); } bool operator==(const Mint& x) const { return val == x.val; } bool operator!=(const Mint& x) const { return val != x.val; } bool operator<(const Mint& x) const { return val < x.val; } bool operator<=(const Mint& x) const { return val <= x.val; } bool operator>(const Mint& x) const { return val > x.val; } bool operator>=(const Mint& x) const { return val >= x.val; } Mint operator-() const { return Mint(-val); } Mint operator+(const Mint& x) const { return Mint(*this) += x; } Mint operator-(const Mint& x) const { return Mint(*this) -= x; } Mint operator*(const Mint& x) const { return Mint(*this) *= x; } Mint operator/(const Mint& x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: factorial(int maxx) { Fact.resize(maxx + 1, Mint(1)); Finv.resize(maxx + 1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * Mint(i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * Mint(i); } Mint fact(int n) { return Fact[n]; } Mint finv(int n) { return Finv[n]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); return Fact[n] * Finv[r] * Finv[n - r]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); return Fact[n] * Finv[n - r]; } }; class UnionFind { vector<int> par; public: UnionFind(int n) { par = vector<int>(n, -1); } int root(int a) { if (par[a] < 0) return a; else return par[a] = root(par[a]); } int size(int a) { return -par[root(a)]; } bool connect(int a, int b) { a = root(a), b = root(b); if (a == b) return false; if (size(a) < size(b)) swap(a, b); par[a] += par[b], par[b] = a; return true; } }; struct max_flow { struct Edge { int to, cap, rev; }; int V; vector<vector<Edge>> G; vector<int> itr, level; public: max_flow(int V) : V(V) { G.assign(V, vector<Edge>()); } void add_edge(int from, int to, int cap) { G[from].push_back({ to, cap, (int)G[to].size() }); G[to].push_back({ from, 0, (int)G[from].size() - 1 }); } void bfs(int s) { level.assign(V, -1); queue<int> q; level[s] = 0; q.push(s); while (!q.empty()) { int v = q.front(); q.pop(); for (auto& e : G[v]) { if (e.cap > 0 && level[e.to] < 0) { level[e.to] = level[v] + 1; q.push(e.to); } } } } int dfs(int v, int t, int f) { if (v == t) return f; for (int& i = itr[v]; i < (int)G[v].size(); ++i) { Edge& e = G[v][i]; if (e.cap > 0 && level[v] < level[e.to]) { int d = dfs(e.to, t, min(f, e.cap)); if (d > 0) { e.cap -= d, G[e.to][e.rev].cap += d; return d; } } } return 0; } int run(int s, int t) { int ret = 0, f; while (bfs(s), level[t] >= 0) { itr.assign(V, 0); while ((f = dfs(s, t, inf)) > 0) ret += f; } return ret; } }; vector<ll> dijkstra(vector<vector<edge>> Grp, int s) { priority_queue<P, vector<P>, greater<P> > que; vector<ll> dist(Grp.size(), INF); dist[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (dist[v] < p.first) continue; rep(i, 0, Grp[v].size()) { edge e = Grp[v][i]; if (dist[e.v] > dist[v] + e.cost) { dist[e.v] = dist[v] + e.cost; que.push(P(dist[e.v], e.v)); } } } return dist; } void fft(vector<com>& x, bool inv) { int s = x.size(); if (s == 1) return; vector<com> even(s / 2), odd(s / 2); rep(i, 0, s / 2)even[i] = x[i * 2], odd[i] = x[i * 2 + 1]; fft(even, inv), fft(odd, inv); com w = 1, w_0 = polar(1.0, (inv ? -1 : 1) * 2LL * M_PI / s); rep(i, 0, s)x[i] = even[i % (s / 2)] + w * odd[i % (s / 2)], w *= w_0; } void MultiFunction(vector<int>& a, vector<int>& b) { int n = a.size(), maxx = 1; while (maxx <= 2 * n)maxx *= 2; vector<com> x(maxx), y(maxx); rep(i, 0, n) x[i] = com(a[i], 0), y[i] = com(b[i], 0); fft(x, 0), fft(y, 0); rep(i, 0, maxx) x[i] *= y[i]; fft(x, 1); rep(i, 0, maxx)x[i] /= maxx; a.resize(2 * n - 1, 0); rep(i, 0, 2 * n - 1)a[i] = (int)(x[i].real() + 0.5); } ll merge_cnt(vector<int> a) { ll n = a.size(), ai = 0, bi = 0, ci = 0, cnt = 0; if (n <= 1) return 0; vector<int> b(a.begin(), a.begin() + n / 2); vector<int> c(a.begin() + n / 2, a.end()); cnt += merge_cnt(b) + merge_cnt(c); while (ai < n) { if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci]))a[ai++] = b[bi++]; else cnt += n / 2LL - bi, a[ai++] = c[ci++]; } return cnt; } //template end int main() { int n; cin >> n; int x[] = { 1, 2, 4, 7, 12, 20, 29, 38, 52, 73 }; ll a[11][11] = {}; a[0][1] = a[1][0] = 1; ll m = 1; rep(rot, 2, n) { rep(i, 0, rot)a[i][rot] = a[rot][i] = (m + 1) * x[i]; vector<int> f(rot+1); rep(i, 0, rot+1)f[i] = i; do{ ll s = 0; rep(i, 0, rot) s += a[f[i]][f[i+1]]; chmax(m, s); } while (next_permutation(f.begin(),f.end())); } rep(i, 0, n) { rep(j, 0, n)printf("%lld ", a[i][j]); printf("\n"); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long lint; typedef long double louble; #define so(a) ((int)((a).size())) template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;} template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;} const char lf = '\n'; namespace ae86 { const int bufl = 1 << 15; char buf[bufl],*s=buf,*t=buf; inline int fetch() { if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;} return *s++; } inline int ty() { int a=0;int b=1,c=fetch(); while(!isdigit(c))b^=c=='-',c=fetch(); while(isdigit(c))a=a*10+c-48,c=fetch(); return b?a:-a; } } using ae86::ty; const int _ = 11; const int biao [] = { 0,1,2,4,7,12,20,29,38,52,73 }; int n; lint dis[_][_]={0}; int main() { ios::sync_with_stdio(0),cout.tie(nullptr); n=ty(); lint now=0; for(int i=2;i<=n;i++) { for(int j=1;j<i;j++) dis[i][j]=dis[j][i]=(now+1)*biao[j]; now=now-dis[i-1][i-2]+dis[i][i-1]+dis[i][i-2]; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cout<<dis[i][j]<<" \n"[j==n]; return 0; }
#include <bits/stdc++.h> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<30; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-8; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; int n; vvl g; vi a,b; ll dfs(int v,ll d,int t,int N){ if(t==N-1) return d; a[v]++; ll M=0; for(int u=0;u<N;u++) if(!a[u]) M=max(M,dfs(u,d+g[v][u],t+1,N)); a[v]--; return M; } int main(){ cin>>n; g=vvl(n,vl(n)); a=b=vi(n); g[0][1]=g[1][0]=b[0]=1; set<int> st; st.insert(1); for(int i=1;i<n;i++){ for(int j=0;j<i-1;j++) st.insert(b[j]+b[i-1]); int t=0; while(1){ bool B=1; if(st.find(t)!=st.end()) B=0; for(int j=0;j<i;j++) if(st.find(b[j]+t)!=st.end()) B=0; if(B){ b[i]=t; st.insert(t); break; } t++; } } for(int i=2;i<n;i++){ ll M=0; for(int j=0;j<i;j++){ a=vi(n); M=max(M,dfs(j,0,0,i)); } for(int j=0;j<i;j++) g[i][j]=g[j][i]=(M+1)*b[j]; } for(int i=0;i<n;i++) for(int j=0;j<n;j++) cout<<g[i][j]<<" \n"[j==n-1]; }
#include <bits/stdc++.h> using namespace std; //#define cerr if (false) cerr #define db(x) cerr << #x << "=" << x << endl #define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl #define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl #define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl #define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& x) { return os << "(" << x.first << "," << x.second << ")"; } typedef long long ll; typedef long double ld; ll E[15][15]; int main() { vector<int> v(10); v[0] = 1; bitset<1000> has; has[1] = true; for (int i = 1; i < 10; ++i) { for (int j = v[i - 1] + 1;; ++j) { if (has[j]) continue; for (int k = 0; k < i; ++k) if (has[v[k] + j]) goto end; v[i] = j; break; end:; } has[v[i]] = true; for (int k = 0; k < i; ++k) has[v[k] + v[i]] = true; } ll mx = 0; for (int n = 2; n <= 10; ++n) { for (int i = 0; i + 1 < n; ++i) E[i][n - 1] = E[n - 1][i] = v[i] * (mx + 1); vector<int> perm(n); iota(perm.begin(), perm.end(), 0); do { ll tot = 0; for (int i = 0; i + 1 < n; ++i) { tot += E[perm[i]][perm[i + 1]]; } mx = max(mx, tot); } while (next_permutation(perm.begin(), perm.end())); } int N; scanf("%d", &N); for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) printf("%lld%c", E[i][j], j == N - 1 ? '\n' : ' '); }
#include<bits/stdc++.h> #define IL inline #define _ 105 #define ll long long using namespace std; IL int gi(){ int data=0,fu=1; char ch=0; while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar(); if(ch=='-')fu=-1,ch=getchar(); while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar(); return data*fu; } int n,q[_],p[_]; bool Ban[1000005]; ll E[_][_]; map<ll,int>M; IL ll Halmilton(int nc){ ll ret=0,len=0; for(int i=1;i<=nc;++i)p[i]=i; do{ len=0; for(int i=2;i<=nc;++i)len+=E[p[i-1]][p[i]]; ret=max(ret,len); }while(next_permutation(p+1,p+nc+1)); return ret; } int main(){ n=gi(); int l=1,nq=0; bool flag; while(nq<n){ flag=true; for(int j=1;j<=nq;++j)if(Ban[l+q[j]])flag=false; if(Ban[l])flag=false; if(flag){ for(int j=1;j<=nq;++j)Ban[l+q[j]]=true; q[++nq]=l; } ++l; } E[1][2]=E[2][1]=q[1]; for(int i=3;i<=n;++i){ ll m=Halmilton(i-1); for(int j=1;j<i;++j)E[i][j]=E[j][i]=1ll*(m+1)*q[j]; } for(int i=1;i<=n;++i,puts("")) for(int j=1;j<=n;++j)cout<<E[i][j]<<" "; return 0; }
/* cerberus97 - Hanit Banga */ #include <iostream> #include <iomanip> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <chrono> #include <random> using namespace std; #define pb push_back #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL) typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const int N = 15; const ll MX = (1e11 / 9); ll e[N][N]; set<ll> st[N]; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void solve(int n); ll get_max(int n); bool check(int n); int main() { fast_cin(); int n; cin >> n; solve(n); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cout << e[i][j] << ' '; } cout << '\n'; } } void solve(int n) { vector<int> sum_free = {0, 1, 2, 4, 7, 12, 20, 29, 38, 52, 73}; e[1][2] = e[2][1] = 1; ll M = 1; for (int i = 3; i <= n; ++i) { for (int j = 1; j < i; ++j) { e[i][j] = e[j][i] = M * sum_free[(i == 3 ? j + 1 : j)]; } M = get_max(i); } // cout << M / (1e11) << endl; // cout << M << endl; // check(n); // cout << check(n) << endl; } ll get_max(int n) { vector<int> perm; for (int i = 1; i <= n; ++i) { perm.pb(i); } ll ans = 0; do { if (perm[0] > perm[n - 1]) { continue; } ll sum = 0; for (int i = 0; i < n - 1; ++i) { sum += e[perm[i]][perm[i + 1]]; } ans = max(ans, sum); } while (next_permutation(perm.begin(), perm.end())); return ans; } bool check(int n) { vector<int> perm; for (int i = 1; i <= n; ++i) { perm.pb(i); } set<ll> all_sums; int ctr = 0; do { if (perm[0] > perm[n - 1]) { continue; } ++ctr; ll sum = 0; for (int i = 0; i < n - 1; ++i) { sum += e[perm[i]][perm[i + 1]]; } all_sums.insert(sum); } while (next_permutation(perm.begin(), perm.end())); cout << ctr << ' ' << all_sums.size() << endl; return (ctr == all_sums.size()); }
#include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; #define REP(i, n) for(int i = 0; i < (int)(n); ++i) #define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) typedef long long ll; ll ans[11][11][11] = { {}, // 0 {}, // 1 { // 2 {0, 1}, {1, 0} }, { // 3 {0, 1, 2}, {1, 0, 3}, {2, 3, 0}, }, { // 4 {0, 1, 2, 3}, {1, 0, 4, 7}, {2, 4, 0, 12}, {3, 7, 12, 0} }, { // 5 {0LL, 1LL, 2LL, 3LL, 5LL}, {1LL, 0LL, 6LL, 12LL, 21LL}, {2LL, 6LL, 0LL, 33LL, 59LL}, {3LL, 12LL, 33LL, 0LL, 107LL}, {5LL, 21LL, 59LL, 107LL, 0LL} }, { // 6 {0LL, 1LL, 2LL, 3LL, 5LL, 8LL}, {1LL, 0LL, 9LL, 18LL, 33LL, 57LL}, {2LL, 9LL, 0LL, 88LL, 171LL, 313LL}, {3LL, 18LL, 88LL, 0LL, 513LL, 985LL}, {5LL, 33LL, 171LL, 513LL, 0LL, 1813LL}, {8LL, 57LL, 313LL, 985LL, 1813LL, 0LL} }, { // 7 {0LL, 1LL, 2LL, 3LL, 5LL, 8LL, 13LL}, {1LL, 0LL, 14LL, 33LL, 58LL, 101LL, 160LL}, {2LL, 14LL, 0LL, 251LL, 476LL, 861LL, 1472LL}, {3LL, 33LL, 251LL, 0LL, 2416LL, 4777LL, 8566LL}, {5LL, 58LL, 476LL, 2416LL, 0LL, 14624LL, 28334LL}, {8LL, 101LL, 861LL, 4777LL, 14624LL, 0LL, 52087LL}, {13LL, 160LL, 1472LL, 8566LL, 28334LL, 52087LL, 0LL} }, { // 8 {0LL, 1LL, 2LL, 3LL, 5LL, 8LL, 13LL, 21LL}, {1LL, 0LL, 16LL, 44LL, 71LL, 133LL, 217LL, 369LL}, {2LL, 16LL, 0LL, 547LL, 1089LL, 2064LL, 3448LL, 5871LL}, {3LL, 44LL, 547LL, 0LL, 8184LL, 17347LL, 28671LL, 53079LL}, {5LL, 71LL, 1089LL, 8184LL, 0LL, 87173LL, 174210LL, 329503LL}, {8LL, 133LL, 2064LL, 17347LL, 87173LL, 0LL, 570121LL, 1014448LL}, {13LL, 217LL, 3448LL, 28671LL, 174210LL, 570121LL, 0LL, 1933928LL}, {21LL, 369LL, 5871LL, 53079LL, 329503LL, 1014448LL, 1933928LL, 0LL} }, { // 9 {0LL, 1LL, 2LL, 3LL, 5LL, 8LL, 13LL, 21LL, 34LL}, {1LL, 0LL, 35LL, 81LL, 127LL, 214LL, 352LL, 587LL, 953LL}, {2LL, 35LL, 0LL, 1332LL, 2660LL, 5107LL, 8608LL, 12288LL, 21965LL}, {3LL, 81LL, 1332LL, 0LL, 34689LL, 67572LL, 130934LL, 228030LL, 384742LL}, {5LL, 127LL, 2660LL, 34689LL, 0LL, 639008LL, 1245184LL, 2487343LL, 4177264LL}, {8LL, 214LL, 5107LL, 67572LL, 639008LL, 0LL, 7061377LL, 14188610LL, 28067969LL}, {13LL, 352LL, 8608LL, 130934LL, 1245184LL, 7061377LL, 0LL, 46572628LL, 81788920LL}, {21LL, 587LL, 12288LL, 228030LL, 2487343LL, 14188610LL, 46572628LL, 0LL, 132595451LL}, {34LL, 953LL, 21965LL, 384742LL, 4177264LL, 28067969LL, 81788920LL, 132595451LL, 0LL}, }, { // 10 {0LL, 1LL, 2LL, 3LL, 5LL, 8LL, 13LL, 21LL, 34LL, 48LL}, {1LL, 0LL, 49LL, 129LL, 184LL, 331LL, 526LL, 897LL, 1450LL, 2334LL}, {2LL, 49LL, 0LL, 3590LL, 7216LL, 13913LL, 23502LL, 40969LL, 67850LL, 96252LL}, {3LL, 129LL, 3590LL, 0LL, 164224LL, 303104LL, 572928LL, 998968LL, 1682240LL, 2791421LL}, {5LL, 184LL, 7216LL, 164224LL, 0LL, 4558912LL, 8910819LL, 17380608LL, 29359616LL, 50253536LL}, {8LL, 331LL, 13913LL, 303104LL, 4558912LL, 0LL, 82435150LL, 163244031LL, 327165975LL, 544567680LL}, {13LL, 526LL, 23502LL, 572928LL, 8910819LL, 82435150LL, 0LL, 937430049LL, 1598799868LL, 3085697000LL}, {21LL, 897LL, 40969LL, 998968LL, 17380608LL, 163244031LL, 937430049LL, 0LL, 5303799809LL, 9996473518LL}, {34LL, 1450LL, 67850LL, 1682240LL, 29359616LL, 327165975LL, 1598799868LL, 5303799809LL, 0LL, 15031992320LL}, {48LL, 2334LL, 96252LL, 2791421LL, 50253536LL, 544567680LL, 3085697000LL, 9996473518LL, 15031992320LL, 0LL}, } }; bool check(int n) { int perm[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; set<ll> ss; do { if(perm[0] > perm[n-1]) { continue; } ll d = 0; // REP(i, n) { // cerr << perm[i] << " "; // } // cerr << endl; REP(i, n-1) { d += ans[n][perm[i]][perm[i+1]]; } // cerr << "d = " << d << endl; if(ss.count(d) > 0) { // cerr << d << "!!!!!!!" << endl; return false; } ss.insert(d); } while(next_permutation(perm, perm + n)); return true; } // // 初期用の吐くやつ // int main0(void) { // int n = 4; // ll k = 0; // REP(i, n) { // printf("{"); // REP(j, n) { // if(i != j && ans[n][i][j] == 0) { // ans[n][i][j] = ans[n][j][i] = 1LL << k; // ++k; // } // printf("%lldLL%s", ans[n][i][j], j == n-1 ? "},\n" : ", "); // } // } // return 0; // } // int main1(void) { // int n = 9; // assert(check(n)); // ll last = 0; // REP(i, n) { // for(int j = i+1; j < n; ++j) { // cerr << "(" << i << "," << j << ")" << endl; // ll left = last; // ll right = ans[n][i][j]; // while(left + 1 < right) { // ll md = (left + right) / 2; // ans[n][i][j] = ans[n][j][i] = md; // if(check(n)) { // right = md; // } else { // left = md; // } // } // ans[n][j][i] = ans[n][i][j] = right; // } // } // printf("Ans for %d\n", n); // REP(i, n) { // printf("{"); // REP(j, n) { // printf("%lldLL%s", ans[n][i][j], j == n-1 ? "},\n" : ", "); // } // } // return 0; // } int main(void) { int n; cin >> n; REP(i, n) { REP(j, n) { printf("%lld%c", ans[n][i][j], j == n-1 ? '\n' : ' '); } } return 0; }
#include<bits/stdc++.h> typedef long long ll; ll gi(){ ll x=0,f=1; char ch=getchar(); while(!isdigit(ch))f^=ch=='-',ch=getchar(); while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return f?x:-x; } std::mt19937 rnd(time(NULL)); #define rand rnd #define pr std::pair<int,int> #define all(x) (x).begin(),(x).end() #define fi first #define se second template<class T>void cxk(T&a,T b){a=a>b?a:b;} template<class T>void cnk(T&a,T b){a=a<b?a:b;} #ifdef mod int pow(int x,int y){ int ret=1; while(y){ if(y&1)ret=1ll*ret*x%mod; x=1ll*x*x%mod;y>>=1; } return ret; } template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;} template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;} #endif int shit[]={0,1,2,4,7,12,20,29,38,52,73}; ll w[11][11]; int p[11]; int main(){ #ifdef LOCAL freopen("in.in","r",stdin); //freopen("out.out","w",stdout); #endif int n=gi(); w[1][2]=w[2][1]=1;ll M=1; for(int x=3;x<=n;++x){//insert node x for(int i=1;i<x;++i)w[x][i]=w[i][x]=shit[i]*(M+1); for(int i=1;i<=x;++i)p[i]=i; do{ if(p[1]>p[x])continue; ll sum=0; for(int i=1;i<x;++i)sum+=w[p[i]][p[i+1]]; cxk(M,sum); }while(std::next_permutation(p+1,p+x+1)); } assert(M<=1e11); for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j)printf("%lld ",w[i][j]); puts(""); } return 0; }
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <cmath> #include <iomanip> #include <time.h> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) (((x) < 0)?-(x):(x)) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge using cat = long long; #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif cat W[10][10]; void upd(int a, int b, cat hint = 1) { int P[10]; for(int i = 0; i < 10; i++) P[i] = i; vector<cat> sum_c, sum_l; while(true) { if(P[0] < P[9]) { cat s = 0; int l = 0; for(int i = 0; i < 9; i++) { if(P[i] == a && P[i+1] == b) l++; else if(P[i] == b && P[i+1] == a) l++; else s += W[P[i]][P[i+1]]; } if(l == 0) sum_c.push_back(s); else sum_l.push_back(s); } if(!next_permutation(P, P+10)) break; } sort(begin(sum_c), end(sum_c)); sort(begin(sum_l), end(sum_l)); vector<int> pos_c(sum_l.size(), 0); priority_queue< pair<cat, int>, vector< pair<cat, int> >, greater< pair<cat, int> > > q; for(int i = 0; i < (int)sum_l.size(); i++) { if(i > 0) pos_c[i] = pos_c[i-1]; while(pos_c[i] < (int)sum_c.size() && sum_c[pos_c[i]] < sum_l[i]+hint) pos_c[i]++; if(pos_c[i] < (int)sum_c.size()) q.push({sum_c[pos_c[i]]-sum_l[i], i}); } cat x = hint; while(!q.empty()) { pair<cat, int> p = q.top(); if(x < p.ff) break; q.pop(); while(true) { pos_c[p.ss]++; q.push({sum_c[pos_c[p.ss]]-sum_l[p.ss], p.ss}); p = q.top(); if(p.ff > x) break; q.pop(); } x++; } if(q.empty()) return; cerr << x << " " << max(sum_c.back(), sum_l.back()+x)*1e-11 << endl; W[a][b] = W[b][a] = x; } int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; memset(W, 0, sizeof(cat)*100); int seq[11] = {1, 2}; for(int i = 2; i <= 10; i++) seq[i] = seq[i-1]+seq[i-2]+1; cat prod = 1; int n = N-1; while(n > 0) { for(int i = 0; i < n; i++) W[i][n] = W[n][i] = prod * seq[i]; prod *= seq[n]; n--; } if(N == 10) { W[1][2] = W[2][1] = 3; //upd(1, 2); W[0][1] = W[1][0] = 214; //upd(0, 1); W[0][2] = W[2][0] = 95963; //upd(0, 2, 50000); W[2][3] = W[3][2] = 1002019965;//upd(2, 3, 1002000000); W[1][3] = W[3][1] = 2004429048;//upd(1, 3, 2004000000); W[0][3] = W[3][0] = 4008331713;//upd(0, 3, 4008000000); } for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cout << W[i][j] << ((j+1 == N) ? "\n" : " "); return 0; } // look at my code // my code is amazing
#include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <vector> #include <string> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <bitset> #include <algorithm> #include <complex> #include <array> using namespace std; #define REP(i,n) for(int i=0; i<n; ++i) #define FOR(i,a,b) for(int i=a; i<=b; ++i) #define FORR(i,a,b) for (int i=a; i>=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int,int> P; typedef pair<ll,ll> PL; typedef vector<double> VD; typedef vector<VD> VVD; template<typename T> void chmin(T &a, T b) { if (a > b) a = b; } template<typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } ll calc(VVL d){ int n = d.size(); VI p(n); REP(i,n) p[i] = i; ll ret = 0; do { ll s = 0; REP(i,n-1) s += d[p[i]][p[i + 1]]; chmax(ret, s); }while (next_permutation(ALL(p))); return ret; } int main() { ll n; cin >> n; VL a(n-1); a[0] = 1; a[1] = 2; FOR(i,2,n-2){ set<int> st; REP(j,i) st.insert(a[j]); REP(j,i) REP(k,j) st.insert(a[j] + a[k]); FOR(x,1,1e5){ if (st.count(x)) continue; bool ok = true; REP(j,i) if (st.count(x + a[j])) ok = false; if (ok){ a[i] = x; break; } } } // REP(i,n-1) cout << a[i] << endl; VVL d(2, VL(2)); d[0][1] = d[1][0] = 1; FOR(x,2,n-1){ ll m = calc(d); REP(i,x) d[i].push_back((m + 1) * a[i]); d.push_back(VL()); REP(i,x) d[x].push_back((m + 1) * a[i]); d[x].push_back(0); } REP(i,n){ REP(j,n) cout << d[i][j] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 101; const long long DMAX = 1e11; long long g[N][N], mul[N]; int p[N]; int main() { mul[0] = 1; for (int i = 1; i < 10; ++i) { mul[i] = mul[i-1] + 1; bool ok = 0; while (!ok) { ok = 1; set<int> st; for (int j = 0; j <= i && ok; ++j) { if (st.count(mul[j])) { ok = 0; break; } st.insert(mul[j]); for (int k = j+1; k <= i; ++k) { int now = mul[k] + mul[j]; if (st.count(now)) { ok = 0; break; } st.insert(now); } } if (ok) break; ++mul[i]; } } int N, n = 2; scanf("%d", &N); g[0][1] = g[1][0] = 1; long long last = 1; while (n < N) { ++n; long long cur = last; bool ok = 0; while (!ok) { ok = 1; for (int i = 0; i < n-1; ++i) g[i][n-1] = g[n-1][i] = mul[i] * cur; last = 0; for (int i = 0; i < n; ++i) p[i] = i; set<long long> st; do { if (p[0] > p[n-1]) continue; long long sum = 0; for (int i = 0; i + 1 < n; ++i) sum += g[p[i]][p[i+1]]; if (st.count(sum)) { ok = 0; break; } st.insert(sum); last = max(last, sum); ++cur; } while (next_permutation(p, p+n)); } } assert(last <= DMAX); cerr << last << endl; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { printf("%lld%c", g[i][j], j == N-1 ? '\n' : ' '); } } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; const int N = 10; bool visited[N]; vector<ll> vals; ll cost[N][N]; int n, j; void dfs(int i, ll s) { visited[i] = true; int outs = 0; for (int t = 0; t < n; ++t) { if (! visited[t]) { ++outs; dfs(t, s + cost[i][t]); } } if (outs == 0 && i > j) vals.push_back(s); visited[i] = false; } bool works() { for (j = 0; j+1 < n; ++j) dfs(j, 0); sort(vals.begin(), vals.end()); cerr << vals.back() << '\n'; bool ans = true; for (int i = 0; i+1 < vals.size(); ++i) { if (vals[i] == vals[i+1]) ans = false; } vals.clear(); return ans; } int main() { vector<vector<int>> xr = { {1}, {1,2}, {1,2,4}, {1,2,4,7}, {1,2,4,7,12}, {1,2,4,8,13,18}, {1,2,4,8,14,19,24}, {1,2,4,8,15,24,29,34}, {1,2,4,8,15,24,29,34,46} /* {1}, {1,2}, {1,2,4}, {1,2,4,7}, {1,2,4,7,12}, {1,2,4,8,13,18}, {1,2,4,8,14,19,24}, {1,2,4,8,15,24,29,34}, {1,7,10,13,21,26,41,43,45} */ }; cin >> n; ll b = 1; for (int i = 0; i+1 < n; ++i) { for (j = i+1; j < n; ++j) { cost[i][j] = b * xr[n-2-i][j-1-i]; cost[j][i] = cost[i][j]; } if (i+2 < n) b *= (xr[n-2-i][n-2-i] + xr[n-2-i][n-3-i]); } if (works()) { for (int i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { cout << cost[i][j] << ' '; } cout << '\n'; } } else cout << "QAQ\n"; }
#include<bits/stdc++.h> using namespace std; long long a1[13]={1,2,4,7,12,20,29,38,52,101},a2[13]={1,2,4,7,12,20,30,39,67,101}; long long n,w=1,mp[15][15]; int main() { cin>>n; for(int i=1;i<=n;i++)mp[i][i]=0; for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++)mp[i][j]=mp[j][i]=w*a1[j-i-1]; w*=a2[n-i]; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++)cout<<mp[i][j]<<' '; cout<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; ll W[10][10]; void solve() { int i,j,k,l,r,x,y; string s; W[1][0]=W[0][1]=1; for(N=3;N<=10;N++) { vector<int> V; FOR(i,N-1) V.push_back(i); ll ma=0; do { if(V[0]>V.back()) continue; ll ret=0; FOR(i,N-2) ret+=W[V[i]][V[i+1]]; ma=max(ma,ret); } while(next_permutation(ALL(V))); ma++; int cand[]={1,2,4,7,12,20,29,38,52,73}; FOR(x,N-1) { W[N-1][x]=W[x][N-1]=ma*cand[x]; } } cin>>N; vector<int> V; FOR(i,N) V.push_back(i); set<ll> C; do { if(V[0]>V.back()) continue; ll ret=0; FOR(i,N-1) ret+=W[V[i]][V[i+1]]; assert(C.count(ret)==0); } while(next_permutation(ALL(V))); FOR(y,N) { FOR(x,N) cout<<W[y][x]<<" "; cout<<endl; } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
// https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_f /*<head>*/ // #include "Template.hpp" /*</head>*/ /*<body>*/ /* #region header */ /* #region 1*/ /** * @file Template.hpp * @brief 競技プログラミング用テンプレート * @author btk15049 * @date 2019/05/02 */ #include <bits/stdc++.h> using namespace std; /* #region macro */ #ifdef BTK # define DEBUG if (1) # define CIN_ONLY if (0) #else # define DEBUG if (0) # define CIN_ONLY if (1) #endif /** @def * ALLマクロ */ #define ALL(v) (v).begin(), (v).end() /** @def * 再帰ラムダをするためのマクロ */ #define REC(ret, ...) std::function<ret(__VA_ARGS__)> /* #endregion */ namespace _Template_ { /** * @brief cin高速化処理を行うための構造体 * @details CIN_ONLYマクロで動作が変わる */ struct cww { cww() { CIN_ONLY { ios::sync_with_stdio(false); cin.tie(0); } } } star; /** * @brief change min * @tparam T 型 * @param l 参照 * @param r 非参照 * @return 更新があればtrue */ template <typename T> inline bool chmin(T& l, T r) { bool a = l > r; if (a) l = r; return a; } /** * @brief chminのmax版 * @see chmin */ template <typename T> inline bool chmax(T& l, T r) { bool a = l < r; if (a) l = r; return a; } /** * @brief * vectorに直接cin流すためのやつ * @tparam T * @param is * @param v * @return istream& */ template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (auto& it : v) is >> it; return is; } /** * @brief * rangeを逆向きに操作したいとき用 * @details * ループの範囲は[bg,ed)なので注意 * @see range */ class reverse_range { private: struct I { int x; int operator*() { return x - 1; } bool operator!=(I& lhs) { return x > lhs.x; } void operator++() { --x; } }; I i, n; public: reverse_range(int n) : i({0}), n({n}) {} reverse_range(int i, int n) : i({i}), n({n}) {} I& begin() { return n; } I& end() { return i; } }; /** * @brief * python みたいな range-based for を実現 * @details * ループの範囲は[bg,ed)なので注意 * !つけると逆向きにループが回る (reverse_range) * 空間計算量はO(1) * 使わない変数ができて警告が出がちなので,unused_varとかを使って警告消しするとよい */ class range { private: struct I { int x; int operator*() { return x; } bool operator!=(I& lhs) { return x < lhs.x; } void operator++() { ++x; } }; I i, n; public: range(int n) : i({0}), n({n}) {} range(int i, int n) : i({i}), n({n}) {} I& begin() { return i; } I& end() { return n; } reverse_range operator!() { return reverse_range(*i, *n); } }; /** * @brief * rangeで生まれる使わない変数を消す用(警告消し) */ template <typename T> inline T& unused_var(T& v) { return v; } using LL = long long; } // namespace _Template_ using namespace _Template_; /* #endregion */ /* #endregion */ /*</body>*/ namespace xorshift { unsigned yy = 143132322; inline unsigned rand() { yy = yy ^ (yy << 13); yy = yy ^ (yy >> 17); return yy = yy ^ (yy << 5); } inline unsigned randInt() { return rand(); } } // namespace xorshift LL w[11][11]; int N; int calc() { unordered_map<LL, int> cnt; vector<int> o(N); iota(ALL(o), 0); int c = 0; LL mx = 0; do { LL k = 0; for (int i : range(N - 1)) { k += w[o[i]][o[i + 1]]; } cnt[k]++; if (cnt[k] >= 3) { c++; } chmax(mx, k); } while (next_permutation(ALL(o))); cerr << c << " " << mx << endl; return c; } LL magic_number[] = {1, 2, 4, 7, 12, 20, 29, 38, 52}; LL magic_sum[] = {2, 4, 5, 12, 20, 33, 50, 68, 81}; int main() { cin >> N; LL bottom = 1; for (int i : range(1, N)) { for (int j : range(i)) { w[i][j] = w[j][i] = bottom * magic_number[j]; } bottom *= magic_sum[i - 1]; } // int cur = calc(); for (int i : range(N)) { for (int j : range(N)) { cout << w[i][j] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll,ll> pll; typedef vector<bool> vb; const ll oo = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define FOR(i,a,b) for (ll i = (a); i < (b); i++) #define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--) #define mp make_pair #define pb push_back #define eb emplace_back #define xx first #define yy second #define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; }) vl weights = {1,2,4,7,12,20,29,38,52,73}; ll max_hamilton(vvl adj) { ll n = sz(adj), res = 0; vl p(n); iota(all(p),0); do { ll cur = 0; FOR(i,1,n) cur += adj[ p[i] ][ p[i-1] ]; res = max(res,cur); } while (next_permutation(all(p))); return res; } bool check(vvl adj) { ll n = sz(adj); vl p(n); iota(all(p),0); set<ll> s; do { ll cur = 0; if (p[0] > p[n-1]) continue; FOR(i,1,n) cur += adj[ p[i] ][ p[i-1] ]; if (s.count(cur)) return false; s.insert(cur); } while (next_permutation(all(p))); return true; } vvl solve(ll n) { if (n == 2) return {{0,1},{1,0}}; n--; vvl res = solve(n); ll hmax = max_hamilton(res) + (n==2); res.pb(vl(n+1)); FOR(i,0,n) res[i].resize(n+1); FOR(i,0,n) res[i][n] = res[n][i] = weights[i] * hmax; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; vvl res = solve(n); FOR(i,0,n) FOR(j,0,n) cout << res[i][j] << " \n"[j+1==n]; cout << endl; cerr << max_hamilton(res) << endl; assert(check(res)); }
#include <bits/stdc++.h> using namespace std; #define int long long int max_ham(vector<vector<int>> &w, int N){ vector<int> p(N); int i, ans = 0; for(i = 0; i < N; i++){ p[i] = i; } do{ /* for(i = 0; i < N; i++){ printf("%lld ", p[i]); } printf("\n"); */ int now = 0; for(i = 1; i < N; i++){ now += w[p[i - 1]][p[i]]; } ans = max(ans, now); }while(next_permutation(p.begin(), p.end())); return ans; } signed main(){ int N, i, j; int a[] = {1, 2, 4, 7, 12, 20, 29, 38, 52, 73}; scanf("%lld", &N); vector<vector<int>> w(N, vector<int>(N, 0)); w[0][1] = 1; w[1][0] = 1; for(i = 2; i < N; i++){ // printf("i = %lld\n", i); int M = max_ham(w, i); // printf("M = %lld\n", M); for(j = 0; j < i; j++){ w[i][j] = a[j] * (M + 1); w[j][i] = a[j] * (M + 1); } } // printf("%lld\n", max_ham(w, N)); for(i = 0; i < N; i++){ for(j = 0; j < N; j++){ printf("%lld ", w[i][j]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int n; bool u[20]; map<long long, int> m; vector<int> v; long long cur = 1, x[20][20]; long long ma(int a, int b, long long c) { if (b == n) cur = max(cur, c); b++; for (int i = 0; i < n; i++) if (!u[i]) { u[i] = 1; ma(i, b, c + x[a][i]); u[i] = 0; } return 1; } bool check(int a, int b, long long c) { // printf("check(a=%d b=%d c=%lld)\n", a, b, c); if (b == n) return ++m[c] <= 2 || !printf("c=%lld\n", c); b++; for (int i = 0; i < n; i++) if (!u[i]) { u[i] = 1; bool ret = check(i, b, c + x[a][i]); u[i] = 0; if (!ret) return 0; } return 1; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 1; ; j++) { bool ok = 1; set<int> s; v.push_back(j); for (int k : v) if (!s.insert(k).second) ok = 0; for (int k = 0; k < v.size(); k++) for (int l = k + 1; l < v.size(); l++) if (!s.insert(v[k] + v[l]).second) ok = 0; if (ok) break; else v.pop_back(); } // printf("v="); for (int i : v) printf("%d ", i); puts(""); x[0][1] = x[1][0] = 1; cur = 1; for (int i = 2; i < n; i++) { cur++; for (int j = 0; j < i; j++) x[i][j] = x[j][i] = cur * v[j]; if (i == n - 1) break; for (int j = 0; j <= i; j++) { u[j] = 1; ma(j, 1, 0); u[j] = 0; } } /* printf("cur=%lld\n", cur); bool ok = 1; for (int i = 0; i < n && ok; i++) { u[i] = 1; ok &= check(i, 1, 0); u[i] = 0; } printf("ok=%d\n", ok); */ for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) printf("%lld%c", x[i][j], " \n"[j == n - 1]); }
#include <bits/stdc++.h> #define clr(x) memset(x,0,sizeof(x)) #define For(i,a,b) for (int i=(a);i<=(b);i++) #define Fod(i,b,a) for (int i=(b);i>=(a);i--) #define fi first #define se second #define kill _z_kill #define y0 _z_y0 #define y1 _z_y1 #define x0 _z_x0 #define x1 _z_x1 #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) using namespace std; typedef long long LL; typedef unsigned long long ull; typedef unsigned uint; typedef long double LD; typedef vector <int> vi; typedef pair <int,int> pii; void enable_comma(){} string tostring(char c); string tostring(LL x); template <class A,class B> string tostring(pair <A,B> p); template <class A> string tostring(vector <A> v); string tostring(char c){ string s=""; s+=c; return s; } string tostring(string s){ return "\""+s+"\""; } string tostring(char *c){ return tostring((string)c); } string tostring(LL x){ if (x<0) return "-"+tostring(-x); if (x>9) return tostring(x/10)+tostring(char('0'+x%10)); else return tostring(char('0'+x)); } string tostring(int x){ return tostring((LL)x); } string tostring(ull x){ if (x>9) return tostring((LL)(x/10))+tostring(char('0'+x%10)); else return tostring(char('0'+x)); } string tostring(uint x){ return tostring((LL)x); } string tostring(double x){ static char res[114]; sprintf(res,"%lf\n",x); return tostring(res); } string tostring(LD x){ return tostring((double)x); } template <class A,class B> string tostring(pair <A,B> p){ return "("+tostring(p.fi)+","+tostring(p.se)+")"; } template <class A> string tostring(vector <A> v){ string res="{"; For(i,0,(int)v.size()-1){ res+=tostring(v[i]); res+=i==(int)v.size()-1?"}":","; } if (res=="{") res+="}"; return res; } template <class A> string tostring(A a,int L,int R){ string res="{"; For(i,L,R){ res+=tostring(a[i]); res+=i==R?"}":","; } if (res=="{") res+="}"; return res; } string tostrings(){ return ""; } template <typename Head,typename... Tail> string tostrings(Head H,Tail... T){ return tostring(H)+" "+tostrings(T...); } #define User_Time ((double)clock()/CLOCKS_PER_SEC) #ifdef zzd #define outval(x) cerr<<#x" = "<<tostring(x)<<endl #define outvals(...) cerr<<"["<<#__VA_ARGS__<<"]: "<<tostrings(__VA_ARGS__)<<endl #define outtag(x) cerr<<"--------------"#x"---------------"<<endl #define outsign(x) cerr<<"<"#x">"<<endl #define outarr(a,L,R) cerr<<#a"["<<(L)<<".."<<(R)<<"] = "<<tostring(a,L,R)<<endl #else #define outval(x) enable_comma() #define outvals(...) enable_comma() #define outtag(x) enable_comma() #define outsign(x) enable_comma() #define outarr(a,L,R) enable_comma() #endif #ifdef ONLINE_JUDGE #ifdef assert #undef assert #endif #define assert(x) (!(x)?\ cout<<"Assertion failed!"<<endl<<\ "function: "<<__FUNCTION__<<endl<<\ "line: "<<__LINE__<<endl<<\ "expression: "<<#x<<endl,exit(3),0:1) #endif LL read(){ LL x=0,f=0; char ch=getchar(); while (!isdigit(ch)) f=ch=='-',ch=getchar(); while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); return f?-x:x; } template <class T> void ckmax(T &x,const T y){ if (x<y) x=y; } template <class T> void ckmin(T &x,const T y){ if (x>y) x=y; } //int Pow(int x,int y){ // int ans=1; // for (;y;y>>=1,x=(LL)x*x%mod) // if (y&1) // ans=(LL)ans*x%mod; // return ans; //} //void Add(int &x,int y){ // if ((x+=y)>=mod) // x-=mod; //} //void Del(int &x,int y){ // if ((x-=y)<0) // x+=mod; //} //int Add(int x){ // return x>=mod?x-mod:x; //} //int Del(int x){ // return x<0?x+mod:x; //} //int md(LL x){ // return (x%mod+mod)%mod; //} const int N=233; int n; LL g[N][N]; namespace test{ void main(){ unordered_map <LL,int> vis; vi id(n); iota(id.begin(),id.end(),1); do { LL now=0; For(i,1,(int)id.size()-1) now+=g[id[i-1]][id[i]]; assert(now<=1e11); if ((++vis[now])>2) assert(0); } while (next_permutation(id.begin(),id.end())); } } int main(){ n=read(); g[n-1][n]=1; Fod(i,n-2,1){ For(j,i+2,min(n,i+3)) g[i][n]+=g[i+1][j]; if (i==n-2) g[i][n]++; g[i][n-1]=g[i][n]*2-1; if (i<n-2) g[i][n-1]--; if (i<n-3) g[i][n-1]--; Fod(j,n-2,i+1) g[i][j]=g[i][j+1]+g[i][j+2]+g[i][n]-2; } For(i,1,n) For(j,i+1,n) g[j][i]=g[i][j]; For(i,1,n){ For(j,1,n) printf("%lld ",g[i][j]); puts(""); } #ifdef zzd test::main(); #endif return 0; }
#include<bits/stdc++.h> using namespace std; #define nn 14 #define ll long long ll road[nn][nn]; ll n; ll rati[]={1,2,4,7,12,20,29,38,52,73}; ll M; void outprint(){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ printf("%lld ",road[i][j]); } puts(""); } exit(0); } ll id[nn]; void solve(ll m){ for(int i=0;i<m;i++) id[i]=i; do{ ll ans=0; for(int i=0;i<m;i++) ans+=road[id[i]][id[(i+1)%m]]; M=max(M,ans); }while(next_permutation(id,id+m)); } int main(){ srand(time(0)); cin>>n; if(n==2){ road[1][0]=road[0][1]=1; outprint(); } while(1){ road[0][1]=road[1][0]=1,road[1][2]=road[2][1]=2,road[0][2]=road[2][0]=3; for(int i=3;i<n;i++){ solve(i); random_shuffle(rati,rati+i); for(int j=0;j<i;j++){ road[j][i]=road[i][j]=(M)*rati[j]; } } solve(n); if(M<1e11) outprint(); } return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);i++) using namespace std; typedef long long ll; const int N=12,c[11]={0,1,2,4,7,12,20,29,38,52,73}; ll w[N][N],p[N],n,M; int main(){ cin>>n; rep(i,2,n){ rep(j,1,i-1) w[i][j]=w[j][i]=(M+1)*c[j]; if(i==n) break; rep(j,1,i) p[j]=j; do{ if(p[1]>p[i]) continue; ll sum=0; rep(j,1,i-1) sum+=w[p[j]][p[j+1]]; M=max(M,sum); }while(next_permutation(p+1,p+i+1)); } rep(i,1,n) rep(j,1,n) printf("%lld%c",w[i][j]," \n"[j==n]); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define DBG(v) cerr << #v << " = " << (v) << endl; vector<int> f() { vector<int> v; set<int> s; auto ok = [&](const int i) { if(s.count(i)) return false; for(int x : v) if(s.count(x +i)) return false; return true; }; for (int i = 1; (int) v.size() < 10; ++i) if (ok(i)) { s.insert(i); for (int x : v) s.insert(x + i); v.push_back(i); } assert(s.size() == 10 + 10 * 9 / 2); return v; } ll M[111][111]; ll getMx(const ll n) { vector<int> v(n); for (int i = 0; i < n; ++i) v[i] = i + 1; ll mx = 0; do { ll temp = 0; for (int i = 1; i < n; ++i) temp += M[v[i - 1]][v[i]]; mx = max(mx, temp); } while (next_permutation(v.begin(), v.end())); return mx; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n; cin >> n; assert(2 <= n && n <= 10); M[1][2] = M[2][1]= 1; const vector<int> v = f(); for (int i = 3; i <= n; ++i) { ll mx = getMx(i - 1); for (int j = 1; j < i; ++j) M[i][j] = M[j][i] =(mx + 1) * v[j - 1]; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) cout << M[i][j] << ' '; cout << endl; } cerr << "mx: " << getMx(n); return 0; }
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> using namespace std; template<class t> inline t read(t &x){ char c=getchar();bool f=0;x=0; while(!isdigit(c)) f|=c=='-',c=getchar(); while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar(); if(f) x=-x;return x; } template<class t,class ...A> inline void read(t &x,A &...a){ read(x);read(a...); } template<class t> inline void write(t x){ if(x<0) putchar('-'),write(-x); else{if(x>9) write(x/10);putchar('0'+x%10);} } #define int long long const int N=15,a[]={0,1,2,4,7,12,20,29,38,52,73}; int maxlen,n,ans[N][N],p[N]; signed main(){ read(n); for(int i=1;i<=n;i++) p[i]=i; for(int i=2;i<=n;i++){ for(int j=1;j<i;j++) ans[j][i]=ans[i][j]=(maxlen+1)*a[j]; if(i==n) continue; do{ int cur=ans[p[i]][p[0]]; for(int j=2;j<=i;j++) cur+=ans[p[j-1]][p[j]]; maxlen=max(maxlen,cur); }while(next_permutation(p+1,p+1+i)); } for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=n;j++,putchar(' ')) write(ans[i][j]); }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; int read() { int x=0,f=1; char ch=getchar(); while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();} while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();} return x*f; } ll re[15][15]; int dis[]={0,1,2,4,7,12,20,29,38,52,73}; int n; int book[15]; int a[15]; int vis[15]; ll mx; void dfs(int x,int n) { if(x>n) { ll tmp=0; for(int i=2;i<=n;i++) tmp=tmp+re[a[i-1]][a[i]]; mx=max(mx,tmp); return; } for(int i=1;i<=n;i++) { if(!vis[i]) { a[i]=x; vis[i]=1; dfs(x+1,n); vis[i]=0; } } } int main() { n=read(); re[1][2]=re[2][1]=1; for(int i=3;i<=n;i++) { mx=0; dfs(1,i-1); for(int j=1;j<i;j++) re[i][j]=re[j][i]=(ll)dis[j]*(mx+1); } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) printf("%lld ",re[i][j]); puts(""); } return 0; }
// ==================================== // author: M_sea // website: https://m-sea-blog.com/ // ==================================== #include <bits/stdc++.h> using namespace std; typedef long long ll; int read() { int X=0,w=1; char c=getchar(); while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); } while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar(); return X*w; } const int N=10+10; const int a[11]={0,1,2,4,7,12,20,29,38,53,73}; int n,p[N]; ll M,G[N][N]; void update(int n) { for (int i=1;i<=n;++i) p[i]=i; do { ll l=0; for (int i=2;i<=n;++i) l+=G[p[i-1]][p[i]]; M=max(M,l); } while (next_permutation(p+1,p+n+1)); } int main() { n=read(); for (int i=2;i<=n;++i) { for (int j=1;j<i;++j) G[i][j]=G[j][i]=(M+1)*a[j]; update(n); } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) printf("%lld%c",G[i][j]," \n"[j==n]); return 0; }
#include <bits/stdc++.h> using namespace std; #define _for(i,j,N) for(int i = (j);i < (N);i++) #define _rep(i,j,N) for(int i = (j);i <= (N);i++) #define ALL(x) x.begin(),x.end() #define pb push_back #define mk make_pair typedef long long LL; typedef pair<int,int> Interval; template<typename T> ostream& operator<<(ostream& os,const vector<T>& v) { _for(i,0,v.size()) os << v[i] << " "; return os; } template<typename T> ostream& operator<<(ostream& os,const set<T>& v){ for(typename set<T>::iterator it = v.begin();it != v.end();it++) os << *it <<" "; return os; } template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& v){ os << v.first <<" "<<v.second<<endl; return os; } const int maxn = 11; LL num = 1; LL bef = 0; int n; LL ans[maxn][maxn]; LL p[maxn]; set<int> si; set<int> sii; bool valid(int num){ for(int a:si){ if(si.count(num+a) || si.count(num) || sii.count(num) || sii.count(num+a)) return false; } return true; } map<LL,int> mp; LL check(vector<int> &vi){ LL ret = 0; _for(i,0,vi.size()-1){ ret += ans[vi[i]][vi[i+1]]; } return ret; } LL cal(int nn){ vector<int> vi; _for(i,0,nn){ vi.pb(i); } LL biggest = 0; do{ biggest = max(biggest,check(vi)); }while(next_permutation(ALL(vi))); return biggest; } int main() { scanf("%d",&n); num = 1; _for(i,0,n){ while(!valid(num)){ num++; } for(auto a:si){ sii.insert(a+num); } si.insert(num); p[i] = num; } num = 1; _for(i,1,n){ _for(j,0,i){ (ans[i][j] = ((ans[j][i]) = p[j] * num));; } num = cal(i+1) + 1; //cout <<"ok"<<endl; } //cout << cal(10) << endl; _for(i,0,n){ _for(j,0,n){ if(j) printf(" "); printf("%lld",ans[i][j]); } printf("\n"); } // cout << longest << endl; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef long double ld; #define mp make_pair mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll a[10][10]; ll b[100]; ll ans[20][20]; bool check(int m, int k) { set<ll> setik; for (int mask = 0; mask < (1 << m); mask++) { int cnt = 0; ll sum = 0; for (int i = 0; i < m; i++) { if ((mask >> i) & 1) { cnt++; sum += a[k][i]; } } if (k == 0) { if (cnt == 2) { if (setik.count(sum)) return false; setik.insert(sum); } } else { if (cnt <= k) { if (setik.count(sum)) return false; setik.insert(sum); } } } return true; } void checkAns(int n) { int p[20]; set<ll> setik; for (int i = 0; i < n; i++) { p[i] = i; } ll mx = 0; do { if (p[0] > p[n - 1]) continue; ll sum = 0; for (int i = 1; i < n; i++) sum += ans[p[i - 1]][p[i]]; if (setik.count(sum)) throw; setik.insert(sum); mx = max(mx, sum); } while(next_permutation(p, p + n)); cerr << (double)mx / 1e11 << endl; } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); for (int k = 0; k < 6; k++) { a[k][0] = 1; for (int i = 1; i < 10; i++) { for (ll x = a[k][i - 1] + 1;; x++) { a[k][i] = x; if (check(i + 1, k)) break; } } /* for (int i = 0; i < 10; i++) printf("%lld\t", a[k][i]); printf("\n"); */ } /* for (int i = 0; i <= 45; i++) { ll sum = 0; for (int j = max(0, i - 9); j < i; j++) sum += b[j]; b[i] = sum + 1; } cerr << (double)b[45] / 1e11 << endl; */ ll res = 1; for (int i = 0; i < 9; i++) { int k = 2; if (i == 5) k = 0; b[i] = (i > 0 ? a[k][i - 1] : 0) + a[k][i] + 1; res *= b[i]; } /* cerr << (double)res / 1e11 << endl; for (int i = 0; i < 9; i++) cerr << b[i] << " "; cerr << endl; */ int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int k = 2; if (i == 6) k = 0; ll p = 1; for (int j = 0; j < i - 1; j++) p *= b[j]; for (int j = 0; j < i; j++) ans[i][j] = ans[j][i] = a[k][j] * p; } // checkAns(n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) printf("%lld ", ans[i][j]); printf("\n"); } return 0; }
#include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<stack> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<bitset> #include<stdlib.h> #include<cassert> #include<time.h> #include<bitset> using namespace std; const long long mod=1000000007; const long long inf=mod*mod; const long long d2=(mod+1)/2; const long double EPS=1e-9; const long double PI=acos(-1.0); int ABS(int a){return max(a,-a);} long long ABS(long long a){return max(a,-a);} long double ABS(long double a){return max(a,-a);} long long g[20][20]; int perm[20]; int mag[]={1,2,4,7,12,20,29,38,52,73}; int main(){ int a;scanf("%d",&a); g[0][1]=g[1][0]=1; for(int i=3;i<=a;i++){ for(int j=0;j<i-1;j++)perm[j]=j; long long cur=0; do{ long long tmp=0; for(int j=0;j<i-2;j++){ tmp+=g[perm[j]][perm[j+1]]; } cur=max(cur,tmp); }while(next_permutation(perm,perm+i-1)); cur++; for(int j=0;j<i-1;j++){ // g[j][i-1]=g[i-1][j]=mag[i-2-j]*cur; g[j][i-1]=g[i-1][j]=mag[j]*cur; } } for(int i=0;i<a;i++){ for(int j=0;j<a;j++){ if(j)printf(" ");printf("%lld",g[i][j]); } printf("\n"); } }
#include <iostream> #include <vector> using namespace std; using ll = long long; const int N = 10; ll cost[N][N]; int main() { vector<vector<int>> xr = { {1}, {1,2}, {1,2,4}, {1,2,4,7}, {1,2,4,7,12}, {1,2,4,8,13,18}, {1,2,4,8,14,19,24}, {1,2,4,8,15,24,29,34}, {1,7,10,13,21,26,41,43,45} }; int n; cin >> n; ll b = 1; for (int i = 0; i+1 < n; ++i) { int ln = n-1-i; for (int j = i+1; j < n; ++j) { cost[i][j] = b * xr[ln-1][j-1-i]; cost[j][i] = cost[i][j]; } if (ln >= 2) b *= (1+xr[ln-1][ln-1]+xr[ln-1][ln-2]); } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cout << cost[i][j] << ' '; } cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; int main(){ int N; scanf("%d", &N); // N <= 9 can be easily solved using random weights. Only N=10 requires more thought if(N == 2){ printf("0 4200782951\n4200782951 0\n"); }else if(N == 3){ printf("0 595392113 3485670742\n595392113 0 3993409801\n3485670742 3993409801 0\n"); }else if(N == 4){ printf("0 111 157 193\n111 0 224 239\n157 224 0 258\n193 239 258 0"); }else if(N == 5){ printf("0 1120293596 1363411275 2695033576 291754917\n1120293596 0 2777187166 3912821471 2792178619\n1363411275 2777187166 0 1790344584 1794788877\n2695033576 3912821471 1790344584 0 3404614660\n291754917 2792178619 1794788877 3404614660 0\n"); }else if(N == 6){ printf("0 1547419313 3678796810 3419032095 2383395373 269101889\n1547419313 0 4137780530 2312578763 822741678 489322228\n3678796810 4137780530 0 3434072510 2267928371 2446355330\n3419032095 2312578763 3434072510 0 1926732053 439765232\n2383395373 822741678 2267928371 1926732053 0 1621238000\n269101889 489322228 2446355330 439765232 1621238000 0\n"); }else if(N == 7){ printf("0 3685533898 3309879430 42521343 2314944944 1256565514 3820379386\n3685533898 0 1757633705 3297135931 3791422498 2957445228 146685956\n3309879430 1757633705 0 1643871611 2850559186 466341128 984219233\n42521343 3297135931 1643871611 0 4125620415 3732072487 4009228811\n2314944944 3791422498 2850559186 4125620415 0 585048619 2998838566\n1256565514 2957445228 466341128 3732072487 585048619 0 4134564458\n3820379386 146685956 984219233 4009228811 2998838566 4134564458 0\n"); }else if(N == 8){ printf("0 563875800 1225318167 2972645697 1289032234 1129116426 1831367910 2475552129\n563875800 0 2369444361 83802213 2990813968 848577381 3881659247 2855810912\n1225318167 2369444361 0 1604039992 2940918157 4175936479 2816444489 635132575\n2972645697 83802213 1604039992 0 2614553284 3914586299 3796326189 3899806310\n1289032234 2990813968 2940918157 2614553284 0 1763008100 3401272316 3602081843\n1129116426 848577381 4175936479 3914586299 1763008100 0 3276476006 3466646881\n1831367910 3881659247 2816444489 3796326189 3401272316 3276476006 0 4253168046\n2475552129 2855810912 635132575 3899806310 3602081843 3466646881 4253168046 0\n"); }else if(N == 9){ printf("0 2941370754 4046762338 300037691 408459189 3602734362 3184708449 795303870 1201486887\n2941370754 0 3179271189 1947889707 2557790900 715944681 355015879 1729791022 459441371\n4046762338 3179271189 0 1691113181 3767977083 739061260 3307313601 56212245 1439886185\n300037691 1947889707 1691113181 0 2599344567 3766080836 2407782913 3448394576 232010982\n408459189 2557790900 3767977083 2599344567 0 215332527 1807157280 2069476376 3939369296\n3602734362 715944681 739061260 3766080836 215332527 0 3755033663 3219425845 4237361776\n3184708449 355015879 3307313601 2407782913 1807157280 3755033663 0 364719491 2967029607\n795303870 1729791022 56212245 3448394576 2069476376 3219425845 364719491 0 1739274572\n1201486887 459441371 1439886185 232010982 3939369296 4237361776 2967029607 1739274572 0\n"); }else if(N == 10){ // This one came from the explanation from Xellos in the Codeforces discussion page // I coded the idea and obtained this. printf("0 1 2 4 7 12 20 33 54 88\n1 0 143 286 572 1001 1716 2860 4719 7722\n2 143 0 12584 25168 50336 88088 151008 251680 415272\n4 286 12584 0 679536 1359072 2718144 4756752 8154432 13590720\n7 572 25168 679536 0 22424688 44849376 89698752 156972816 269096256\n12 1001 50336 1359072 22424688 0 448493760 896987520 1793975040 3139456320\n20 1716 88088 2718144 44849376 448493760 0 5381925120 10763850240 21527700480\n33 2860 151008 4756752 89698752 896987520 5381925120 0 37673475840 11855313354\n54 4719 251680 8154432 156972816 1793975040 10763850240 37673475840 0 28284057711\n88 7722 415272 13590720 269096256 3139456320 21527700480 11855313354 28284057711 0\n"); } }
#pragma GCC optimize("Ofast","inline") #include <bits/stdc++.h> #define clr(x) memset(x,0,sizeof x) #define For(i,a,b) for (int i=(a);i<=(b);i++) #define Fod(i,b,a) for (int i=(b);i>=(a);i--) #define fi first #define se second #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define outval(x) cerr<<#x" = "<<x<<endl #define outtag(x) cerr<<"---------------"#x"---------------"<<endl #define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\ For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl; using namespace std; typedef long long LL; typedef vector <int> vi; LL read(){ LL x=0,f=0; char ch=getchar(); while (!isdigit(ch)) f|=ch=='-',ch=getchar(); while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); return f?-x:x; } const int N=100; int n,m; LL g[N][N]; LL gg[N][N]; int a[N]; LL rand48(){ LL a=rand()&65535,b=rand()&65535,c=rand()&65535; return (a<<32)^(b<<16)^c; } unordered_map <LL,int> mp; int p[N]; bool check(int i){ For(j,1,i-1) For(k,j+1,i-1) if (a[j]+a[k]==a[i]) return 0; For(j,1,i-1) For(k,j+1,i-1) For(t,1,i-1) if (a[j]+a[k]==a[t]+a[i]) return 0; return 1; } LL ans[N*N]={0, 0,1,2,8,56,672,13440,443520,22176000,1507968000, 1,0,4,16,112,1344,26880,887040,44352000,3015936000, 2,4,0,32,224,2688,53760,1774080,88704000,6031872000, 8,16,32,0,392,4704,94080,3104640,155232000,10555776000, 56,112,224,392,0,8064,161280,5322240,266112000,18095616000, 672,1344,2688,4704,8064,0,268800,8870400,443520000,30159360000, 13440,26880,53760,94080,161280,268800,0,12862080,643104000,43731072000, 443520,887040,1774080,3104640,5322240,8870400,12862080,0,842688000,7313164692, 22176000,44352000,88704000,155232000,266112000,443520000,643104000,842688000,0,28424716692, 1507968000,3015936000,6031872000,10555776000,18095616000,30159360000,43731072000,7313164692,28424716692,0 }; int main(){ n=read(); if (n==10){ For(i,1,n){ For(j,1,n){ cout<<ans[(i-1)*n+j]<<" "; } cout<<endl; } return 0; } a[0]=0,a[1]=1; For(i,2,n-1){ a[i]=a[i-1]+1; while (!check(i)) a[i]++; } // outarr(a,1,n-1); LL tmp=1; For(i,2,n){ For(j,1,i-1) gg[i][j]=gg[j][i]=tmp*a[j]; tmp*=a[i-1]+a[i-2]+1; } while (1){ int flag=1; LL mod=rand48()%100000000LL+49900000000LL; For(i,1,n) For(j,1,n) g[i][j]=gg[i][j]%mod; For(i,1,n) For(j,i+1,n) if (!g[i][j]) flag=0; if (flag){ mp.clear(); For(i,1,n) p[i]=i; do { if (p[1]>p[n]) continue; LL tot=0; For(i,1,n-1) tot+=g[p[i]][p[i+1]]; if (tot>100000000000LL||mp[tot]){ flag=0; break; } mp[tot]++; } while (next_permutation(p+1,p+n+1)); } if (flag){ For(i,1,n){ For(j,1,n){ cout<<g[i][j]<<" "; } cout<<endl; } break; } } return 0; }
#include <bits/stdc++.h> #define debug(...) fprintf(stderr, __VA_ARGS__) #ifndef AT_HOME #define getchar() IO::myGetchar() #define putchar(x) IO::myPutchar(x) #endif namespace IO { static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23; inline char myGetchar() { static char buf[IN_BUF], *ps = buf, *pt = buf; if (ps == pt) { ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin); } return ps == pt ? EOF : *ps++; } template<typename T> inline bool read(T &x) { bool op = 0; char ch = getchar(); x = 0; for (; !isdigit(ch) && ch != EOF; ch = getchar()) { op ^= (ch == '-'); } if (ch == EOF) { return false; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + (ch ^ '0'); } if (op) { x = -x; } return true; } inline int readStr(char *s) { int n = 0; char ch = getchar(); for (; isspace(ch) && ch != EOF; ch = getchar()) ; for (; !isspace(ch) && ch != EOF; ch = getchar()) { s[n++] = ch; } s[n] = '\0'; return n; } inline void myPutchar(char x) { static char pbuf[OUT_BUF], *pp = pbuf; struct _flusher { ~_flusher() { fwrite(pbuf, 1, pp - pbuf, stdout); } }; static _flusher outputFlusher; if (pp == pbuf + OUT_BUF) { fwrite(pbuf, 1, OUT_BUF, stdout); pp = pbuf; } *pp++ = x; } template<typename T> inline void print_(T x) { if (x == 0) { putchar('0'); return; } static int num[40]; if (x < 0) { putchar('-'); x = -x; } for (*num = 0; x; x /= 10) { num[++*num] = x % 10; } while (*num){ putchar(num[*num] ^ '0'); --*num; } } template<typename T> inline void print(T x, char ch = '\n') { print_(x); putchar(ch); } inline void printStr_(const char *s, int n = -1) { if (n == -1) { n = strlen(s); } for (int i = 0; i < n; ++i) { putchar(s[i]); } } inline void printStr(const char *s, int n = -1, char ch = '\n') { printStr_(s, n); putchar(ch); } } using namespace IO; const int N = 10; const int f[] = {1, 2, 4, 7, 12, 20, 29, 38, 52}; int n, p[N]; long long w[N][N]; int main() { read(n); long long mx = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { w[i][j] = w[j][i] = (mx + 1) * f[j]; } mx = 0; for (int j = 0; j <= i; ++j) { p[j] = j; } while (1) { long long sum = 0; for (int j = 1; j <= i; ++j) { sum += w[p[j - 1]][p[j]]; } mx = std::max(mx, sum); if (!std::next_permutation(p, p + i + 1)) { break; } } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { print(w[i][j], ' '); } putchar('\n'); } debug("%lld\n", mx); }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; // #define int long long // #define double long double #define rep(i,n) for (int i=0; i<(int)(n); ++i) #define rep1(i,n) for (int i=1; i<(int)(n); ++i) #define repeq(i,n) for (int i=0; i<=(int)(n); ++i) #define rep1eq(i,n) for (int i=1; i<=(int)(n); ++i) #define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i) #define rrep1(i,n) for (int i=(int)(n)-1; i>0; --i) #define rrepeq(i,n) for (int i=(int)(n); i>=0; --i) #define rrep1eq(i,n) for (int i=(int)(n); i>0; --i) #define REP(i,a,b) for (int i=(int)(a); i<=(int)(b); ++i) #define RREP(i,a,b) for (int i=(int)(a); i>=(int)(b); --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; template<typename T> using Graph = vector<vector<T>>; template<typename T> using Spacial = vector<vector<vector<T>>>; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>; const int MOD = 1e9+7; const int MOD2 = 998244353; // const double EPS = 1e-9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; string interval[2] = {" ", "\n"}; // {" ", "\n"} template<typename T> struct is_plural : false_type{}; template<typename T1, typename T2> struct is_plural<pair<T1, T2>> : true_type{}; template<typename T> struct is_plural<vector<T>> : true_type{}; template<typename T> struct is_plural<complex<T>> : true_type{}; template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << " " << p.second; } template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { if (vec.empty()) return os; bool pl = is_plural<T>(); os << vec.front(); for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) os << interval[pl] << *itr; return os; } bool CoutYN(bool a, string y = "Yes", string n = "No") { cout << (a ? y : n) << "\n"; return a; } template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } long long modpow(int a, long long n, int mod = MOD) { long long ret = 1; do { if (n & 1) ret = ret * a % mod; a = 1LL * a * a % mod; } while (n >>= 1); return ret; } template<typename T> T GCD(T a, T b) { return b ? GCD(b, a%b) : a; } template<typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; } template<typename T1, typename T2> bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) { return a.second != b.second ? a.second < b.second : a.first < b.first; } template<typename T1, typename T2> bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) { return a.first != b.first ? a.first < b.first : a.second > b.second; } /* -------- <templates end> -------- */ void solve() { int n; cin >> n; Graph<ll> ans(n, vl(n)); /* auto check = [&]() { vi vec(n); iota(ALL(vec), 0); set<ll> s, t; do { ll dist = 0; rep1(i,n) dist += ans[vec[i]][vec[i-1]]; if (!s.count(dist)) s.emplace(dist); else if (!t.count(dist)) t.emplace(dist); else { cout << "Impossible\n"; return; } } while (next_permutation(ALL(vec))); cout << "Possible\n" << *rbegin(s) << endl; }; */ if (n < 10) { ll num = 1; rep1(i,n) { rep(j,i) { ans[i][j] = ans[j][i] = num; num <<= 1; } } // check(); cout << ans << endl; return; } vi calc(10); calc[0] = 1, calc[1] = 2; REP(i,2,9) calc[i] = calc[i-1] + calc[i-2] + 1; ll num = 1; ll sum = 0; ll pro = 6; rep1(i,10) { rep(j,i) { ans[i][j] = ans[j][i] = num * calc[j]; } if (i == 1) num = 2; else { sum += ans[i][i-2]; pro *= calc[i-2]; num = sum + ans[i][i-1] + 5 - pro; } } // check(); cout << ans << endl; } /* -------- <programs end> -------- */ signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); solve(); return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; int main() { int n; cin>>n; ll a[12]; a[0]=1, a[1]=2; set<ll> st; st.insert(1); st.insert(2); st.insert(3); for(int i=2; i<=n; i++){ for(a[i]=a[i-1]+1; ; a[i]++){ if(st.find(a[i])!=st.end()) continue; bool ok=1; for(int j=0; j<i; j++){ if(st.find(a[j]+a[i])!=st.end()){ ok=0; break; } } if(ok){ st.insert(a[i]); for(int j=0; j<i; j++) st.insert(a[j]+a[i]); break; } } } ll w[12][12]={}; w[0][1]=w[1][0]=1, w[0][2]=w[2][0]=2, w[1][2]=w[2][1]=3; ll m=5; for(int i=3; i<n; i++){ for(int j=0; j<i; j++) w[j][i]=w[i][j]=(m+1)*a[j]; vector<int> v(i+1); for(int j=0; j<=i; j++) v[j]=j; while(1){ ll s=0; for(int j=0; j<i; j++){ s+=w[v[j]][v[j+1]]; } m=max(m, s); if(!next_permutation(v.begin(), v.end())) break; } } //cerr<<m<<endl; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cout<<w[i][j]<<" "; } cout<<endl; } return 0; }
// ==================================== // author: M_sea // website: https://m-sea-blog.com/ // ==================================== #include <bits/stdc++.h> using namespace std; typedef long long ll; int read() { int X=0,w=1; char c=getchar(); while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); } while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar(); return X*w; } const int N=10+10; const int a[11]={0,1,2,4,7,12,20,29,38,53,73}; int n,tot,vis[N]; ll M,G[N][N]; void dfs(int u,int d,ll l) { if (d>tot) { M=max(M,l); return; } for (int i=1;i<=tot;++i) if (!vis[i]) vis[i]=1,dfs(i,d+1,l+G[u][i]),vis[i]=0; } int main() { n=read(); for (int i=2;i<=n;++i) { for (int j=1;j<i;++j) G[i][j]=G[j][i]=(M+1)*a[j]; tot=i,dfs(0,1,0); } for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) printf("%lld%c",G[i][j]," \n"[j==n]); return 0; }
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<map> #define ll long long #define mod 998244353 #define maxn 200010 inline ll read() { ll x=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; return x*f; } inline void write(ll x) { static int buf[20],len; len=0; if(x<0)x=-x,putchar('-'); for(;x;x/=10)buf[len++]=x%10; if(!len)putchar('0'); else while(len)putchar(buf[--len]+'0'); } inline void writeln(ll x){write(x); putchar('\n');} inline void writesp(ll x){write(x); putchar(' ');} ll cnt[30],base[30],now[30]; int a[30],mx[30],v[1010]; ll mp[15][15]; int n; std::map<ll,int>mark; int vis[maxn]; int dfs(int S,int now,int dep,int n,ll dis) { if(dep==n&&now>S){ if(mark[dis])return 0; mark[dis]=1; return 1; } for(int i=1;i<=n;i++) if(!vis[i]){ vis[i]=1; if(!dfs(S,i,dep+1,n,dis+mp[now][i]))return 0; vis[i]=0; } return 1; } ll calc(int n) { mark.clear(); mark[0]=1; memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++){ vis[i]=1; dfs(i,i,1,n,0); vis[i]=0; } return (*(--mark.end())).first; } int check() { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i==j&&mp[i][j])return 0; else if(i!=j&&(mp[i][j]<1||mp[i][j]>1e11))return 0; int flag=1; mark.clear(); memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++){ vis[i]=1; flag&=dfs(i,i,1,n,0); vis[i]=0; } return flag&&calc(n)<=1e11; } int main() { n=read(); int k=1; a[0]=0; for(int i=1;i<=n;i++){ while(1){ int flag=1; for(int j=0;j<i;j++) if(v[k+a[j]])flag=0; if(flag)break; ++k; } a[i]=k; for(int j=0;j<i;j++) v[a[i]+a[j]]=1; } // for(int i=1;i<=n;i++) // printf("%d %d ***\n",i,a[i]); for(int i=2;i<=n;i++){ ll mx=calc(i-1)+1; for(int j=1;j<i;j++) mp[i][j]=mp[j][i]=mx*a[j]; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) writesp(mp[i][j]); putchar('\n'); } // puts(check()?"AC":"WA"); return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s, t = "keyence"; cin >> s; for (int i = 0; i < s.length(); i++) { for (int j = i - 1; j < s.length(); j++) { if (s.substr(0, i) + s.substr(j + 1, s.length() - j + 1) == t) { cout << "YES" << endl; return 0; } } } cout << "NO" << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string s; cin >> s; int n = s.length()-7; bool iFlg = false; for(int i=0;i<7;i++){ string ans = s.substr(0, i) + s.substr(i+n); if(ans == "keyence"){ iFlg = true; break; } } (iFlg)? ( cout << "YES"): (cout << "NO") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int x = S.size(); string S_new; for(int i=0; i<8; i++){ S_new = S; S_new.erase(i, x-7); if(S_new=="keyence"){ cout << "YES"; return 0; } } cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, k = "keyence"; cin >> s; for (int i = 0; i < 8; i++) { if (s.substr(0, i) == k.substr(0, i) && s.substr(s.length() + i - 7) == k.substr(i)) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include<iostream> #include<string> using namespace std; int main(){ string str; cin >> str; int i=0; for(i=0;i<8;i++){ if(str.substr(0,7-i)+str.substr(str.size()-i,i)=="keyence"){ cout << "YES\n"; break; } } if(i==8) cout << "NO\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if(s.substr(0,7)=="keyence"||s.substr(s.size()-7,7)=="keyence") { cout << "YES" << endl; return 0; } for(int i=1; i<=6; i++){ if(s.substr(0,i)+s.substr(s.size()-(7-i),7-i)=="keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std ; #define rep(i,n) for( int i = 0 ; i < n ; i++ ) typedef long long ll ; int main(){ string s ; cin >> s ; string t = "keyence" ; rep(i,s.size()){ rep(j,s.size()){ string u = s ; if( u.erase(i,j) == t ){ cout << "YES" << endl; return 0 ; } } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string t = "keyence"; string s; cin >> s; int a = 0, b = 0; while (a < s.size() && a < t.size() && s[a] == t[a]) a++; while (b < s.size() && b < t.size() && s[s.size() - 1 - b] == t[t.size() - 1 - b]) b++; cout << (a + b >= t.size() ? "YES" : "NO") << endl; }
#include<bits/stdc++.h> using namespace std; #define maxn 120 char S[maxn]; int main(){ cin >> S; const char *s = "keyence"; int n = strlen(S); int i = 0; while(i < 7 && s[i] == S[i]) i += 1; int j = 0; while(j < 7 && s[6 - j] == S[n - j - 1]) j += 1; cout << (i + j >= 7 ? "YES" : "NO"); }
#include <bits/stdc++.h> using namespace std; #define int long long int int32_t main(){ string s;cin>>s; string key = "keyence"; for(int i=0;i<=7;i++){ if(s.substr(0,i)+s.substr(s.length()-7+i)==key){ cout<<"YES";return 0; } } cout<<"NO"; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin>>s; for(int i=0;i<s.size();i++) { for(int j=0;j<s.size()-i;j++) { string t=s; t.erase(i,j); if(t=="keyence") { cout<<"YES"<<endl; return 0; } } } cout <<"NO"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); ++i) for (int j = i; j < s.size(); ++j) { if (s.substr(0, i) + s.substr(j, s.size() - j) == "keyence") { puts("YES"); return 0; } } puts("NO"); }
#include <bits/stdc++.h> #define r(i,n) for(int i = 0; i<n; i++) typedef long long ll; using namespace std; int main(){ string s,a,b; bool flag=false; cin >> s; r(i,8){ a=s.substr(0,i); b=s.substr(s.length()-7+i,7-i); if(a+b=="keyence"){ cout << "YES"<<endl; flag=true; break; } } if(!flag)cout << "NO"<<endl; }
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; bool res = 0; for (int i = 0; i <= 7; ++i) { string t; for (int j = 0; j < i; ++j) t += s[j]; for (int j = i; j < 7; ++j) t += s[s.size() - 7 + j]; if (t == "keyence") res = 1; } if (res) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; for (int i=0; i<s.size(); i++){ for (int j=i; j<s.size(); j++){ string check = s.substr(0,i) + s.substr(j); if (check == "keyence") { cout << "YES" << endl; return 0; } } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ string S,T="keyence";cin>>S; int i; for(i=0;i<8;i++){ if(S.substr(0,i)==T.substr(0,i)&&S.substr(S.size()+i-7,7-i)==T.substr(i,7-i))break; } if(i==8)cout<<"NO"<<endl; else cout<<"YES"<<endl; }
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; if (S == "keyence") { cout << "YES" << endl; return 0; } for (int i = 0; i < S.length(); i++) { for (int j = 1; i + j < S.length(); j++) { string T = S; T.erase(i, j); if (T == "keyence") { cout << "YES" << endl; return 0; } } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int n = s.length(); for(int i=0; i<=7; i++){ string test = s.substr(0,i) + s.substr(n-7+i,7-i); if(test == "keyence"){ cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include<iostream> #include<algorithm> using namespace std; int main() { char s[1020]; char c[] = "keyence"; cin >> s; int j = 0, k = 0; for (j = 0; s[j] != '\0'; j++); int i; for (i = 0;i<7; i++) { if (s[i] != c[i])break; } for (k = 0; k < 7; k++) { if (s[j-k-1] != c[7-k-1])break; } if (i == 7||k==7||i+k>=7)cout << "YES"; else cout << "NO"; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0;i<(ll)n;++i) int main(){ string s; cin >> s; ll n = s.size()-7; for(ll i=0;i<8;++i){ string j = s.substr(0,i) + s.substr(i+n); //cout << j << "\n"; if( j == "keyence" ){ puts("YES"); return 0; } } puts("NO"); return 0; }
#include <iostream> #include <string> using namespace std; string s; string st="keyence"; int main() { cin >>s; for (int i=1;i<=7;i++) { string a=st.substr(0,i); string b=st.substr(i); //cout <<a<<" "<<b<<"\n"; if (s.substr(0,i)==a && s.substr(s.size()-7+i)==b) { cout <<"YES"; return 0; } } cout <<"NO"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size() - 7; for (int i = 0; i < S.size() - N + 1; i++) { string s1 = S.substr(0, i); string s2 = S.substr(i + N); if (s1 + s2 == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s; cin>>s; string k = "keyence"; int n = s.length(); bool flag = false; for(int i=0; i<=7; i++) { string t = s.substr(0,(7-i)) + s.substr(n-i,i); if(k == t) flag = true; } if(flag) cout<<"YES"<<"\n"; else cout<<"NO"<<"\n"; }
#include <iostream> #include <algorithm> #include <string> using namespace std; signed main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { for (int j = i; j < s.size(); j++) { if (s.substr(0, i) + s.substr(j, s.size() - j) == "keyence") { cout << "YES\n"; return 0; } } } cout << "NO\n"; }
#include <bits/stdc++.h> #include <math.h> using namespace std; int main() { string s; cin >> s; int l = s.size(); for (int i = 0; i <= 7; i++) { if (s.substr(0, i) + s.substr(l - 7 + i, 7 - i) == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; int m = S.size(); string s_tmp; for(int i = 0; i <= m; ++i){ for(int j = i; j <= m; ++j){ s_tmp = S.substr(0, i) + S.substr(j); if(s_tmp == "keyence"){ cout << "YES" << endl; return 0; } } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main(){ string s; cin >> s; string u="keyence",ans="NO"; int l=s.size(); for(int i=0;i<l;i++){ for(int j=0;j<=l-i-1;j++){ string cp=s; cp=cp.erase(i,j); if(u==cp){ ans="YES"; } } } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s; int n=s.size(); for(int i=0; i<=n; i++) { for(int j=0; j<=n; j++) { string t=s; if(t.erase(i,j)=="keyence") { cout<<"YES"<<endl; return 0; } } } cout<<"NO"<<endl; return 0; }
#include<iostream> #include<string> using namespace std; int main(){ string s; cin>>s; string ans="NO",t="keyence"; for(int i=0;i<=7;i++){ if(s.substr(0,i)==t.substr(0,i)&&s.substr(s.length()-7+i,7-i)==t.substr(i,7-i)) ans="YES"; } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; using lli = long long; #define rep(i,n) for(int i=0;i<n;i++) string s; int main(void){ cin >> s; int n = s.size(); bool ans = false; rep(i, n){ rep(j, n){ if(j < i) continue; if(s.substr(0, i)+s.substr(j) == "keyence") ans = true; } } if(ans) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <string> #include <iostream> using namespace std; int main() { string s; cin >> s; bool ok = false; for (int i = 0; i <= 7; ++i) { if (s.substr(0, i) == string("keyence").substr(0, i) && s.substr(s.size() - (7 - i)) == string("keyence").substr(i)) { ok = true; } } cout << (ok ? "YES" : "NO") << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ string s; cin>>s; int n=s.size(); for(int i=0;i<=7;i++){ string t=s.substr(0,i)+s.substr(n-7+i); if(t=="keyence"){ cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string S,keyence; int sizedif; cin>>S; keyence="keyence"; sizedif=S.size()-7; for(int k=0;k<7;k++){ if(S.at(k)!=keyence.at(k)){ if(S.compare(k+sizedif,7-k,keyence,k,7-k)==0) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ string S;cin>>S; int N=S.size(),flag=1; string sample; for(int i=0;i<7;i++){ sample=S.substr(0,i)+S.substr(N-7+i,7-i); if(sample=="keyence")flag=0; } if(S.substr(0,7)=="keyence")flag==0; if(flag==0)cout<<"YES"<<endl; else cout<<"NO"<<endl; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ int i,j,cnt=0; string s; cin>>s; for(i=0;i<=7;i++){ if(s.substr(0,i)+s.substr(s.size()-(7-i),7-i)=="keyence"){ cout<<"YES"; return 0; } } cout<<"NO"; }
#include <iostream> #include <string> using namespace std; int main(){ string s; string t = "keyence"; cin >> s; for (int i = 1; i <= 7 ; i++) { string s1 = s.substr(0, i); string s2 = s.substr(s.size() - 7 + i); string s3 = s1 + s2; if (t == s3) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; cout<<(regex_match(s,regex(".*keyence|k.*eyence|ke.*yence|key.*ence|keye.*nce|keyen.*ce|keyenc.*e|keyence.*"))?"YES":"NO")<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int N = S.size(); string str = "keyence"; int M = str.size(); bool res = false; for (int i = 0; i <= M; i++){ if (S.substr(0, i) == str.substr(0, i)){ if (S.substr(N - M + i, M - i) == str.substr(i, M - i)){ res = true; } } } cout << (res ? "YES" : "NO"); }
#include <iostream> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) for (int j = i; j < s.size(); j++) { if (s.substr(0, i) + s.substr(j, s.size()-j) == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }
// B - KEYENCE String #include <bits/stdc++.h> using namespace std; #define rp(i,s,e) for(int i=(s);i<(e);++i) int main(){ string s,t="keyence"; cin>>s; int sn = s.size(), tn = t.size(); rp(L, 0, tn){ string r; int R = sn - (tn-L) - 1; rp(m, 0, sn) if(m < L || R < m) r += s[m];//delete [L,R] if(r == t){ puts("YES"); return 0; } } puts("NO"); }
#include<iostream> #include<algorithm> #include<string> using namespace std; int main(){ string s,x,a="keyence"; cin>>s; int n=s.length(); int f=0; for(int i=0;i<=7;i++){ x=s.substr(0,i)+s.substr(n-7+i,7-i); if(x==a) f=1; } if(f) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; bool ans = false; for (int i = 0; i < S.size(); i++) { for (int j = i; j < S.size(); j++) { string sub = S.substr(0, i) + S.substr(j); if (sub == "keyence") { ans = true; break; } } } cout << (ans ? "YES" : "NO") << endl; }
#include<bits/stdc++.h> using namespace std; string s,t,a="keyence"; int i; bool fl; int main(){ cin>>s; fl=s==a; for(int i=0;i<a.size();++i){ t=s;t.erase(i,s.size()-a.size()); if(t==a)fl=1; } puts(fl?"YES":"NO"); return 0; }
#include<iostream> #include<algorithm> #include<cmath> #include<cstdio> #include<string> #include<vector> using namespace std; int main(void){ ios::sync_with_stdio(false); cin.tie(0); string s; int i; cin>>s; for(i=0;i<7;i++){ if(s.substr(0,i)+s.substr(s.length()-7+i)=="keyence"){ cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string s; cin>>s; int flag=0; for(int i=0;i<s.length();i++){ for(int j=0;j<s.length()-i;j++){ string s1 = s; s1.erase(i,j); if(s1=="keyence"){ flag=1; break; } } } if(flag) cout<<"YES\n"; else cout<<"NO\n"; }
#include <iostream> #include <string> int main() { std::string s; std::cin >> s; for (int i = 0; i < s.size(); ++i) { for (int j = i; j <= s.size(); ++j) { if (s.substr(0, i) + s.substr(j, s.size() - j) == "keyence") { puts("YES"); return 0; } } } puts("NO"); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; bool ok=false; int n=s.size(); for(int i=0;i<=n-7;i++){ if(s.substr(i,7)=="keyence") ok=true; } for(int i=1;i<=6;i++){ if(s.substr(0,i)+s.substr(n-7+i,7-i)=="keyence") ok=true; } if(ok) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
#include <bits/stdc++.h> using namespace std; int main () { string S, key = "keyence"; cin >> S; for(int i = 0; i < S.size(); i++){ for(int j = 0; j <= S.size() - i; j++){ if((S.substr(0, i) + S.substr(i + j, S.size() - j)) == key){ cout << "YES" << endl; return 0; } } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> char s1[110],s2[10]="keyence"; int n,i,j,k; int main() { scanf("%s",s1); n=strlen(s1); for (i=0;(i<7) && (s1[i]==s2[i]);i++); for (j=1;(n-j>=0) && (7-j>=0) && (s1[n-j]==s2[7-j]);j++); k=i+j-1; if (k>=7) printf("YES"); else printf("NO"); return 0; }