QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#242921 | #7337. Grasshoppers | PetroTarnavskyi# | WA | 897ms | 37292kb | C++17 | 2.9kb | 2023-11-07 18:40:04 | 2023-11-07 18:40:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
typedef complex<db> com;
const int LEN = 1 << 18;
com pw[LEN];
void init()
{
db phi = 2 * acos(-1.0) / LEN;
FOR(i, 0, LEN)
pw[i] = com(cos(i * phi), sin(i * phi));
}
void fft(vector<com>& a, bool inv)
{
int lg = 0;
while((1 << lg) < SZ(a)) lg++;
FOR(i, 0, SZ(a))
{
int x = 0;
FOR(j, 0, lg)
x |= ((i >> j) & 1) << (lg - j - 1);
if(i < x)
swap(a[i], a[x]);
}
for(int len = 2; len <= SZ(a); len *= 2)
{
int diff = inv ? LEN - LEN / len : LEN / len;
for(int i = 0; i < SZ(a); i += len)
{
int pos = 0;
FOR(j, 0, len / 2)
{
com v = a[i + j];
com u = a[i + j + len / 2] * pw[pos];
a[i + j] = v + u;
a[i + j + len / 2] = v - u;
pos += diff;
if(pos >= LEN)
pos -= LEN;
}
}
}
if(inv)
{
FOR(i, 0, SZ(a))
a[i] /= SZ(a);
}
}
int toInt(db a)
{
if(a >= 0)
return int(a + 0.5);
return -toInt(-a);
}
VI mult(vector<com> a, vector<com> b)
{
int sz = 0;
int sum = SZ(a) + SZ(b) - 1;
while((1 << sz) < sum) sz++;
a.resize(1 << sz);
b.resize(1 << sz);
fft(a, false);
fft(b, false);
FOR(i, 0, SZ(a))
a[i] *= b[i];
fft(a, true);
a.resize(sum);
VI res(SZ(a));
FOR(i, 0, SZ(res))
{
res[i] = toInt(a[i].real());
}
return res;
}
VI mult(VI a, VI b)
{
vector<com> A(ALL(a));
vector<com> B(ALL(b));
return mult(A, B);
}
int n, m;
VI multNM(VI a, VI b)
{
VI res = mult(a, b);
for(int & i : res)
i %= m;
FOR(i, n, SZ(res))
{
res[i % n] += res[i];
}
res.resize(min(SZ(res), n));
for(int &i : res)
{
i = (i % m + m) % m;
}
return res;
}
VI binpow(VI a, int t)
{
VI res = {1};
while(t)
{
if(t & 1)
res = multNM(res, a);
a = multNM(a, a);
t /= 2;
}
return res;
}
void solve()
{
int t;
cin >> n >> m >> t;
VI a(2 * n);
FOR(i, 0, n)
{
cin >> a[i];
a[i]--;
a[i + n] = a[i];
}
VI f = binpow({-1, 2}, t);
reverse(ALL(f));
VI res = mult(a, f);
FOR(i, 0, n)
{
int ans = res[i + SZ(f) - 1];
ans = (ans % m + m) % m;
if(i > 0)
cout << " ";
cout << ans + 1;
}
cout << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
init();
//VI res = mult(VI{1, 2, 1}, VI{-1, 1});
//
//FOR(i, 0, SZ(res))
// cout << res[i] << " ";
//cout << endl;
//return 0;
int t;
cin >> t;
while(t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8000kb
input:
2 3 5 1 1 1 2 3 5 4 1 1 2
output:
1 3 5 5 4 5
result:
ok 6 numbers
Test #2:
score: -100
Wrong Answer
time: 897ms
memory: 37292kb
input:
92 3 5 5 4 2 3 3 5 5 3 1 5 3 5 5 4 3 5 3 5 5 3 3 2 3 5 5 1 3 3 3 5 5 2 3 3 3 5 5 3 3 2 3 5 5 4 2 5 3 5 5 1 2 4 3 5 5 4 5 1 3 5 5 4 1 4 3 5 5 1 1 2 3 5 5 1 1 4 3 5 5 1 1 4 3 5 5 5 2 4 3 5 5 5 5 1 3 5 5 2 5 5 3 5 5 3 2 5 3 5 5 1 2 3 3 5 5 1 1 1 3 5 5 4 3 1 3 5 5 1 3 4 3 5 5 1 5 1 3 5 5 1 4 4 3 5 5 5 2...
output:
2 1 1 2 5 2 1 5 1 1 3 4 5 4 3 4 1 3 1 3 4 1 1 4 2 5 5 3 3 4 4 2 3 3 1 5 2 1 3 2 1 3 3 3 5 2 5 4 3 4 5 2 4 4 5 5 1 1 1 1 3 5 5 2 4 2 1 2 4 2 3 4 5 3 4 3 4 2 4 3 5 2 5 5 4 4 1 2 5 1 1 1 5 2 5 2 1 5 1 1 1 1 2 2 5 4 3 4 4 2 2 1 2 5 2 5 4 3 3 1 4 4 5 5 5 1 4 3 3 3 4 2 3 4 5 3 2 2 5 2 3 5 1 3 5 1 3 5 2 4 ...
result:
wrong answer 12881st numbers differ - expected: '31', found: '50'