Submission #2793263
Source Code Expand
/** * File : F.cpp * Author : Kazune Takahashi * Created : 2018-7-2 20:45:55 * Powered by Visual Studio Code */ #include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> #include <random> // random_device rd; mt19937 mt(rd()); uniform_int_distribution<int> ra(0, 99); ra(mt); #include <chrono> // std::chrono::system_clock::time_point start_time, end_time; // start = std::chrono::system_clock::now(); // double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count(); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> using namespace std; #define DEBUG 0 // change 0 -> 1 if we need debug. typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; // const int C = 1e6+10; const ll MOD = 1000000007; const ll M = 250010; random_device rd; mt19937 mt(rd()); uniform_int_distribution<ll> ra(1, MOD - 1); typedef tuple<ll, ll> D; int N; string S; map<ll, int> ans; ll X; ll X_inv; ll C; ll a[500100]; D g[250010]; map<ll, ll> G; ll power2(int i) { if (i == 0) { return 1; } else if (i % 2 == 0) { ll half = power2(i / 2); return (half * half) % MOD; } else { return (power2(i - 1) * X) % MOD; } } ll power(int i) { if (i == 0) { return 1; } else if (i < 0) { return power2(MOD + i - 1); } return power2(i); } ll calc_hash() { fill(a, a + 500100, 0); int P = M; for (auto e : S) { if (e == '+') { a[P]++; } else if (e == '-') { a[P]--; } else if (e == '>') { P++; } else { P--; } } ll res = 0; for (auto i = 0; i < 500100; i++) { res += (((MOD + a[i]) % MOD) * power(i - M)) % MOD; res %= MOD; } return res; } void calc_g() { g[N] = D(1, 0); for (auto i = N - 1; i >= 0; i--) { ll A_prime = get<0>(g[i + 1]); ll B_prime = get<1>(g[i + 1]); ll A, B; if (S[i] == '+') { A = 1, B = MOD - 1; } else if (S[i] == '-') { A = 1, B = 1; } else if (S[i] == '>') { A = X_inv, B = 0; } else { A = X, B = 0; } g[i] = D((A_prime * A) % MOD, ((A_prime * B) % MOD + B_prime) % MOD); } } ll count_ans() { ll res = 0; G.clear(); for (int i = N; i >= 1; i--) { ll J = get<1>(g[i]); if (G.find(J) == G.end()) { G[J] = 1; } else { G[J]++; } ll I = ((get<0>(g[i - 1]) * C) % MOD + get<1>(g[i - 1])) % MOD; if (G.find(I) != G.end()) { // cerr << "i = " << i - 1 << ", cnt of j = " << G[I] << endl; res += G[I]; } } return res; } void solve() { X = ra(mt); X_inv = power(-1); C = calc_hash(); calc_g(); ll res = count_ans(); if (ans.find(res) == ans.end()) { ans[res] = 1; } else { ans[res]++; } } int main() { cin >> N >> S; for (auto i = 0; i < 4; i++) { solve(); } ll res = 0; int maxi = 0; for (auto e : ans) { ll a = e.first; int cnt = e.second; if (cnt > maxi) { cnt = maxi; res = a; } } cout << res << endl; }
Submission Info
Submission Time | |
---|---|
Task | F - Eating Symbols Hard |
User | kazunetakahashi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3669 Byte |
Status | WA |
Exec Time | 1654 ms |
Memory | 23940 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1200 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 4.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 5.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 6.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt, 67.txt, 68.txt, 69.txt, 7.txt, 70.txt, 71.txt, 72.txt, 73.txt, 74.txt, 75.txt, 76.txt, 77.txt, 78.txt, 8.txt, 9.txt, a.txt, b.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
1.txt | AC | 496 ms | 6016 KB |
10.txt | AC | 682 ms | 9604 KB |
11.txt | WA | 685 ms | 9732 KB |
12.txt | AC | 640 ms | 9220 KB |
13.txt | WA | 644 ms | 9348 KB |
14.txt | AC | 582 ms | 8452 KB |
15.txt | AC | 584 ms | 8452 KB |
16.txt | WA | 937 ms | 13444 KB |
17.txt | AC | 660 ms | 9732 KB |
18.txt | WA | 792 ms | 10884 KB |
19.txt | WA | 792 ms | 11396 KB |
2.txt | AC | 496 ms | 6016 KB |
20.txt | AC | 641 ms | 9348 KB |
21.txt | AC | 582 ms | 8452 KB |
22.txt | WA | 935 ms | 13444 KB |
23.txt | WA | 653 ms | 9604 KB |
24.txt | WA | 794 ms | 10884 KB |
25.txt | WA | 725 ms | 10372 KB |
26.txt | AC | 640 ms | 9348 KB |
27.txt | AC | 584 ms | 8452 KB |
28.txt | WA | 943 ms | 13444 KB |
29.txt | WA | 664 ms | 9732 KB |
3.txt | AC | 504 ms | 6400 KB |
30.txt | WA | 795 ms | 10884 KB |
31.txt | WA | 918 ms | 13188 KB |
32.txt | AC | 642 ms | 9348 KB |
33.txt | AC | 584 ms | 8452 KB |
34.txt | WA | 942 ms | 13444 KB |
35.txt | WA | 661 ms | 9732 KB |
36.txt | WA | 794 ms | 10884 KB |
37.txt | WA | 769 ms | 11140 KB |
38.txt | AC | 641 ms | 9348 KB |
39.txt | AC | 583 ms | 8452 KB |
4.txt | WA | 939 ms | 13444 KB |
40.txt | WA | 935 ms | 13444 KB |
41.txt | AC | 655 ms | 9604 KB |
42.txt | WA | 793 ms | 10884 KB |
43.txt | WA | 758 ms | 10884 KB |
44.txt | AC | 639 ms | 9220 KB |
45.txt | AC | 583 ms | 8452 KB |
46.txt | AC | 566 ms | 8452 KB |
47.txt | AC | 526 ms | 8452 KB |
48.txt | AC | 527 ms | 8452 KB |
49.txt | AC | 720 ms | 13572 KB |
5.txt | WA | 938 ms | 13444 KB |
50.txt | AC | 1654 ms | 23940 KB |
51.txt | AC | 525 ms | 8452 KB |
52.txt | WA | 939 ms | 13444 KB |
53.txt | WA | 660 ms | 9732 KB |
54.txt | WA | 794 ms | 10884 KB |
55.txt | WA | 831 ms | 12036 KB |
56.txt | AC | 641 ms | 9348 KB |
57.txt | AC | 582 ms | 8452 KB |
58.txt | WA | 981 ms | 14596 KB |
59.txt | WA | 966 ms | 14596 KB |
6.txt | WA | 657 ms | 9604 KB |
60.txt | WA | 767 ms | 9732 KB |
61.txt | WA | 767 ms | 9732 KB |
62.txt | WA | 1333 ms | 22532 KB |
63.txt | WA | 1353 ms | 22532 KB |
64.txt | WA | 691 ms | 9860 KB |
65.txt | WA | 690 ms | 9860 KB |
66.txt | WA | 698 ms | 9860 KB |
67.txt | WA | 1101 ms | 18052 KB |
68.txt | WA | 848 ms | 14592 KB |
69.txt | WA | 898 ms | 15236 KB |
7.txt | AC | 662 ms | 9732 KB |
70.txt | WA | 943 ms | 16388 KB |
71.txt | WA | 982 ms | 16772 KB |
72.txt | WA | 1017 ms | 17412 KB |
73.txt | WA | 982 ms | 16132 KB |
74.txt | WA | 992 ms | 16388 KB |
75.txt | WA | 971 ms | 15876 KB |
76.txt | WA | 1041 ms | 17284 KB |
77.txt | WA | 927 ms | 15108 KB |
78.txt | WA | 1081 ms | 17668 KB |
8.txt | WA | 797 ms | 10884 KB |
9.txt | WA | 797 ms | 10884 KB |
a.txt | AC | 496 ms | 6016 KB |
b.txt | AC | 496 ms | 6016 KB |
sample1.txt | AC | 496 ms | 6016 KB |
sample2.txt | AC | 496 ms | 6016 KB |
sample3.txt | AC | 496 ms | 6016 KB |