QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#603582#7789. Outro: True Love Waitsorz_zWA 1ms3592kbC++144.0kb2024-10-01 17:36:012024-10-01 17:36:01

Judging History

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

  • [2024-10-01 17:36:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2024-10-01 17:36:01]
  • 提交

answer

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
	cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
	for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
	else if (s[i] == ')' || s[i] == '}') b--;
	else if (s[i] == ',' && b == 0) {
		cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
		debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
		break;
	}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
	int x = 0;
	bool t = 0;
	char c = getchar();
	while (c < '0' || c > '9') t |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return t ? -x : x;
}
inline void wi(int x) {
	if (x < 0) {
		putchar('-'), x = -x;
	}
	if (x > 9) wi(x / 10);
	putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
	wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;

string s1, s2; int k;

int qpow(int x, int y) {
	int res = 1;
	while(y) {
		if(y & 1) res = 1ll * res * x % mod;
		x = 1ll * x *x % mod , y>>= 1;
	} return res;
}

void solve() {
	cin >> s1 >>s2;
	k = ri();
	if(s1 == s2) {
		int ans = (qpow(4, k) + mod - 4) % mod;
		ans = 1ll * ans * qpow(3, mod - 2) % mod;
		cout << ans <<'\n';
		return;
	}
	int len = max(s1.size(), s2.size());
	if(len & 1) len++;
	while(s1.size() < len) s1 = "0" + s1;
	while(s2.size() < len) s2 = "0" + s2;
	vi s3, s4;
	s3.resize(len, 0);
	F(i, 0, len - 1) s3[i] = ((s1[i] - '0') ^ (s2[i] - '0'));
	F(i, 0, len - 1) {
		int w = (s3[i] * 2 + s3[i + 1]);
		++i;
		Debug(w);
		s4.pb(w);
	}
	int ln = s4.size();
	int wk = 0;
	dF(i, ln - 1, 0) {
		if(s4[i]) break;
		wk++;
	}
	wk++;
	if(k > wk) {
		puts("-1");
		return;
	}
	F(i, 0, ln - 1) {
		if(s4[i] == 1) s4[i] = 1;
		else if(s4[i] == 3) s4[i] = 2;
		else if(s4[i] == 2) s4[i] = 3;
		else s4[i] = 0;
	}
//	reverse(s4.begin(), s4.end());
	int st = 000;
	F(i, 0, ln - 1) {
		Debug(i, s4[i]);
		st = (5ll * st % mod + s4[i]) % mod;
	}
//	int zkw = 0;
//	dF(i, ln - 1, 0) {
//		zkw = (4ll * zkw % mod + s4[i]) % mod;
//	}
//	Debug(zkw);
	Debug(st);
	int ans = (qpow(4, k) + mod - 4) % mod;
	ans = 1ll * ans * qpow(3, mod - 2) % mod;
	ans = (ans + st) % mod;
	cout << ans << '\n';
}

bool Med;
signed main() {
	// Mry;
	int T = ri();
	while(T--) solve();
	// Try;
	return 0;
}

/*
4
1 10 1
1 10 2
100 0 2
11 11 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1 10 1
1 10 2
100 0 2
11 11 3

output:

2
-1
9
20

result:

ok 4 number(s): "2 -1 9 20"

Test #2:

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

input:

1
0 0 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3556kb

input:

100
110111 11111 1
10110 101101 1
11010 111111 1
100110 1 1
10010 11010 1
1100 10111 1
100100 111110 1
101110 101100 1
1011 10110 1
110100 1110 1
11010 11000 1
11110 1000 1
111000 11101 1
110 1001 1
101010 11000 1
10 111110 1
110001 101000 1
1010 1000 1
10101 11 1
111011 11010 1
110001 100000 1
1100...

output:

90
67
81
82
15
42
43
3
36
68
3
33
81
12
53
60
41
3
33
76
26
43
62
81
77
31
37
88
38
18
65
13
93
15
27
82
81
40
18
27
33
50
81
62
6
0
75
3
33
15
10
16
92
28
41
67
83
13
27
35
25
38
27
56
25
55
7
52
50
3
41
87
67
33
63
43
33
32
33
82
63
16
62
55
28
18
91
68
8
30
76
66
36
6
8
41
2
80
50
52

result:

wrong answer 1st numbers differ - expected: '78', found: '90'