Submission #74308638
Source Code Expand
#include<bits/extc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx,avx2")
#include<iostream>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define mp make_pair
// #define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
// #define cin fin
// #define cout fout
// ifstream fin("word.in");
// ofstream fout("word.out");
const int inf = INT_MAX;
const int MOD = 998244353;
double PI = 4*atan(1);
#ifdef DEBUG
string to_string(char c) { return string({c}); }
// 7
template<class... Ts>
ostream& operator<<(ostream& o, tuple<Ts...> t) {
string s = "(";
apply([&](auto&&... r) {
((s += to_string(r) + ", "), ...); }, t);
return o << s.substr(0, len(s) - 2) + ")";
}
// 3
ostream& operator<<(ostream &o, pair<auto, auto> p) {
return o << "(" << p.fi << ", " << p.se << ")";
}
// 7
template<class C, class T = typename C::value_type,
typename std::enable_if<!std::is_same<C, std::string>
::value>::type* = nullptr>
ostream& operator<<(ostream &o, C c) {
for (auto e : c) o << setw(7) << right << e;
return o << endc << endl << coutc;
}
// 7
void debug(const auto &e, const auto &... r) {
cout << coutc << e;
((cout << " " << r), ..., (cout << endc << endl));
}
#else
#define debug(...)
#endif
map<string,int> mon;
map<int,string> inp;
ll pw(ll a, ll e) {
ll r = 1;
while (e) {
if (e & 1) r = r * a % MOD;
a = a * a % MOD;
e >>= 1;
}
return r;
}
void _main(int tc) {
int N;
cin >> N;
ll s = 0, q = 0;
int i = 0;
while (i < N) {
ll x;
cin >> x;
x %= MOD;
s += x;
if (s >= MOD) s -= MOD;
q += x * x % MOD;
if (q >= MOD) q -= MOD;
i++;
}
if (N == 1) {
cout << q << endl;
return;
}
if (N == 2) {
ll ans = (s * s % MOD - 2 * q % MOD + MOD) % MOD;
ans = (q + ans) % MOD;
cout << ans << endl;
return;
}
ll num = ((3LL * N - 1) % MOD) * q % MOD;
num = (num - 2 * s % MOD * s % MOD + MOD) % MOD;
ll den = 3LL * (N - 1) % MOD;
ll ans = num * pw(den, MOD - 2) % MOD;
cout << ans << endl;
}
// 5
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
_main(0), exit(0);
int tc; cin >> tc; rep(i, tc) _main(i + 1);
}
Submission Info
| Submission Time |
|
| Task |
G - Random Subtraction |
| User |
zaahir |
| Language |
C++23 (GCC 15.2.0) |
| Score |
0 |
| Code Size |
3391 Byte |
| Status |
WA |
| Exec Time |
10 ms |
| Memory |
3704 KiB |
Compile Error
./Main.cpp: In function 'void _main(int)':
./Main.cpp:102:16: warning: unused parameter 'tc' [-Wunused-parameter]
102 | void _main(int tc) {
| ~~~~^~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 575 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_01.txt, 00_sample_02.txt, 01_01.txt, 01_02.txt, 01_03.txt, 01_04.txt, 01_05.txt, 01_06.txt, 01_07.txt, 01_08.txt, 01_09.txt, 01_10.txt, 01_11.txt, 01_12.txt, 01_13.txt, 01_14.txt, 01_15.txt, 01_16.txt, 01_17.txt, 01_18.txt, 01_19.txt, 01_20.txt, 02_01.txt, 02_02.txt, 02_03.txt, 02_04.txt, 02_05.txt, 02_06.txt, 02_07.txt, 02_08.txt, 02_09.txt, 02_10.txt, 02_11.txt, 02_12.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_01.txt |
AC |
1 ms |
3492 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3652 KiB |
| 01_01.txt |
AC |
1 ms |
3612 KiB |
| 01_02.txt |
AC |
1 ms |
3580 KiB |
| 01_03.txt |
WA |
1 ms |
3480 KiB |
| 01_04.txt |
WA |
1 ms |
3460 KiB |
| 01_05.txt |
AC |
1 ms |
3704 KiB |
| 01_06.txt |
AC |
1 ms |
3460 KiB |
| 01_07.txt |
AC |
1 ms |
3496 KiB |
| 01_08.txt |
AC |
1 ms |
3492 KiB |
| 01_09.txt |
AC |
7 ms |
3460 KiB |
| 01_10.txt |
AC |
3 ms |
3408 KiB |
| 01_11.txt |
AC |
4 ms |
3552 KiB |
| 01_12.txt |
AC |
8 ms |
3544 KiB |
| 01_13.txt |
AC |
7 ms |
3652 KiB |
| 01_14.txt |
AC |
6 ms |
3436 KiB |
| 01_15.txt |
AC |
10 ms |
3612 KiB |
| 01_16.txt |
AC |
10 ms |
3492 KiB |
| 01_17.txt |
AC |
10 ms |
3652 KiB |
| 01_18.txt |
AC |
9 ms |
3492 KiB |
| 01_19.txt |
AC |
10 ms |
3492 KiB |
| 01_20.txt |
AC |
10 ms |
3480 KiB |
| 02_01.txt |
AC |
1 ms |
3488 KiB |
| 02_02.txt |
AC |
1 ms |
3636 KiB |
| 02_03.txt |
AC |
1 ms |
3552 KiB |
| 02_04.txt |
WA |
1 ms |
3612 KiB |
| 02_05.txt |
AC |
1 ms |
3436 KiB |
| 02_06.txt |
AC |
1 ms |
3436 KiB |
| 02_07.txt |
AC |
8 ms |
3396 KiB |
| 02_08.txt |
AC |
9 ms |
3620 KiB |
| 02_09.txt |
AC |
8 ms |
3428 KiB |
| 02_10.txt |
AC |
9 ms |
3552 KiB |
| 02_11.txt |
AC |
7 ms |
3460 KiB |
| 02_12.txt |
AC |
9 ms |
3436 KiB |