QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47185 | #1855. Minimal Cyclic Shift | YaoBIG# | AC ✓ | 221ms | 14908kb | C++17 | 3.9kb | 2022-09-04 16:38:19 | 2022-09-04 16:38:22 |
Judging History
answer
#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); ++i)
#define revrep(i, a, n) for (auto i = n; i >= (a); --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
template<class A, class B> string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string) s); }
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(bool x) { return x ? "true" : "false"; }
template<class A> string to_string(A v) {
bool first = 1;
string res = "{";
for (const auto &x: v) {
if (!first) res += ", ";
first = 0;
res += to_string(x);
}
res += "}";
return res;
}
template<class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
void debug_out() { cerr << endl; }
template<class Head, class... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) if(0) puts("No effect.")
#endif
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
template<const int &mod> struct Z {
int x;
Z(ll a = 0): x(a % mod) { if (x < 0) x += mod; }
explicit operator int() const { return x; }
Z& operator +=(Z b) { x += b.x; if (x >= mod) x -= mod; return * this; }
Z& operator -=(Z b) { x -= b.x; if (x < 0) x += mod; return * this; }
Z& operator *=(Z b) { x = 1ll * x * b.x % mod; return * this; }
friend Z operator +(Z a, Z b) { return a += b; }
friend Z operator -(Z a, Z b) { return a -= b; }
friend Z operator *(Z a, Z b) { return a *= b; }
Z pow(ll k) const {
Z res = 1, a = *this;
for (; k; k >>= 1, a = a * a) if (k & 1) res = res * a;
return res;
}
Z& operator /=(Z b) {
assert(b.x != 0);
*this = *this * b.pow(mod - 2);
return *this;
}
friend Z operator /(Z a, Z b) { return a /= b; }
friend string to_string(Z a) { return to_string(a.x); }
};
const int mod = 998244353;
using Mint = Z<mod>;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vi as(n);
for (auto &x: as) cin >> x;
if (n == 1) {
puts("1");
return 0;
} else {
const int maxn = 100'000;
vector<Mint> g(maxn + 1);
vvi facs(maxn + 1);
rep(i, 1, maxn) g[i] = Mint{26}.pow(i);
rep(i, 1, maxn) {
facs[i].push_back(i);
for (int j = i * 2; j <= maxn; j += i) {
g[j] -= g[i];
facs[j].push_back(i);
}
}
vector<Mint> inv(maxn + 1);
rep(i, 1, maxn) inv[i] = Mint{1} / i;
// debug(g);
auto solve = [&](int a, int b) -> Mint {
auto &fa = facs[a];
auto &fb = facs[b];
Mint ans = 0;
// for (auto i: fa) for (auto j: fb) ans += g[i] * g[j] / max(i, j);
// debug(a, b);
// debug(fa, fb);
Mint psa = 0, psb = 0;
auto ita = fa.begin();
auto itb = fb.begin();
while (ita != fa.end() || itb != fb.end()) {
if (ita != fa.end() && itb != fb.end()) {
if (*ita <= *itb) {
ans += g[*ita] * psb * inv[*ita];
psa += g[*ita];
ita++;
} else {
ans += g[*itb] * psa * inv[*itb];
psb += g[*itb];
itb++;
}
} else if (ita != fa.end()) {
ans += g[*ita] * psb * inv[*ita];
psa += g[*ita];
ita++;
} else {
ans += g[*itb] * psa * inv[*itb];
psb += g[*itb];
itb++;
}
}
return ans;
};
Mint ans = 0;
rep(i, 0, n - 1) {
int a = as[i];
int b = as[(i + 1) % n];
Mint res = solve(a, b);
ans += res / Mint{26}.pow(a + b);
}
printf("%d\n", (int) ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 65ms
memory: 14380kb
input:
5 3 1 5 2 4
output:
727907401
result:
ok single line: '727907401'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3704kb
input:
1 100000
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 101ms
memory: 14864kb
input:
86767 35422 24898 32532 92988 84636 99872 57831 31700 47597 79017 25316 96560 4822 31820 62125 8873 31377 38988 12468 71596 52652 40575 1313 82552 37864 96176 34224 84035 10267 29886 57968 31414 95022 61051 97957 89292 9248 89389 23526 19511 12610 95760 86463 65531 43001 40017 88433 26385 4384 91445...
output:
878054961
result:
ok single line: '878054961'
Test #4:
score: 0
Accepted
time: 88ms
memory: 14720kb
input:
55721 51563 5451 94713 9537 30709 63343 41819 65855 51779 39457 85060 96650 74359 93631 10042 80788 11639 69710 76709 68048 33133 23893 75696 96409 23880 14590 91789 74156 10137 49112 35534 41001 71159 63159 35661 91318 39323 76627 89445 35612 30725 94245 20918 99528 36789 86829 79973 84299 146 7185...
output:
91462762
result:
ok single line: '91462762'
Test #5:
score: 0
Accepted
time: 83ms
memory: 14468kb
input:
56074 407 10197 24191 58791 9486 68030 25807 11 88665 32600 12100 29445 33496 96658 57959 28510 83389 67729 40950 55989 80911 31402 17375 42970 99496 8811 8138 88468 10007 92530 21612 83292 81887 97972 62965 58752 36694 96568 46851 75905 91943 60026 88076 57717 97872 936 71513 74917 52805 60776 3187...
output:
602599501
result:
ok single line: '602599501'
Test #6:
score: 0
Accepted
time: 65ms
memory: 14348kb
input:
82 518 71 971 121 862 967 607 138 754 513 337 499 873 337 387 647 917 76 417 1000 12 703 826 356 728 984 227 371 864 387 196 251 565 54 672 148 390 5 50 349 772 375 131 885 790 158 269 994 215 155 323 310 11 393 718 20 101 501 450 216 212 508 854 76 162 181 320 916 852 779 967 659 676 620 263 588 26...
output:
166275963
result:
ok single line: '166275963'
Test #7:
score: 0
Accepted
time: 68ms
memory: 14220kb
input:
18 171 816 449 375 934 950 299 702 232 657 81 885 306 660 304 369 371 798
output:
991165057
result:
ok single line: '991165057'
Test #8:
score: 0
Accepted
time: 94ms
memory: 14260kb
input:
28 311 74 927 732 711 126 583 857 118 97 928 975 843 175 221 284 929 816 602 689 863 721 888 478 953 722 141 804
output:
93898560
result:
ok single line: '93898560'
Test #9:
score: 0
Accepted
time: 58ms
memory: 14304kb
input:
38 155 820 596 986 976 813 571 13 301 832 376 769 276 498 138 414 679 834 651 142 449 39 759 527 865 943 1 924 67 257 815 228 862 980 281 42 102 717
output:
974161669
result:
ok single line: '974161669'
Test #10:
score: 0
Accepted
time: 121ms
memory: 14660kb
input:
75469 67704 10077 34778 90239 11457 80284 42263 53872 74779 93976 53416 83860 74518 72013 20351 78137 67238 70557 16596 79890 56227 1548 62143 71384 92585 80165 81054 2533 42745 18675 3893 37815 82998 33577 43689 38771 91177 48955 80996 59136 61438 3714 78549 97960 82533 33405 69133 63866 95761 2212...
output:
348777940
result:
ok single line: '348777940'
Test #11:
score: 0
Accepted
time: 127ms
memory: 14888kb
input:
94424 83844 14823 64255 15301 90234 84972 93547 88028 11665 54415 13159 83950 951 42336 92460 50051 47500 1279 80836 43639 36708 9057 3822 17945 2793 74386 5915 25357 42615 37901 14164 55915 26431 68390 38289 97693 88548 3489 71107 99429 79552 69495 13003 56148 43616 80216 60673 54484 48420 35236 50...
output:
629399843
result:
ok single line: '629399843'
Test #12:
score: 0
Accepted
time: 85ms
memory: 14524kb
input:
63378 32688 95377 26437 64554 60498 56955 10239 22183 15847 47559 40199 92552 70488 4147 73082 97774 51954 99297 53589 31579 60294 16567 78205 31802 13002 68607 63480 39669 9781 57127 67538 65502 2567 3202 75993 32423 51327 99238 28514 48233 64963 43788 47458 90145 61596 27028 84917 12398 76887 1564...
output:
26347638
result:
ok single line: '26347638'
Test #13:
score: 0
Accepted
time: 104ms
memory: 14788kb
input:
95130 24637 8634 80107 81104 39275 53130 94227 56339 87326 7999 75751 92642 96921 74470 20999 69688 99512 30019 50534 28032 8072 67180 19884 45659 55914 30124 12533 97086 9652 546 10512 40497 45999 5311 3298 99857 48698 86476 61728 55822 58885 9569 14616 48334 89975 49647 649 78824 29545 61464 12773...
output:
855877739
result:
ok single line: '855877739'
Test #14:
score: 0
Accepted
time: 86ms
memory: 14468kb
input:
64084 73481 13380 42288 6166 85348 25113 78215 23198 24212 44246 35494 92733 66459 44793 68916 82818 3967 28037 47479 91780 55850 74689 18459 92220 41930 24345 4690 44102 9522 87068 96591 25892 22136 31612 41002 34586 78773 73713 19135 96115 44296 75350 49070 39227 83763 63755 24893 36738 58012 5038...
output:
417509537
result:
ok single line: '417509537'
Test #15:
score: 0
Accepted
time: 89ms
memory: 14560kb
input:
64437 55030 93934 39062 88123 88317 21289 62203 57354 28394 37390 95238 92823 92892 39308 16833 54733 51525 58759 87527 79721 46731 14903 92843 38781 52138 18566 62255 25710 9392 30486 74157 35479 65568 33721 11410 69316 8848 93655 85054 44920 62410 49643 7717 73223 44847 43270 16433 27356 77967 962...
output:
605645910
result:
ok single line: '605645910'
Test #16:
score: 0
Accepted
time: 116ms
memory: 14792kb
input:
98557 88704 61481 72140 15810 58854 43034 5150 80684 61360 50516 54301 78790 43678 46138 79893 89899 60260 2881 66499 99500 54572 54419 33657 43179 61234 29965 91136 37826 26886 6880 64913 90362 85934 53747 40219 14676 46017 62847 87713 7556 37069 40466 17625 63376 62673 63213 7789 40149 2948 31686 ...
output:
496339968
result:
ok single line: '496339968'
Test #17:
score: 0
Accepted
time: 221ms
memory: 14864kb
input:
100000 92400 65520 65520 90720 98280 90720 92400 90720 83160 75600 55440 95040 98280 95760 95040 75600 90720 65520 95760 95040 95040 92400 90720 75600 95040 75600 95760 92400 83160 92400 83160 65520 75600 75600 95760 95040 83160 90720 85680 83160 65520 65520 55440 90720 65520 90720 65520 90720 95040...
output:
994389174
result:
ok single line: '994389174'
Test #18:
score: 0
Accepted
time: 203ms
memory: 14788kb
input:
100000 90720 85680 95760 95760 85680 83160 75600 65520 65520 95040 55440 83160 83160 75600 95760 95040 65520 98280 83160 65520 75600 95760 75600 95760 92400 90720 92400 92400 90720 85680 92400 95040 83160 98280 92400 95040 90720 95040 83160 90720 83160 75600 95040 98280 83160 85680 65520 98280 55440...
output:
774988411
result:
ok single line: '774988411'
Test #19:
score: 0
Accepted
time: 196ms
memory: 14788kb
input:
100000 55440 83160 55440 55440 90720 83160 85680 85680 98280 95760 75600 83160 83160 55440 92400 83160 98280 95040 98280 95760 90720 55440 55440 85680 55440 85680 98280 98280 98280 65520 75600 55440 55440 65520 75600 65520 83160 83160 65520 75600 83160 98280 92400 95040 95040 83160 90720 95760 75600...
output:
944180242
result:
ok single line: '944180242'
Test #20:
score: 0
Accepted
time: 211ms
memory: 14860kb
input:
100000 55440 55440 75600 92400 95040 55440 75600 85680 65520 95760 95040 90720 90720 85680 55440 98280 98280 95040 75600 95040 98280 95040 92400 98280 90720 55440 83160 95760 98280 55440 98280 75600 95760 83160 83160 65520 95760 55440 95040 98280 55440 85680 75600 95760 85680 95760 90720 98280 98280...
output:
228240608
result:
ok single line: '228240608'
Test #21:
score: 0
Accepted
time: 215ms
memory: 14876kb
input:
100000 95040 98280 75600 85680 83160 92400 95040 65520 55440 75600 85680 95760 83160 65520 85680 90720 85680 75600 95040 95040 98280 65520 92400 92400 65520 83160 95760 90720 92400 55440 65520 92400 65520 95760 85680 90720 95760 90720 95040 65520 55440 98280 98280 75600 98280 55440 90720 65520 98280...
output:
202421813
result:
ok single line: '202421813'
Test #22:
score: 0
Accepted
time: 177ms
memory: 14868kb
input:
100000 83160 98280 98280 98280 98280 83160 83160 98280 83160 83160 98280 98280 98280 98280 98280 83160 83160 83160 98280 98280 98280 98280 98280 98280 98280 98280 83160 83160 83160 98280 83160 98280 83160 83160 83160 98280 83160 83160 98280 83160 83160 83160 98280 83160 98280 83160 98280 98280 83160...
output:
245057894
result:
ok single line: '245057894'
Test #23:
score: 0
Accepted
time: 188ms
memory: 14872kb
input:
100000 98280 83160 98280 98280 83160 98280 83160 83160 83160 83160 98280 98280 98280 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 98280 98280 83160 83160 98280 83160 83160 83160 98280 83160 83160 98280 83160 83160 98280 83160 98280 83160 98280 83160 83160 98280 98280 98280...
output:
528912947
result:
ok single line: '528912947'
Test #24:
score: 0
Accepted
time: 181ms
memory: 14868kb
input:
100000 98280 83160 98280 83160 98280 83160 83160 98280 83160 98280 98280 83160 83160 98280 98280 98280 83160 83160 98280 83160 83160 98280 98280 98280 83160 83160 83160 98280 98280 98280 83160 98280 83160 98280 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 83160 98280 98280 98280 98280...
output:
663696018
result:
ok single line: '663696018'
Test #25:
score: 0
Accepted
time: 173ms
memory: 14724kb
input:
100000 98280 83160 83160 83160 83160 83160 83160 98280 83160 98280 83160 83160 98280 83160 83160 98280 83160 83160 98280 98280 83160 98280 83160 83160 83160 98280 83160 98280 98280 98280 98280 83160 98280 83160 98280 83160 98280 98280 98280 98280 98280 98280 98280 83160 83160 98280 98280 98280 83160...
output:
185293781
result:
ok single line: '185293781'
Test #26:
score: 0
Accepted
time: 176ms
memory: 14724kb
input:
100000 83160 98280 83160 98280 98280 83160 98280 98280 83160 98280 83160 98280 98280 83160 83160 98280 83160 83160 83160 98280 98280 98280 98280 98280 83160 98280 83160 83160 98280 83160 98280 98280 83160 83160 83160 83160 83160 83160 83160 83160 98280 98280 98280 98280 83160 83160 83160 83160 98280...
output:
265618970
result:
ok single line: '265618970'
Test #27:
score: 0
Accepted
time: 125ms
memory: 14864kb
input:
100000 6748 69788 47260 32480 33942 8188 11479 78664 53113 73255 72304 66716 84089 23818 89927 12933 30905 34034 84229 54762 91319 49293 94715 87966 91496 99505 17334 38844 78839 99605 3668 3081 4280 49023 55926 37506 53303 5751 17404 69716 65284 67418 34181 6252 63092 13391 50498 63161 2336 78092 6...
output:
160307784
result:
ok single line: '160307784'
Test #28:
score: 0
Accepted
time: 146ms
memory: 14784kb
input:
100000 36693 74588 16740 13832 50825 52864 16936 18083 3638 13862 70146 96614 58612 48809 99800 32563 34063 39829 25887 63951 99448 13271 85503 77170 83384 47076 3866 40138 83223 18369 69671 94601 97967 42839 56265 72834 37368 78674 57258 91559 41290 11977 57230 95197 10241 49035 2851 91122 24829 17...
output:
554262457
result:
ok single line: '554262457'
Test #29:
score: 0
Accepted
time: 105ms
memory: 14788kb
input:
100000 84569 34031 4228 7376 19559 52455 28768 29106 53141 13488 23960 29617 7830 62630 11135 33979 12467 48342 5864 40166 82966 47314 34488 2828 2527 18966 73049 36609 23768 89555 29171 93051 1991 49912 35098 68600 39096 78039 85825 11757 70024 14491 57941 53860 89313 63841 74508 40403 34047 42177 ...
output:
797657432
result:
ok single line: '797657432'
Test #30:
score: 0
Accepted
time: 103ms
memory: 14908kb
input:
100000 45286 93143 22827 37213 37159 18971 51524 32208 59869 28956 53278 88584 93369 89164 49622 51530 25244 64430 45694 75680 20664 23452 14824 18371 92132 33013 27654 79082 9740 50616 81017 70773 52583 80609 44874 55839 41913 79135 51204 2289 61357 44901 31020 48708 65048 63264 91120 82386 9556 54...
output:
76546307
result:
ok single line: '76546307'
Test #31:
score: 0
Accepted
time: 109ms
memory: 14808kb
input:
100000 18017 13136 53161 11222 34529 90802 19730 5468 34092 80846 4644 22895 8597 79211 29451 29153 70397 80427 41431 59258 8714 39102 26588 64092 6542 39933 10714 43534 36605 98350 36454 90632 61650 92387 13238 35631 98838 68804 62993 91499 25414 83427 8773 8041 84712 87832 92207 80279 32098 79683 ...
output:
909129079
result:
ok single line: '909129079'
Test #32:
score: 0
Accepted
time: 60ms
memory: 14260kb
input:
63 221 895 89 673 890 9 855 685 232 330 21 868 659 982 291 20 364 952 770 906 288 853 547 430 447 734 14 411 422 242 915 728 454 937 948 129 803 914 713 118 277 390 658 154 938 394 649 45 66 513 774 811 914 664 672 595 154 873 579 841 135 40 84
output:
63778565
result:
ok single line: '63778565'
Test #33:
score: 0
Accepted
time: 83ms
memory: 14284kb
input:
56 770 448 54 926 667 184 139 840 118 577 469 470 388 793 208 743 626 970 11 847 874 362 226 695 655 955 363 723 588 660 697 315 590 750 356 858 173 151 823 514 392 171 9 343 918 206 189 767 21 627 826 608 246 856 611 186
output:
876601404
result:
ok single line: '876601404'