QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#54253#4888. Decoding The Messageflower_and_qingyu#WA 2ms3648kbC++202.0kb2022-10-07 17:42:242022-10-07 17:42:30

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-07 17:42:30]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3648kb
  • [2022-10-07 17:42:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int N = 300, mod1 = 255, mod2 = 257, phi1 = 128, phi2 = 256;
int fpw(int a, int b, int mod) {
	int ans = 1;
	for(; b; b >>= 1, a = 1ll * a * a % mod) if(b & 1) ans = 1ll * ans * a % mod;
	return ans;
}
int main() {
	// freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0);
	int T;
	for(cin >> T; T; T --) {
		int k, s = 0, n = 0;
		cin >> k;
		vector<int> vec;
		for(int i = 0; i < k; i ++) {
			int di, ci;
			cin >> di >> ci;
			s = (s + 1ll * di * ci) % mod1;
			n += ci;
			for(int i = 0; i < ci; i ++) vec.emplace_back(di);
		}
		int facn = 1;
		if(n < 8) {
			for(int i = 1; i <= n; i ++){
				facn = facn * i;
			}
		}
		else facn = 2 * phi1;
		int ans1 = fpw(s, facn, mod1), ans2 = 1;
		// cout << ans1 << '\n';
		if(n < 12) {
			int m = (n + 1) / 2;
			vector<vector<vector<int>>> f(n + 1, vector<vector<int>> (m + 1, vector<int> (mod2)));
			f[0][0][0] = 1;
			// cout << "-----------\n";
			for(int i = 0; i < n; i ++) {
				for(int j = 0; j <= m; j ++) {
					for(int s = 0; s < mod2; s ++) if(f[i][j][s]) {
						if(j < m) f[i + 1][j + 1][(s + vec[i]) % mod2] += f[i][j][s];
						f[i + 1][j][(s - vec[i] + mod2) % mod2] += f[i][j][s];
					}
				}
			}
			int w = 1;
			for(int i = 1; i <= m; i ++) w = w * i;
			for(int i = 1; i <= n - m; i ++) w = w * i;
			// cout << w << '\n';
			for(int i = 0; i < mod2; i ++) if(f[n][m][i]) {
				// cout << i << ": " << w << ' ' << f[n][m][i] << '\n';
				ans2 = 1ll * ans2 * fpw(i, 1ll * f[n][m][i] * w % phi2, mod2) % mod2;
			}
		}
		else ans2 = 1;
		auto crt = [&] (int m1, int a1, int m2, int a2) {
			int d = a2 - a1, m = m1 * m2;
			int x, y;
			function<void(int, int, int&, int &)> exgcd =[&] (int a, int b, int &x, int &y) {
				if(!b) return x = 1, y = 0, void();
				exgcd(b, a % b, y, x), y -= a / b * x;
			};
			exgcd(m1, m2, x, y);
			x *= d;
			return ((a1 + m1 * x) % m + m) % m;
		};
		cout << crt(mod1, ans1, mod2, ans2) << '\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3576kb

input:

5
1
42 1
2
0 1
1 1
1
239 2
2
1 1
2 1
3
1 1
2 2
3 2

output:

42
256
514
1284
61726

result:

ok 5 number(s): "42 256 514 1284 61726"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3648kb

input:

100
1
213 79
1
54 69
1
218 55
1
248 80
1
101 8
1
153 79
1
240 45
1
112 70
1
217 5
1
208 64
1
48 30
1
0 19
1
53 40
1
63 17
1
179 65
1
221 22
1
135 84
1
138 20
1
54 29
1
114 19
1
253 94
1
240 36
1
40 94
1
244 93
1
239 24
1
133 8
1
105 91
1
45 43
1
241 74
1
206 17
1
100 73
1
133 44
1
57 70
1
56 72
1
47...

output:

21846
21846
26215
26215
32896
6426
48060
26215
43570
1
48060
32640
26215
6426
26215
50116
48060
48060
21846
21846
1
48060
26215
21846
21846
32896
48060
48060
1
50116
26215
1
48060
21846
6426
50116
48060
21846
21846
6426
21846
21846
6426
21846
1
26215
26215
26215
21846
48060
48060
22101
26215
26215
1...

result:

wrong answer 4th numbers differ - expected: '59110', found: '26215'