Submission #1046285

# Submission time Handle Problem Language Result Execution time Memory
1046285 2024-08-06T12:29:31 Z Nickpapadak Exam (eJOI20_exam) C++14
0 / 100
3 ms 2652 KB
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010LL
#define INF 1000000010LL
#define ll long long
ll N, B[MAXN];
ll A[MAXN];
pair<ll,ll> Range[MAXN];

ll solveEQ(){
    ll ans = 0;
    ll i = 1, j =1;
    bool foundB = false;
    for(;j<=N;++j){
        if(A[j] > B[1]) {
            ans += (j-i) * (ll) foundB;
            i= j+1;
            foundB = false;
        }
        else if(A[j] == B[1]) foundB= true;
    }
    return ans;
}

void setRange(){
    A[0] = INF;
    A[N+1] = INF;
    for(ll i =1;i<=N;++i){
        ll j =i,k =i;
        while(A[j-1] <= A[i] || A[k+1] <=A[i]){
            if(A[j-1] <= A[i]) --j;
            if(A[k+1] <= A[i]) ++k;
        }
        Range[i] = {j,k};
    }
}

ll solveSORT(){
    ll ans =0;
    for(ll i = 1;i<=N;++i){
        for(ll j = Range[i].first; j<=Range[i].second; ++j){
            if(B[j] == A[i]) ans++;
        }
    }
    
    return ans;
}

int main(){
    scanf("%lld",&N);
    for(ll i=1;i<=N;++i){
        scanf("%lld",&A[i]);
    }
    bool AllB = true;
    for(ll i =1;i<=N;++i){
        scanf("%lld",&B[i]);
        if(B[i] != B[i-1] && i > 1) AllB = false;
    }
    if(AllB)
        printf("%lld\n", solveEQ());
    else if(is_sorted(A+1, A+N+1)){
        setRange();
        printf("%lld\n", solveSORT());
    }
    
    return 0;
}

Compilation message

exam.cpp: In function 'int main()':
exam.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
exam.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%lld",&A[i]);
      |         ~~~~~^~~~~~~~~~~~~~
exam.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%lld",&B[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Incorrect 3 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -