QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#55321#4855. Puzzle: X-Sums Sudokuzhoukangyang#AC ✓132ms3736kbC++112.5kb2022-10-13 09:43:322022-10-13 09:43:33

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-13 09:43:33]
  • 评测
  • 测评结果:AC
  • 用时:132ms
  • 内存:3736kb
  • [2022-10-13 09:43:32]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int > 
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
#define I __int128_t
using namespace std;
const int N = 5007;

int n, m, a[N][N];
void draw() {
	L(i, 0, (1 << n) - 1) {
		a[0][i] = i + 1; 
	}
	int li = 1, lj = 1 << n;
	L(t, 1, m) {
		L(i, 0, li - 1) {
			L(j, 0, lj - 1) {
				a[i + li][j + lj] = a[i][j];
				a[i + li][j] = a[i][j] + lj;
				a[i][j + lj] = a[i][j] + lj;
			}
		}
		li *= 2, lj *= 2;
	}
	li = 1 << m;
	L(t, 0, n - 1) {
		L(i, 0, li - 1) {
			L(j, 0, (1 << (n + m)) - 1) {
				a[i + li][j] = a[i][j ^ (1 << t)];
			}
		}
		li <<= 1;
	}
	L(i, 0, (1 << (n + m)) - 1) {
		L(j, 0, (1 << (n + m)) - 1) {
			cout << (j ^ (i >> m) ^ ((i & ((1 << m) - 1)) << n)) + 1 << ' ';
		}
		cout << '\n';
	}
}

ll x, lim;
I ns;
void print(I a) {
	if(a > 9) print(a / 10);
	cout << ((int) (a % 10));
}
string s;

inline ll get(ll x, ll y) {
	return y ^ (x >> n) ^ ((x & ((1LL << n) - 1)) << m);
}
I A(ll x, ll y) {
	I ns = 0;
	for(; x; ) {
		ll lw = x & -x, c = lw - 1;
		x -= lw;
		ll cur = x ^ (y >> n) ^ ((y & ((1LL << n) - 1)) << m);
		I a = cur ^ (cur & c);
		ns += (I) a * lw, ns += (I) c * lw / 2;
	}
	return ns;
}
I B(ll x, ll y) {
	I ns = 0;
	for(; x; ) {
		ll lw = x & -x, c = lw - 1;
		x -= lw;
		ll cur = y ^ (x >> n) ^ ((x & ((1LL << n) - 1)) << m);
		c = (c >> n) ^ ((c & ((1LL << n) - 1)) << m);
		I a = cur ^ (cur & c);
		ns += (I) a * lw;
		ns += (I) c * lw / 2;
	}
	return ns;
}

void Main() {
	cin >> n >> m >> s >> x, --x, lim = (1LL << (n + m)) - 1;
	ns = 0;
	if(s == "top") {
		ll w = get(0, x);
		ns += w + 1 + B(w + 1, x);
	} else if(s == "bottom") {
		ll w = get(lim, x);
		ns += w + 1 + (I) lim * (lim + 1) / 2 - B(lim - w, x);
	} else if(s == "left") {
		ll w = get(x, 0);
		ns += w + 1 + A(w + 1, x);
	} else if(s == "right") {
		ll w = get(x, lim);
		ns += w + 1 + (I) lim * (lim + 1) / 2 - A(lim - w, x);
	}
	print(ns), cout << '\n';
//	L(i, 0, (1 << (n + m)) - 1) {
//		L(j, 0, (1 << (n + m)) - 1) {
//			cout << get(i, j) << ' ';
//		}
//		cout << '\n';
//	}
}

int main() {
//	return system("fc B.out A.out"), 0;
//	freopen("B.out", "w", stdout);
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	while(t--) Main();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3556kb

input:

4
2 1 top 1
2 1 bottom 2
2 1 left 3
2 1 right 4

output:

1
34
27
3

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

4
11 19 top 1053766555
12 26 top 230781535210
14 10 right 8344647
7 30 right 70120568170

output:

565741033271081135
31719572400444316026492
112693473538824
477453505821905419941

result:

ok 4 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 3720kb

input:

1
1 1 right 1

output:

10

result:

ok single line: '10'

Test #4:

score: 0
Accepted
time: 132ms
memory: 3516kb

input:

100000
20 29 top 257095114618907
13 23 left 54481547025
12 30 left 3617852247968
9 2 top 336
29 5 top 4512541036
11 20 top 1441537922
11 22 bottom 663925222
22 6 bottom 161962542
10 10 top 623031
1 13 right 13855
29 2 right 814001609
7 21 top 258317404
12 16 right 127899460
2 12 right 2608
21 24 bot...

output:

72365878684739299349500249330
588017022058838439666
9662552090602663949581947
239776
37869457663672028144
1548057695947494022
34042524198475305980
14205938085912676
326660065713
102273529
574770226186886766
34663716399392240
27135914299638562
7972435
488424528027186861329373749
852
105967175721525
2...

result:

ok 100000 lines