QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750674#9745. 递增序列lonelywolf#WA 38ms3664kbC++201.7kb2024-11-15 15:27:152024-11-15 15:27:16

Judging History

This is the latest submission verdict.

  • [2024-11-15 15:27:16]
  • Judged
  • Verdict: WA
  • Time: 38ms
  • Memory: 3664kb
  • [2024-11-15 15:27:15]
  • Submitted

answer

#include <bits/stdc++.h>  
using namespace std;  

#define int long long  

void solve() {
	int n, k;
	cin >> n >> k;

	array<int, 60> a, b;
	a.fill(-1);
	b.fill(0);

	bool ok = true;
	int lst = 0;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		if (i != 1) {
			for (int j = 60; j >= 0; j--) {
				if ((x >> j & 1) == (lst >> j) & 1) {
					continue;
				}
				if (x >> j & 1) {
					if (a[j] == 1) {
						ok = false;
					}
					a[j] = 0;
				} else {
					if (a[j] == 0) {
						ok = false;
					}
					a[j] = 1;
				}
				break;
			}
		}
		lst = x;
	}

	if (!ok) {
		cout << 0 << "\n";
		return;
	}

	for (int i = 0; i < 60; i++) {
		if (a[i] != -1) {
			b[i] = 1;
		}
		if (i) {
			b[i] += b[i - 1];
		}
	}

	// for (int i = 0; i < 5; i++) {
	// 	cout << a[i] << " ";
	// }
	// cout << "\n";
	// for (int i = 0; i < 5; i++) {
	// 	cout << b[i] << " ";
	// }
	// cout << "\n";
	
	array<int, 60> ans;
	ans.fill(-1);
	auto dfs = [&](auto self, int d, bool flg) -> int {
		// cout << d << " " << flg << "\n";
		if (d == -1) {
			return 1;
		}
		if (!flg) {
			return 1LL << (d + 1 - b[d]);
		}
		if (ans[d] != -1) {
			return ans[d];
		}
		int ret = 0;
		if (a[d] != 0 && (k >> d & 1)) {
			ret += self(self, d - 1, true);
		}
		if (a[d] != 1) {
			if (k >> d & 1) {
				ret += self(self, d - 1, false);
			} else {
				ret += self(self, d - 1, true);
			}
		}
		return ans[d] = ret;
	};

	cout << dfs(dfs, 59, true) << "\n";
}

signed main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

    int t;
    cin >> t;
    while (t--) {
    	solve();
    }

    return 0;
}  
  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3664kb

input:

1
4 17
3 2 5 16

output:

4

result:

ok single line: '4'

Test #2:

score: -100
Wrong Answer
time: 38ms
memory: 3604kb

input:

36156
2 732025001343805266
563399128172323734 55283226774627822
7 388099190813067712
564150557919527813 457487771983557281 332055400678110195 760833651510929158 785768483273197875 690506113272551236 463276585748519124
2 798714574862593347
426890163990834364 434764725667883272
1 414708220571820990
42...

output:

288230376151711744
0
432345564227567616
414708220571820991
716398192192370638
0
1949654914769744
0
0
0
811009189367843523
0
0
0
144115188075855872
0
0
0
91540211282631659
0
694703231769895640
144115188075855872
0
0
0
0
432345564227567616
0
753346372609875093
0
0
364589864498708058
0
7885484551135659...

result:

wrong answer 15th lines differ - expected: '114457959388827198', found: '144115188075855872'