Submission #775614

# Submission time Handle Problem Language Result Execution time Memory
775614 2023-07-06T15:34:08 Z Essa2006 Fortune Telling 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 12492 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=k-1;j>=0;j--){
            if(T[j]>=mx)
                cnt++;
            else if(T[j]>=mn)
                T2.push_back(1);
            if(!j || (T[j-1]>=mn  && T[j-1]<mx)){
                if(cnt&1)
                    T2.push_back(2);
                cnt=0;
            }
            if(T2.size()==2 || (T2.size()==1 && T2[0]==1))
                break;
        }
        reverse(all(T2));
        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 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 19 ms 3332 KB Output is correct
15 Correct 43 ms 6328 KB Output is correct
16 Correct 80 ms 9468 KB Output is correct
17 Correct 94 ms 12444 KB Output is correct
18 Correct 91 ms 12492 KB Output is correct
19 Correct 90 ms 12484 KB Output is correct
20 Correct 106 ms 12416 KB Output is correct
21 Correct 91 ms 12460 KB Output is correct
22 Correct 52 ms 8708 KB Output is correct
23 Correct 46 ms 6860 KB Output is correct
24 Correct 42 ms 5496 KB Output is correct
25 Correct 57 ms 9720 KB Output is correct
26 Correct 2858 ms 7952 KB Output is correct
27 Execution timed out 3052 ms 8776 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 19 ms 3332 KB Output is correct
15 Correct 43 ms 6328 KB Output is correct
16 Correct 80 ms 9468 KB Output is correct
17 Correct 94 ms 12444 KB Output is correct
18 Correct 91 ms 12492 KB Output is correct
19 Correct 90 ms 12484 KB Output is correct
20 Correct 106 ms 12416 KB Output is correct
21 Correct 91 ms 12460 KB Output is correct
22 Correct 52 ms 8708 KB Output is correct
23 Correct 46 ms 6860 KB Output is correct
24 Correct 42 ms 5496 KB Output is correct
25 Correct 57 ms 9720 KB Output is correct
26 Correct 2858 ms 7952 KB Output is correct
27 Execution timed out 3052 ms 8776 KB Time limit exceeded
28 Halted 0 ms 0 KB -