ARC138D 代码求调
  • 板块学术版
  • 楼主xzCyanBrad
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/4/10 19:06
  • 上次更新2023/10/28 04:02:58
查看原帖
ARC138D 代码求调
380730
xzCyanBrad楼主2022/4/10 19:06

RT


//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define Rep(i, n) for(int i=0; i< (int)(n); i++)
#define Rpp(i, n) for(int i=1; i<=(int)(n); i++)
#define Drp(i, n) for(int i=(int)n-1; ~i; i--)
#define Dpp(i, n) for(int i=(int)n; i; i--)
#define Rco(it, cont) for(const auto& it : cont)
#define For(i, s, e) for(int i=(int)(s); i< (int)(e); i++)
#define Frr(i, s, e) for(int i=(int)(s); i<=(int)(e); i++)
#define Tc int T; cin >> T; while(T--)
#define Eps 1e-7
#define Pinf 0x3f3f3f3f3f3f3f3fLL
#define Ninf 0xcfcfcfcfcfcfcfcfLL
#define Mem0(Cont) memset(Cont, 0, sizeof(Cont))
#define MemP(Cont) memset(Cont, 0x3f, sizeof(Cont))
#define MemN(Cont) memset(Cont, 0xcf, sizeof(Cont))
#define endl '\n'
#define int long long
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define yes cout << "yes\n"
#define no cout << "no\n"
//#define Files
using namespace std;

inline bool CheckMax(int& x, int y) { if(x < y) { x = y; return 1; } else return 0; }
inline bool CheckMin(int& x, int y) { if(x > y) { x = y; return 1; } else return 0; }
template <typename T> inline void Print(T x, char ed = '\n') { cout << x << ed; }
template <typename T> inline void Exit(T x, int cd = 0) { cout << x << endl; exit(cd); }

int Pow(int n)
{
	int res = 1;
	while(n--) res <<= 1;
	return res;
}

string Main(int n, int k)
{
	if(n == 0) return "";
	int m = Pow(n-1);
	if(k <= m) return '0' + Main(n-1, k);
	string s = Main(n-1, 2*m - k + 1);
	return '1' + s;
}

int gray[1 << 19], kbt[1 << 19];

signed main()
{
#ifdef Files
	freopen(".in", "r", stdin);
	freopen(".out", "w",stdout);
#endif
	ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, k; cin >> n >> k;
	if(k % 2 == 0 || (n > 1 && k == n))
		Exit("No");
	Yes; Rpp(i, 1<<n)
	{
		string s = Main(n, i);
		bitset <60> b(s);
		gray[i] = (int)b.to_ulong();
//		cout << s << ' ' << gray[i] << endl;
	}
	int now = (1<<k)-1, cnt = 0;
	while(now < (1<<n))
	{
//		cout << now << ' ' << (bitset<10>(now)).to_string() << endl;
		kbt[cnt++] = now;
		int a = now, b = a & -a,
			c = a + b, d = c ^ a,
			e = (d / b) >> 2, f = e | c;
		now = f;
	}
	Rpp(i, 1<<n)
	{
		int b = gray[i], res = 0;
		for(int j=0; 1<<j<=b; j++)
			if(b & 1<<j) res ^= kbt[j+1];
//		cout << endl;
		cout << res << ' ';
	} cout << endl;

	return 0;
}

WA 7 个点,6 3 是错的

2022/4/10 19:06
加载中...