Topic links
Suppose you can always find a state so that the value is 0, then two 1 requires the number of n-2, two 2 between the number of n-3, two 3 of the interval n-4 number. We found that two of the three can be placed between two 1, the same as two 5 put to two 3 .... So it's structured.
#include <iostream>#include<vector>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<Set>#include<string>#include<queue>#include<stack>#include<bitset>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<1|1#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };inta[1000005];intMain () {intN; CIN>>N; intL =1, r = N, cnt =1; while(r>l) {a[l+ +] = cnt, a[r--] =CNT; CNT+=2; } l= n+1, R = l+n-2, cnt =2; while(r>l) {a[l+ +] = cnt, a[r--] =CNT; CNT+=2; } for(inti =1; i<=2*n; i++) { if(A[i]) printf ("%d", A[i]); Elseprintf ("%d", N); } return 0;}
Codeforces 622. Optimal Number permutation construction