Submission #13636

# Submission time Handle Problem Language Result Execution time Memory
13636 2015-02-26T13:58:29 Z gs14004 Fortune Telling 2 (JOI14_fortune_telling2) C++14
4 / 100
2000 ms 4508 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> v;
int n,k;

int a[200005], b[200005], q[200005];
bool flip[200005];

int main(){
    scanf("%d %d",&n,&k);
    for (int i=0; i<n; i++) {
        scanf("%d %d",&a[i],&b[i]);
        if(a[i] > b[i]){
            swap(a[i],b[i]);
            flip[i] = 1;
        }
        v.push_back(a[i]);
        v.push_back(b[i]);
    }
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end()) - v.begin());
    for (int i=0; i<n; i++) {
        a[i] = (int)(lower_bound(v.begin(),v.end(),a[i]) - v.begin());
        b[i] = (int)(lower_bound(v.begin(),v.end(),b[i]) - v.begin());
    }
    for (int i=0; i<k; i++) {
        scanf("%d",&q[i]);
        q[i] = (int)(upper_bound(v.begin(),v.end(),q[i]) - v.begin()) - 1;
    }
    for (int i=0; i<k; i++) {
        for (int j=0; j<n; j++) {
            if(b[j] <= q[i]){
                flip[j] ^= 1;
            }
            else if(a[j] <= q[i]){
                flip[j] = 1;
            }
        }
    }
    long long ret = 0;
    for (int i=0; i<n; i++) {
        if(flip[i]) ret += v[b[i]];
        else ret += v[a[i]];
    }
    printf("%lld",ret);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4120 KB Output is correct
2 Correct 3 ms 4120 KB Output is correct
3 Correct 6 ms 4120 KB Output is correct
4 Correct 3 ms 4120 KB Output is correct
5 Correct 6 ms 4120 KB Output is correct
6 Correct 6 ms 4120 KB Output is correct
7 Correct 5 ms 4120 KB Output is correct
8 Correct 4 ms 4120 KB Output is correct
9 Correct 3 ms 4120 KB Output is correct
10 Correct 2 ms 4120 KB Output is correct
11 Correct 2 ms 4120 KB Output is correct
12 Correct 2 ms 4120 KB Output is correct
13 Correct 5 ms 4120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 589 ms 4252 KB Output is correct
2 Execution timed out 2000 ms 4508 KB Program timed out
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2000 ms 4248 KB Program timed out
2 Halted 0 ms 0 KB -