QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181601#3763. Absolute Difference Equation01team#AC ✓91ms5420kbC++141.2kb2023-09-16 21:13:032023-09-16 21:13:04

Judging History

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

  • [2023-09-16 21:13:04]
  • 评测
  • 测评结果:AC
  • 用时:91ms
  • 内存:5420kb
  • [2023-09-16 21:13:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long; 
constexpr int mod = 1e9 + 7;
int add(int a, int b) {
	return a += b, a < mod ? a : a - mod;
}
int sub(int a, int b) {
	return a -= b, a >= 0 ? a : a + mod;
}
int mul(int a, int b) {
	return 1ull * a * b % mod;
}
int qpow(int a, i64 b) {
	int c = 1;
	while (b) {
		if (b & 1) {
			c = mul(c, a);
		}
		a = mul(a, a);
		b >>= 1;
	}
	return c;
}
int inv(int x) {
	return qpow(x, mod - 2);
}
bool comb(int n, int m) {
	return (n & m) == m;
}
void solve(string s) {
	int n = s.size();
	vector<int> pos;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		if (comb(n - 1, i) == 0) {
			if (s[i] == '?') {
				ans = mul(ans, 2);
			}
		} else {
			pos.push_back(i);
		}
	}
	int m = pos.size();
	vector<int> f{1, 0};
	for (int i = 0; i < m; i++) {
		char c = s[pos[i]];
		vector<int> g = f;
		if (c == '0') {
			
		} else if (c == '1') {
			swap(g[0], g[1]);
		} else if (c == '?') {
			g[0] = add(g[0], f[1]);
			g[1] = add(g[1], f[0]);
		}
		swap(f, g);
	}
	ans = mul(ans, f[1]);
	cout << ans << "\n";
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	while (cin >> s) {
		solve(s);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 91ms
memory: 5420kb

input:

1
?????
1010?1?0
0
1
?
00
10
?0
01
11
?1
0?
1?
??
000
100
?00
010
110
?10
0?0
1?0
??0
001
101
?01
011
111
?11
0?1
1?1
??1
00?
10?
?0?
01?
11?
?1?
0??
1??
???
0000
1000
?000
0100
1100
?100
0?00
1?00
??00
0010
1010
?010
0110
1110
?110
0?10
1?10
??10
00?0
10?0
?0?0
01?0
11?0
?1?0
0??0
1??0
???0
0001
10...

output:

1
16
2
0
1
1
0
1
1
1
0
1
1
1
2
0
1
1
0
1
1
0
2
2
1
0
1
1
0
1
2
0
2
1
1
2
1
1
2
2
2
4
0
1
1
1
0
1
1
1
2
1
0
1
0
1
1
1
1
2
1
1
2
1
1
2
2
2
4
1
0
1
0
1
1
1
1
2
0
1
1
1
0
1
1
1
2
1
1
2
1
1
2
2
2
4
1
1
2
1
1
2
2
2
4
1
1
2
1
1
2
2
2
4
2
2
4
2
2
4
4
4
8
0
1
1
0
1
1
0
2
2
0
1
1
0
1
1
0
2
2
0
2
2
0
2
2
0
4
4...

result:

ok 162656 lines