QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#176049 | #6417. Classical Summation Problem | Pentagonal | AC ✓ | 614ms | 34952kb | C++17 | 4.4kb | 2023-09-11 08:53:19 | 2023-09-11 08:53:20 |
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() {
init(2000001);
cin >> n >> k;
if (k % 2) {
cout << (modEXP(n, k) * (((n + 1) * inverseLookup[2]) % MOD)) % MOD;
return 0;
} else {
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)) % MOD) - ((res * inverseLookup[2])%MOD) + MOD) % MOD;
}
}
详细
Test #1:
score: 100
Accepted
time: 363ms
memory: 34824kb
input:
3 2
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 363ms
memory: 34880kb
input:
5 3
output:
375
result:
ok 1 number(s): "375"
Test #3:
score: 0
Accepted
time: 363ms
memory: 34948kb
input:
2 2
output:
5
result:
ok 1 number(s): "5"
Test #4:
score: 0
Accepted
time: 371ms
memory: 34808kb
input:
10 9
output:
508778235
result:
ok 1 number(s): "508778235"
Test #5:
score: 0
Accepted
time: 367ms
memory: 34820kb
input:
69 3
output:
11497815
result:
ok 1 number(s): "11497815"
Test #6:
score: 0
Accepted
time: 363ms
memory: 34772kb
input:
994 515
output:
33689623
result:
ok 1 number(s): "33689623"
Test #7:
score: 0
Accepted
time: 368ms
memory: 34812kb
input:
4476 6182
output:
114894183
result:
ok 1 number(s): "114894183"
Test #8:
score: 0
Accepted
time: 372ms
memory: 34824kb
input:
58957 12755
output:
932388891
result:
ok 1 number(s): "932388891"
Test #9:
score: 0
Accepted
time: 417ms
memory: 34884kb
input:
218138 28238
output:
392861201
result:
ok 1 number(s): "392861201"
Test #10:
score: 0
Accepted
time: 518ms
memory: 34820kb
input:
644125 316810
output:
420621854
result:
ok 1 number(s): "420621854"
Test #11:
score: 0
Accepted
time: 511ms
memory: 34884kb
input:
612914 505428
output:
973686286
result:
ok 1 number(s): "973686286"
Test #12:
score: 0
Accepted
time: 367ms
memory: 34768kb
input:
998216 938963
output:
251335926
result:
ok 1 number(s): "251335926"
Test #13:
score: 0
Accepted
time: 360ms
memory: 34764kb
input:
990516 996933
output:
549551960
result:
ok 1 number(s): "549551960"
Test #14:
score: 0
Accepted
time: 614ms
memory: 34948kb
input:
999019 999012
output:
637189128
result:
ok 1 number(s): "637189128"
Test #15:
score: 0
Accepted
time: 593ms
memory: 34944kb
input:
999928 999950
output:
185229465
result:
ok 1 number(s): "185229465"
Test #16:
score: 0
Accepted
time: 367ms
memory: 34896kb
input:
999999 999999
output:
384164916
result:
ok 1 number(s): "384164916"
Test #17:
score: 0
Accepted
time: 571ms
memory: 34884kb
input:
999999 1000000
output:
696165930
result:
ok 1 number(s): "696165930"
Test #18:
score: 0
Accepted
time: 371ms
memory: 34892kb
input:
1000000 999999
output:
219071706
result:
ok 1 number(s): "219071706"
Test #19:
score: 0
Accepted
time: 575ms
memory: 34884kb
input:
1000000 1000000
output:
128206597
result:
ok 1 number(s): "128206597"
Test #20:
score: 0
Accepted
time: 351ms
memory: 34900kb
input:
2 10
output:
1410
result:
ok 1 number(s): "1410"
Test #21:
score: 0
Accepted
time: 368ms
memory: 34900kb
input:
84 16
output:
297627153
result:
ok 1 number(s): "297627153"
Test #22:
score: 0
Accepted
time: 371ms
memory: 34900kb
input:
643 800
output:
489237163
result:
ok 1 number(s): "489237163"
Test #23:
score: 0
Accepted
time: 366ms
memory: 34896kb
input:
9903 880
output:
595167333
result:
ok 1 number(s): "595167333"
Test #24:
score: 0
Accepted
time: 386ms
memory: 34820kb
input:
97446 89750
output:
410205549
result:
ok 1 number(s): "410205549"
Test #25:
score: 0
Accepted
time: 412ms
memory: 34812kb
input:
186460 646474
output:
32638530
result:
ok 1 number(s): "32638530"
Test #26:
score: 0
Accepted
time: 490ms
memory: 34952kb
input:
508940 244684
output:
598321755
result:
ok 1 number(s): "598321755"
Test #27:
score: 0
Accepted
time: 499ms
memory: 34900kb
input:
583646 557758
output:
858695621
result:
ok 1 number(s): "858695621"
Test #28:
score: 0
Accepted
time: 591ms
memory: 34896kb
input:
969610 992608
output:
256683498
result:
ok 1 number(s): "256683498"
Test #29:
score: 0
Accepted
time: 605ms
memory: 34768kb
input:
995106 996434
output:
411791999
result:
ok 1 number(s): "411791999"
Test #30:
score: 0
Accepted
time: 583ms
memory: 34812kb
input:
999961 999872
output:
61222370
result:
ok 1 number(s): "61222370"
Test #31:
score: 0
Accepted
time: 603ms
memory: 34888kb
input:
999977 999908
output:
831096762
result:
ok 1 number(s): "831096762"
Test #32:
score: 0
Accepted
time: 610ms
memory: 34884kb
input:
999992 999998
output:
562977678
result:
ok 1 number(s): "562977678"
Test #33:
score: 0
Accepted
time: 537ms
memory: 34824kb
input:
1000000 2
output:
118436113
result:
ok 1 number(s): "118436113"
Test #34:
score: 0
Accepted
time: 367ms
memory: 34880kb
input:
2 1000000
output:
298823641
result:
ok 1 number(s): "298823641"