QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#321757 | #6669. Mapa | Unknown1508 | 0 | 8ms | 3648kb | C++20 | 2.9kb | 2024-02-05 11:46:40 | 2024-02-05 11:46:41 |
answer
#include <bits/stdc++.h>
#include <queue>
using namespace std;
void main_program();
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
main_program();
}
const int mod = 1e9 + 7;
int binpow(int n, int a){
int res = 1;
for (int exp = n; a; a >>= 1, exp = 1LL * exp * exp % mod){
if (a & 1) res = 1LL * res * exp % mod;
}
return res;
}
int inverse(int x){
return binpow(x, mod - 2);
}
int player;
using Poly = vector<int>;
Poly multiply(const Poly &A, const Poly &B){
// O(n^2) multiplication
Poly res(A.size() + B.size() - 1);
for (int i = 0; i < (int)A.size(); i++){
for (int j = 0; j < (int)B.size(); j++){
res[i + j] = (res[i + j] + 1LL * A[i] * B[j]) % mod;
}
}
return res;
}
auto size_comp = [](Poly A, Poly B){ return A.size() > B.size(); };
Poly multiply(const vector<Poly> &V){
priority_queue<Poly, vector<Poly>, decltype(size_comp)> pq(size_comp);
for (Poly P: V) pq.push(P);
while (pq.size() >= 2){
Poly p1 = pq.top(); pq.pop();
Poly p2 = pq.top(); pq.pop();
pq.push(multiply(p1, p2));
}
return pq.top();
}
Poly lagrange(const vector<pair<int, int>> &V){
int n = V.size();
vector<int> X(n), Y(n);
for (int i = 0; i < n; i++){
tie(X[i], Y[i]) = V[i];
}
Poly total(n);
for (int i = 0; i < n; i++){
vector<Poly> vec; vec.reserve(n - 1);
int num = Y[i];
for (int j = 0; j < n; j++){
if (j == i) continue;
vec.push_back(Poly{-X[j], 1});
num = 1LL * num * inverse(X[i] - X[j]) % mod;
}
Poly prod = multiply(vec);
for (int j = 0; j < (int)prod.size(); j++){
total[j] = (total[j] + 1LL * prod[j] * num) % mod;
}
}
return total;
}
namespace encode {
string convert(int x){
if (x < 0) x += mod;
string repr;
for (int i = 29; i >= 0; i--){
repr += ((x >> i) & 1) + '0';
}
return repr;
}
void solve(){
int n; cin >> n;
vector<pair<int, int>> vec(n);
for (int i = 0; i < n; i++){
cin >> vec[i].first >> vec[i].second;
}
Poly f = lagrange(vec);
string answer;
for (int i = 0; i < (int)f.size(); i++){
answer += convert(f[i]);
}
cout << answer.size() << "\n" << answer << "\n";
}
}
namespace decode {
int convert(string s){
int num = 0;
for (int i = 0; i < 30; i++){
int digit = (s[i] - '0');
num = (num << 1) + digit;
}
return num;
}
int n, q, k;
void solve(){
cin >> n >> q >> k;
string S; cin >> S;
vector<int> f(n);
for (int i = 0; i < n; i++){
f[i] = convert(S.substr(i * 30, 30));
}
for (int _ = 0; _ < q; _++){
int x; cin >> x;
int P = 1;
int res = 0;
for (int j = 0; j < n; j++){
res = (res + 1LL * P * f[j]) % mod;
P = 1LL * P * x;
}
cout << res << "\n";
}
}
}
void main_program(){
cin >> player;
if (player == 1) encode::solve();
else decode::solve();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 8ms = 8ms + 0ms
memory: 3644kb,3648kb
input:
1 100 495528311 963488152 269613430 443544124 700489871 792354118 151890319 506569919 180452297 13229948 684464994 543841485 978085128 903812192 238355172 441140842 28061035 783291471 530823766 718942732 936853023 439421263 201361623 226633955 304644844 778868118 864860135 461524170 88300500 6959354...
output:
3000 0111001101110010000011010001011100010010110110001101111010000100111000111111010101101110000000101001011100010011000100111101101101010011110010111010111000111101000111101111000000100011001101000110101111100111000100100110101111111110010110000101010101110010101100010001010011000101100110000101111...
input:
2 100 79 3000 0111001101110010000011010001011100010010110110001101111010000100111000111111010101101110000000101001011100010011000100111101101101010011110010111010111000111101000111101111000000100011001101000110101111100111000100100110101111111110010110000101010101110010101100010001010011000101100110...
output:
-571262522 591611762 -412502711 198596713 -85883856 729397756 441107209 -741276610 312578464 -99114709 -778777743 -660975501 348704604 766976770 -720122736 584847931 683924817 341659358 -656858315 132013576 -251906953 -850943141 -351935719 704054798 549557148 -831775938 -313487985 505337521 -1984978...
result:
wrong answer wrong answer on query #1: read -571262522 but expected 310305144