QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186014 | #5547. Short Function | NYCU_Yamada# | WA | 0ms | 3664kb | C++20 | 3.6kb | 2023-09-22 23:19:35 | 2023-09-22 23:19:36 |
Judging History
answer
#ifndef Yamada
#define Yamada
#include Yamada __FILE__ Yamada
const int mod = 998244353;
int n, k;
pii operator*(const pii &a, const pii &b) {
int F = a.X * b.X % (mod-1) * n % (mod-1);
F = (F + a.X * b.Y % (mod-1)) % (mod-1);
F = (F + a.Y * b.X % (mod-1)) % (mod-1);
int tmp = a.Y * b.Y;
F = (F + tmp / n) % (mod-1);
return pii(F, tmp % n);
}
pii piifpow(pii base, pii ans, int exp) {
while (exp) {
if (exp & 1) ans = ans * base;
exp >>= 1, base = base * base;
}
return ans;
}
int fpow(int base, int exp = mod-2, int ans = 1) {
while (exp) {
if (exp & 1) ans = ans * base % mod;
exp >>= 1, base = base * base % mod;
}
return ans;
}
void solve() {
cin >> n >> k;
vector<int> a(n+1), prod(n+1), inv(n+1);
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (i) {
prod[i] = prod[i-1] * a[i] % mod;
inv[i] = fpow(prod[i]);
}
else {
prod[i] = a[i];
inv[i] = fpow(prod[i]);
}
}
// debug(a);
// debug(prod);
pii base = pii(2 / n, 2 % n);
pii ans = pii(1 / n, 1 % n);
pii K = piifpow(base, ans, k);
for (int i = 0; i < n; ++i) {
int R = (i + fpow(2, k) - 1 + n) % n;
int b = fpow(prod[n-1], K.X);
if (i > 0 && R == i-1) {
cout << b << " \n"[i==n-1];
continue;
}
if (i == 0 && R == n-1) {
cout << b << " \n"[i==n-1];
continue;
}
if (i <= R) {
b = b * prod[R] % mod;
if (i) b = b * inv[i-1] % mod;
}
else {
b = b * prod[R] % mod;
b = b * prod[n-1] % mod;
b = b * inv[i-1] % mod;
}
// debug(K.X, K.Y, R, b);
cout << b;
cout << " \n"[i==n-1];
}
}
signed main() {
IOS();
int t = 1; // cin >> t;
for (int i = 1; i <= t; ++i) solve();
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
using pii = pair<int, int>;
template <typename T> using MaxHeap = std::priority_queue<T>;
template <typename T> using MinHeap = std::priority_queue<T, vector<T>, greater<T>>;
#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define ee emplace
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define X first
#define Y second
template <typename T>
ostream & operator << (ostream &os, const vector<T> &vec) {
os << "[";
for (int i = 0; i < SZ(vec); ++i) {
if (i) os << ", ";
os << vec[i];
}
os << "]";
return os;
}
#ifdef local
#define IOS() void()
#define debug(...) \
fprintf(stderr, "%sAt [%s], line %d: (%s) = ", "\u001b[33m", __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), fprintf(stderr, "%s", "\u001b[0m")
template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#else
#define IOS() ios_base::sync_with_stdio(0); cin.tie(0)
#define debug(...) void()
#define endl '\n'
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
5 2 1 2 3 4 5
output:
24 120 60 40 30
result:
ok 5 number(s): "24 120 60 40 30"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
8 3 12 5 16 14 10 6 9 2
output:
14515200 14515200 14515200 14515200 14515200 14515200 14515200 14515200
result:
ok 8 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
6 10 3 7 8 2 9 5
output:
56347321 169041963 833775940 811788154 844769833 639990479
result:
ok 6 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
2 100 1 2
output:
917380677 917380677
result:
ok 2 number(s): "917380677 917380677"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
119 1000000000 179906895 883175111 831258723 617910763 41850684 952649819 667608052 992898634 871657688 261948841 858714230 452797779 698675390 39373823 268148685 762575950 789163136 676908074 134428624 583625412 549545785 415007638 564283552 596519552 575204092 884934270 632550339 21505752 66058955...
output:
117717217 261459092 130067455 270379893 142179551 979251074 890046277 437551938 318767344 333290158 318144434 400448285 867281154 989616352 187439081 318238700 997496000 118378491 171143862 226384924 472586927 9766341 587627335 470901966 275270576 960905383 316999597 709153139 525671653 634590680 88...
result:
wrong answer 1st numbers differ - expected: '375116230', found: '117717217'