Submission #775611

# Submission time Handle Problem Language Result Execution time Memory
775611 2023-07-06T15:30:08 Z Essa2006 Fortune Telling 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 10332 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int n, k;
vector<int>A, B, T;
map<int, int>mp, inv;

void pre(){
    A.clear(), B.clear(), T.clear(), mp.clear(), inv.clear();
    A.resize(n), B.resize(n), T.resize(k);
}



void comp(){
    vector<int>S=T;
    for(int i=0;i<n;i++){
        S.push_back(A[i]);
        S.push_back(B[i]);
    }
    sort(all(S));
    int cnt=1;
    for(int i=0;i<S.size();i++){
        if(!i || S[i]!=S[i-1]){
            mp[S[i]]=cnt, inv[cnt]=S[i], cnt++;
        }
    }
    for(int i=0;i<n;i++){
        A[i]=mp[A[i]], B[i]=mp[B[i]];
    }
    for(int j=0;j<k;j++){
        T[j]=mp[T[j]];
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>k;
    pre();
    for(int i=0;i<n;i++){
        cin>>A[i]>>B[i];
    }
    for(int j=0;j<k;j++){
        cin>>T[j];
    }
    comp();
    for(int i=0;i<n;i++){
        vector<int>T2;
        int cnt=0;
        int mn=min(A[i], B[i]), mx=max(A[i], B[i]);
        for(int j=0;j<k;j++){
            if(T[j]>=mx)
                cnt++;
            else if(T[j]>=mn)
                T2.push_back(1);
            if(j==k-1 || (T[j+1]>=mn  && T[j+1]<mx)){
                if(cnt&1)
                    T2.push_back(2);
                cnt=0;
            }
                
        }
        if(T2.size()==1 && (A[i]==mn || (T2[0]==2)))
            swap(A[i], B[i]);
        if(T2.size()>1 && T2.back()==1)
            A[i]=mx;
        else if(T2.size()>1 && T2.back()==2)
            A[i]=mn;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=inv[A[i]];
    }
    cout<<ans;
}

Compilation message

fortune_telling2.cpp: In function 'void comp()':
fortune_telling2.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=0;i<S.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 8 ms 588 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 8 ms 596 KB Output is correct
6 Correct 8 ms 660 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 6 ms 616 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 4 ms 492 KB Output is correct
12 Correct 5 ms 464 KB Output is correct
13 Correct 5 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 8 ms 588 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 8 ms 596 KB Output is correct
6 Correct 8 ms 660 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 6 ms 616 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 4 ms 492 KB Output is correct
12 Correct 5 ms 464 KB Output is correct
13 Correct 5 ms 456 KB Output is correct
14 Correct 646 ms 3632 KB Output is correct
15 Correct 2500 ms 6960 KB Output is correct
16 Execution timed out 3074 ms 10332 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 8 ms 588 KB Output is correct
4 Correct 8 ms 596 KB Output is correct
5 Correct 8 ms 596 KB Output is correct
6 Correct 8 ms 660 KB Output is correct
7 Correct 5 ms 596 KB Output is correct
8 Correct 6 ms 616 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 4 ms 492 KB Output is correct
12 Correct 5 ms 464 KB Output is correct
13 Correct 5 ms 456 KB Output is correct
14 Correct 646 ms 3632 KB Output is correct
15 Correct 2500 ms 6960 KB Output is correct
16 Execution timed out 3074 ms 10332 KB Time limit exceeded
17 Halted 0 ms 0 KB -