Submission #5023075
Source Code Expand
// And in the end, the love you take is equal to the love you make. // Paul McCartney (the Beatles). The End. Abbey Road. #include <bits/stdc++.h> using namespace std; using LL = long long; namespace _buff { const size_t BUFF = 1 << 19; char buff[BUFF], *begin = buff, *end = buff; char getc() { if (begin == end) { begin = buff; end = buff + fread(buff, 1, BUFF, stdin); } return begin == end ? -1 : *begin++; } } LL read() { using namespace _buff; LL ret = 0; bool pos = true; char c = getc(); for (; (c < '0' || c > '9') && c != '-'; c = getc()) { assert(~c); } if (c == '-') { pos = false; c = getc(); } for (; c >= '0' && c <= '9'; c = getc()) { ret = (ret << 3) + (ret << 1) + (c ^ 48); } return pos ? ret : -ret; } const size_t N = 1e5 + 5; const int MOD = 1e9 + 7; int rmod(int x) { if (x >= MOD) x -= MOD; if (x < 0 ) x += MOD; return x; } void add(int &dp, int val) { dp = rmod(dp + val); } int n; LL s[N], a, b; int f[N], g[N], df[N], dg[N]; int suma[N], sumb[N]; bool calcfg(int j, int i) { return sumb[i] - sumb[j + 1] == 0; } bool calcgf(int j, int i) { return suma[i] - suma[j + 1] == 0; } int main() { n = read(); a = read(); b = read(); generate_n(s + 1, n, read); s[0] = -2e18; s[n + 1] = 2e18; for (int i = 1; i <= n; ++i) { suma[i] = suma[i - 1] + (s[i] - s[i - 1] < a); sumb[i] = sumb[i - 1] + (s[i] - s[i - 1] < b); } f[0] = g[0] = 1; df[0] = dg[0] = 1; df[1] = dg[1] = MOD - 1; for (int i = 0; i <= n; ++i) { if (i) { add(df[i], df[i - 1]); add(dg[i], dg[i - 1]); } f[i] = df[i]; g[i] = dg[i]; if (i == n) break; /* calc f to g */ { static int l = 1, r = 1; while (s[l + 1] - s[i] < a) ++l; if (l <= i) l = i + 1; if (calcfg(i, l)) { if (r < l) r = l; while (r < n && calcfg(i, r + 1)) ++r; add(dg[l], f[i]); add(dg[r + 1], -f[i]); } } /* calc g to f */ { static int l = 1, r = 1; while (s[l + 1] - s[i] < b) ++l; if (l <= i) l = i + 1; if (calcgf(i, l)) { if (r < l) r = l; while (r < n && calcgf(i, r + 1)) ++r; add(df[l], g[i]); add(df[r + 1], -g[i]); } } } cout << rmod(f[n] + g[n]) << '\n'; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Division into Two |
User | nickluo |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 2443 Byte |
Status | AC |
Exec Time | 10 ms |
Memory | 3840 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1100 / 1100 | ||||
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, s1.txt, s2.txt, s3.txt, s4.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 10 ms | 3840 KB |
02.txt | AC | 9 ms | 3840 KB |
03.txt | AC | 9 ms | 3840 KB |
04.txt | AC | 9 ms | 3840 KB |
05.txt | AC | 9 ms | 3840 KB |
06.txt | AC | 9 ms | 3840 KB |
07.txt | AC | 9 ms | 3840 KB |
08.txt | AC | 10 ms | 3840 KB |
09.txt | AC | 9 ms | 3840 KB |
10.txt | AC | 9 ms | 3840 KB |
11.txt | AC | 9 ms | 3840 KB |
12.txt | AC | 10 ms | 3840 KB |
13.txt | AC | 9 ms | 3840 KB |
14.txt | AC | 9 ms | 3840 KB |
15.txt | AC | 9 ms | 3840 KB |
16.txt | AC | 6 ms | 3840 KB |
17.txt | AC | 7 ms | 3840 KB |
18.txt | AC | 8 ms | 3840 KB |
19.txt | AC | 7 ms | 3840 KB |
20.txt | AC | 8 ms | 3840 KB |
21.txt | AC | 8 ms | 3840 KB |
22.txt | AC | 8 ms | 3840 KB |
23.txt | AC | 6 ms | 3840 KB |
24.txt | AC | 7 ms | 3840 KB |
25.txt | AC | 9 ms | 3840 KB |
26.txt | AC | 8 ms | 3840 KB |
27.txt | AC | 9 ms | 3840 KB |
28.txt | AC | 9 ms | 3840 KB |
29.txt | AC | 8 ms | 3840 KB |
30.txt | AC | 8 ms | 3840 KB |
31.txt | AC | 8 ms | 3840 KB |
32.txt | AC | 8 ms | 3840 KB |
33.txt | AC | 8 ms | 3840 KB |
34.txt | AC | 7 ms | 3840 KB |
35.txt | AC | 8 ms | 3840 KB |
36.txt | AC | 7 ms | 3840 KB |
37.txt | AC | 6 ms | 3840 KB |
38.txt | AC | 7 ms | 3840 KB |
39.txt | AC | 9 ms | 3840 KB |
40.txt | AC | 6 ms | 3840 KB |
41.txt | AC | 6 ms | 3840 KB |
42.txt | AC | 5 ms | 3840 KB |
43.txt | AC | 10 ms | 3840 KB |
44.txt | AC | 10 ms | 3840 KB |
45.txt | AC | 10 ms | 3840 KB |
46.txt | AC | 10 ms | 3840 KB |
47.txt | AC | 10 ms | 3840 KB |
48.txt | AC | 10 ms | 3840 KB |
49.txt | AC | 1 ms | 256 KB |
50.txt | AC | 1 ms | 256 KB |
51.txt | AC | 1 ms | 256 KB |
52.txt | AC | 1 ms | 256 KB |
53.txt | AC | 1 ms | 256 KB |
54.txt | AC | 1 ms | 256 KB |
55.txt | AC | 1 ms | 256 KB |
56.txt | AC | 1 ms | 256 KB |
57.txt | AC | 1 ms | 256 KB |
58.txt | AC | 1 ms | 256 KB |
59.txt | AC | 1 ms | 256 KB |
60.txt | AC | 1 ms | 256 KB |
61.txt | AC | 1 ms | 256 KB |
62.txt | AC | 1 ms | 256 KB |
63.txt | AC | 1 ms | 256 KB |
64.txt | AC | 1 ms | 256 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |
s3.txt | AC | 1 ms | 256 KB |
s4.txt | AC | 1 ms | 256 KB |