# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126634 | 2019-07-08T08:04:08 Z | fizzydavid | Fortune Telling 2 (JOI14_fortune_telling2) | C++14 | 3000 ms | 1136 KB |
//by yjz #include<bits/stdc++.h> #define FF first #define SS second #define MP make_pair #define PB push_back typedef long long ll; using namespace std; const int maxn = 400111; int n, m; vector<int> pts; int getid(int x) {return lower_bound(pts.begin(), pts.end(), x+1)-pts.begin();} pair<int,int> p[maxn]; int arr[maxn]; int main() { scanf("%d%d", &n, &m); for (int i=1; i<=n; i++) { scanf("%d%d", &p[i].FF, &p[i].SS); pts.PB(p[i].FF); pts.PB(p[i].SS); } sort(pts.begin(), pts.end()); pts.erase(unique(pts.begin(), pts.end()), pts.end()); for (int i=1; i<=n; i++) p[i].FF = getid(p[i].FF), p[i].SS = getid(p[i].SS); for (int i=1; i<=m; i++) { scanf("%d", &arr[i]); arr[i] = getid(arr[i]); } // for (int i=1; i<=n; i++) cerr<<p[i].FF<<","<<p[i].SS<<endl; // for (int i=1; i<=m; i++) cerr<<arr[i]<<" "; cerr<<endl; ll ans = 0; for (int i=1; i<=n; i++) { int x = p[i].FF, y = p[i].SS; bool flip = false; if (x>y) flip = true, swap(x, y); int lst = -1; for (int j=1; j<=m; j++) { if (arr[j]>=x&&arr[j]<y) { lst = j; } } if (lst==-1) { for (int j=1; j<=m; j++) flip ^= arr[j]>=y; } else { flip = true; for (int j=lst+1; j<=m; j++) flip ^= arr[j]>=y; } if (flip) ans += pts[y-1]; else ans += pts[x-1]; } cout<<ans<<endl; return 0; } /* 5 3 4 6 9 1 8 8 4 2 3 7 8 2 9 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 6 ms | 376 KB | Output is correct |
5 | Correct | 6 ms | 376 KB | Output is correct |
6 | Correct | 6 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 6 ms | 376 KB | Output is correct |
12 | Correct | 10 ms | 376 KB | Output is correct |
13 | Correct | 7 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 6 ms | 376 KB | Output is correct |
5 | Correct | 6 ms | 376 KB | Output is correct |
6 | Correct | 6 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 6 ms | 376 KB | Output is correct |
12 | Correct | 10 ms | 376 KB | Output is correct |
13 | Correct | 7 ms | 376 KB | Output is correct |
14 | Correct | 366 ms | 712 KB | Output is correct |
15 | Correct | 1436 ms | 900 KB | Output is correct |
16 | Execution timed out | 3036 ms | 1136 KB | Time limit exceeded |
17 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 6 ms | 376 KB | Output is correct |
5 | Correct | 6 ms | 376 KB | Output is correct |
6 | Correct | 6 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 4 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 4 ms | 376 KB | Output is correct |
11 | Correct | 6 ms | 376 KB | Output is correct |
12 | Correct | 10 ms | 376 KB | Output is correct |
13 | Correct | 7 ms | 376 KB | Output is correct |
14 | Correct | 366 ms | 712 KB | Output is correct |
15 | Correct | 1436 ms | 900 KB | Output is correct |
16 | Execution timed out | 3036 ms | 1136 KB | Time limit exceeded |
17 | Halted | 0 ms | 0 KB | - |