답안 #775612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775612 2023-07-06T15:31:46 Z Essa2006 운세 보기 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 13692 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)
                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++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 548 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 548 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 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 3384 KB Output is correct
15 Correct 42 ms 6392 KB Output is correct
16 Correct 72 ms 9384 KB Output is correct
17 Correct 116 ms 13676 KB Output is correct
18 Correct 95 ms 13684 KB Output is correct
19 Correct 90 ms 13628 KB Output is correct
20 Correct 111 ms 13692 KB Output is correct
21 Correct 89 ms 13552 KB Output is correct
22 Correct 53 ms 9360 KB Output is correct
23 Correct 49 ms 7508 KB Output is correct
24 Correct 42 ms 6128 KB Output is correct
25 Correct 60 ms 10480 KB Output is correct
26 Correct 2645 ms 8984 KB Output is correct
27 Execution timed out 3054 ms 9868 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 548 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 4 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 3384 KB Output is correct
15 Correct 42 ms 6392 KB Output is correct
16 Correct 72 ms 9384 KB Output is correct
17 Correct 116 ms 13676 KB Output is correct
18 Correct 95 ms 13684 KB Output is correct
19 Correct 90 ms 13628 KB Output is correct
20 Correct 111 ms 13692 KB Output is correct
21 Correct 89 ms 13552 KB Output is correct
22 Correct 53 ms 9360 KB Output is correct
23 Correct 49 ms 7508 KB Output is correct
24 Correct 42 ms 6128 KB Output is correct
25 Correct 60 ms 10480 KB Output is correct
26 Correct 2645 ms 8984 KB Output is correct
27 Execution timed out 3054 ms 9868 KB Time limit exceeded
28 Halted 0 ms 0 KB -