QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176045 | #6417. Classical Summation Problem | Pentagonal | WA | 364ms | 34888kb | C++17 | 4.3kb | 2023-09-11 08:48:50 | 2023-09-11 08:48:50 |
Judging History
answer
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC -w
//Template {
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//IO templates
//Note: use endl only for interactive problems or to debug segfaults; use newl for other problems
#define newl "\n"
#define fastIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define fileIO(x) ifstream fin((str) x + (str) ".in"); ofstream fout((str) x + (str) ".out");
// void fileIO(string x) {}
#define flush() fflush(stdout)
#define interact(n) fflush(stdout); cin >> n; if (n == -1) return 0
#define testcases int t; cin >> t; fun(i, t) solve();
#define vectorIO(n, MikuBondage) fun(j, n) {int i; cin >> i; MikuBondage.pb(i);}
#define vector2IO(n, MikuBondage) fun(j, n) {int i, ii; cin >> i >> ii; MikuBondage.pb(mp(i, ii));}
#define edgeIO(m) fun(i, m) {int a, b; cin >> a >> b; addEdges(a, b);}
#define WeightedEdgeIO(m) fun(i, m) {int a, b, c; cin >> a >> b >> c; addWeightedEdges(a, b, c);}
//types
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ld long double
#define str string
//vector
#define pb push_back
#define append push_back
//pairs
#define mp make_pair
#define p2 pair<int, int>
#define p3 pair<int, p2>
#define m3(x, y, z) mp(x, mp(y, z))
#define ich first
#define ni second.first
#define sanshi second.second
//For loops
#define ahegao(i, a, b) for (int i = a; i < b; i++)
#define baka(i, b, a) for (int i = b; i > a; i--)
#define fun(i, n) for (int i = 1; i <= (n); (i)++)
#define fon(i, n) for (int i = 0; i < (n); (i)++)
#define fur(i, n) for (auto i : (n))
//Sorts
#define sz(a) ((signed) a.size())
#define all(a) a.begin(), a.end()
#define Sort(a) sort((a).begin(), (a).end())
#define rSort(a) sort((a).rbegin(), (a).rend())
#define clamp(x, y) (x) = min((int) (x), (int) (y))
#define CLAMP(x, y) (x) = max((int) (x), (int) (y))
//Other stuff
#define elif else if
#define addEdges(a, b) adj[a].pb(b); adj[b].pb(a)
#define addWeightedEdges(a, b, c) adj[a].pb(mp(b, c)); adj[b].pb(mp(a, c))
#define find find_by_order
#define printLength(x) if (x < INF) cout << x << newl; else cout << -1 << newl;
#define printVector(a) fur(i, a) cout << i << ' '; cout << newl;
// void printRange(vector<int>::iterator left, vector<int>::iterator right) {
// for (auto i = left; i < right; i++) cout << *i << ' ';
// cout << newl;
// }
//Constants
const int MOD = 998244353; //
// const int SMALLMOD = 998244353;
const int INF = 2e9+1337;
const ll EXCEED = 2e18+1337;
const ll GRAVITY = 9e18;
/*
Pro Tips:
1. Print the whole array at once don't be blinded by bad debug
2. Look at the testcases to see what went wrong
3. Pay attention to the order of operations
4. Modify pointers outside of functions
5. Always remember to save.
*/
#define int ll
//}
//I ran out of time sorry!
//Full solution for problem 3:
//Rename the provinces Biscotti and Galette
//2. Greedily add corners
int n, k;
const int MAX = 2000010;
ll lookup[MAX], inverseLookup[MAX];
ll modEXP(ll a, ll b) {
ll res = 1;
// int i = 0;
baka(i, 30, -1) {
res = (res * res) % MOD;
if (b & (1 << i)) {
// cout << i << newl;
res = (res * a) % MOD;
}
}
return res;
}
void init(int N) {
lookup[0] = 1;
fun(i, N) lookup[i] = (i * lookup[i-1]) % MOD;
ahegao(i, 0, N+1) inverseLookup[i] = modEXP(lookup[i], MOD - 2);
}
ll choice(int a, int b) {
if (a < b or b < 0) return 0;
ll res = (lookup[a] * inverseLookup[b]) % MOD;
return (res * inverseLookup[a-b]) % MOD;
}
signed main() {
cin >> n >> k;
if (k % 2) {
cout << (modEXP(n, k) * ((n + 1) / 2)) % MOD;
return 0;
} else {
init(2000001);
int res = 0;
fun(i, n-1) {
int temp = choice(k, k/2);
temp = (temp * modEXP(i, k/2)) % MOD;
temp = (temp * modEXP(n-i, k/2)) % MOD;
res = (res + temp) % MOD;
}
cout << (((modEXP(n, k) * ((n + 1) * inverseLookup[2])) % MOD) - (res / 2) + MOD) % MOD;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 364ms
memory: 34812kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 363ms
memory: 34888kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
10 9
output:
8778235
result:
wrong answer 1st numbers differ - expected: '508778235', found: '8778235'