Submission #3599234
Source Code Expand
#include <algorithm> #include <cmath> #include <chrono> #include <cstdio> #include <ctime> #include <iostream> #include <random> #include <string> #include <vector> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() /*---------------------------------------*/ const int MAX = 300000; const int MOD = 998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int n; cin >> n; vector<int> a(n); vector<int> length(MAX+1, 0); int first1 = 0, max_num = 0; bool start1 = false; REP(i, n) { cin >> a[i]; max_num = max(max_num, a[i]); if (a[i] == 1) { ++length[1]; if (start1) { first1 = i; start1 = false; } } else if (first1 == 0) { start1 = true; } } vector<int> b(n+1, 0); int i = 0; FOR(j, first1, n) { b[i] = a[j]; ++i; } FOR(j, 0, first1) { b[i] = a[j]; ++i; } long long ans = 1; vector<bool> already(MAX+1, false); int nexti; // vector<int> p(n, 0); // p[0] = 1; for (int i = length[1]; i < n; i = nexti) { if (already[b[i]]) { cout << 0 << "\n"; return 0; } else { already[b[i]] = true; } nexti = i + 1; while (b[nexti] == b[i]) ++nexti; if (nexti - i > length[1]) { cout << 0 << "\n"; return 0; } length[b[i]] = nexti - i; if (b[i-1] > b[i]) { // p[i] = b[i]; if (b[nexti] > b[nexti-1] && length[b[i]] != length[1]) { cout << 0 << "\n"; return 0; } } else if (b[nexti] > b[nexti-1]) { // p[nexti-length[i]] = b[i]; } else { ans *= (length[1] - (length[b[i]]) + 1) % MOD; } } FOR (i, 2, max_num+1) { if (!already[i]) { bool to_next = false; int last = 0, temp = 0, loop_count = 0, temp_loop_count = 0; for(int j = 0; j < n; j += length[b[j]]) { if (b[j] < i) { if (to_next) { temp += length[b[j]]; ++temp_loop_count; } else { last += length[b[j]]; ++loop_count; } } else if (to_next) { last = max(last, temp); if (last == temp) { loop_count = temp_loop_count; } temp = 0; } else { to_next = true; } } last -= length[1] + loop_count - 1; last %= MOD; ans *= last; } } for (int i = n - max_num; i > 1; --i) { ans *= i; ans %= MOD; } cout << ans << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Circular |
User | emthrm |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2713 Byte |
Status | WA |
Exec Time | 2103 ms |
Memory | 3840 KB |
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 900 | ||||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt, s4.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt, 67.txt, 68.txt, 69.txt, 70.txt, 71.txt, 72.txt, 73.txt, 74.txt, 75.txt, 76.txt, 77.txt, 78.txt, 79.txt, 80.txt, 81.txt, 82.txt, 83.txt, 84.txt, 85.txt, 86.txt, 87.txt, 88.txt, 89.txt, 90.txt, 91.txt, 92.txt, 93.txt, 94.txt, 95.txt, 96.txt, 97.txt, 98.txt, 99.txt, s1.txt, s2.txt, s3.txt, s4.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | TLE | 2103 ms | 3840 KB |
02.txt | TLE | 2103 ms | 3840 KB |
03.txt | TLE | 2103 ms | 3840 KB |
04.txt | TLE | 2103 ms | 3840 KB |
05.txt | WA | 96 ms | 3840 KB |
06.txt | WA | 33 ms | 3840 KB |
07.txt | WA | 23 ms | 3840 KB |
08.txt | WA | 22 ms | 3840 KB |
09.txt | WA | 21 ms | 3840 KB |
10.txt | AC | 31 ms | 3840 KB |
11.txt | TLE | 2103 ms | 3840 KB |
12.txt | TLE | 2103 ms | 3840 KB |
13.txt | TLE | 2103 ms | 3840 KB |
14.txt | TLE | 2103 ms | 3840 KB |
15.txt | WA | 119 ms | 3840 KB |
16.txt | WA | 34 ms | 3840 KB |
17.txt | WA | 23 ms | 3840 KB |
18.txt | WA | 22 ms | 3840 KB |
19.txt | WA | 21 ms | 3840 KB |
20.txt | AC | 31 ms | 3840 KB |
21.txt | TLE | 2103 ms | 3840 KB |
22.txt | AC | 28 ms | 3840 KB |
23.txt | AC | 26 ms | 3840 KB |
24.txt | AC | 24 ms | 3840 KB |
25.txt | AC | 23 ms | 3840 KB |
26.txt | AC | 23 ms | 3840 KB |
27.txt | AC | 21 ms | 3840 KB |
28.txt | WA | 22 ms | 3840 KB |
29.txt | WA | 21 ms | 3840 KB |
30.txt | AC | 31 ms | 3840 KB |
31.txt | TLE | 2103 ms | 3840 KB |
32.txt | TLE | 2103 ms | 3840 KB |
33.txt | TLE | 2103 ms | 3840 KB |
34.txt | TLE | 2103 ms | 3840 KB |
35.txt | WA | 101 ms | 3840 KB |
36.txt | WA | 34 ms | 3840 KB |
37.txt | WA | 23 ms | 3840 KB |
38.txt | WA | 22 ms | 3840 KB |
39.txt | WA | 21 ms | 3840 KB |
40.txt | AC | 31 ms | 3840 KB |
41.txt | WA | 21 ms | 3840 KB |
42.txt | WA | 21 ms | 3840 KB |
43.txt | AC | 28 ms | 3840 KB |
44.txt | AC | 26 ms | 3840 KB |
45.txt | AC | 29 ms | 3840 KB |
46.txt | AC | 22 ms | 3840 KB |
47.txt | AC | 28 ms | 3840 KB |
48.txt | AC | 23 ms | 3840 KB |
49.txt | AC | 21 ms | 3840 KB |
50.txt | AC | 20 ms | 3840 KB |
51.txt | AC | 20 ms | 3840 KB |
52.txt | AC | 21 ms | 3840 KB |
53.txt | AC | 20 ms | 3840 KB |
54.txt | AC | 21 ms | 3840 KB |
55.txt | AC | 21 ms | 3840 KB |
56.txt | AC | 21 ms | 3840 KB |
57.txt | AC | 21 ms | 3840 KB |
58.txt | AC | 21 ms | 3840 KB |
59.txt | AC | 21 ms | 3840 KB |
60.txt | AC | 30 ms | 3840 KB |
61.txt | AC | 28 ms | 3840 KB |
62.txt | AC | 26 ms | 3840 KB |
63.txt | AC | 26 ms | 3840 KB |
64.txt | AC | 24 ms | 3840 KB |
65.txt | AC | 23 ms | 3840 KB |
66.txt | AC | 22 ms | 3840 KB |
67.txt | AC | 21 ms | 3840 KB |
68.txt | AC | 20 ms | 3840 KB |
69.txt | AC | 20 ms | 3840 KB |
70.txt | AC | 31 ms | 3840 KB |
71.txt | AC | 30 ms | 3840 KB |
72.txt | AC | 27 ms | 3840 KB |
73.txt | AC | 27 ms | 3840 KB |
74.txt | AC | 24 ms | 3840 KB |
75.txt | AC | 23 ms | 3840 KB |
76.txt | AC | 23 ms | 3840 KB |
77.txt | AC | 23 ms | 3840 KB |
78.txt | AC | 20 ms | 3840 KB |
79.txt | AC | 20 ms | 3840 KB |
80.txt | AC | 28 ms | 3840 KB |
81.txt | AC | 28 ms | 3840 KB |
82.txt | TLE | 2103 ms | 3840 KB |
83.txt | AC | 26 ms | 3840 KB |
84.txt | AC | 24 ms | 3840 KB |
85.txt | AC | 23 ms | 3840 KB |
86.txt | AC | 22 ms | 3840 KB |
87.txt | AC | 21 ms | 3840 KB |
88.txt | AC | 20 ms | 3840 KB |
89.txt | AC | 2 ms | 1408 KB |
90.txt | WA | 2 ms | 1408 KB |
91.txt | AC | 2 ms | 1408 KB |
92.txt | AC | 2 ms | 1408 KB |
93.txt | AC | 2 ms | 1408 KB |
94.txt | TLE | 2103 ms | 1408 KB |
95.txt | AC | 2 ms | 1408 KB |
96.txt | AC | 2 ms | 1408 KB |
97.txt | AC | 2 ms | 1408 KB |
98.txt | AC | 2 ms | 1408 KB |
99.txt | AC | 2 ms | 1408 KB |
s1.txt | AC | 2 ms | 1408 KB |
s2.txt | TLE | 2103 ms | 1408 KB |
s3.txt | AC | 2 ms | 1408 KB |
s4.txt | AC | 2 ms | 1408 KB |