Submission #447498

# Submission time Handle Problem Language Result Execution time Memory
447498 2021-07-26T15:12:21 Z aris12345678 Exam (eJOI20_exam) C++14
0 / 100
246 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1e5+5;
const int mxNumber = 1e9+1;
int a[mxN], b[mxN];

bool sub2(int n) {
    for(int i = 1; i < n; i++) {
        if(b[i] != b[i-1])
            return false;
    }
    return true;
}

int main() {
    int n;
    scanf("%d", &n);
    unordered_map<int, int> mp1;
    mp1.rehash(mxNumber);
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        mp1[a[i]] = i;
    }
    for(int i = 0; i < n; i++)
        scanf("%d", &b[i]);
    if(sub2(n)) {
        int i = 0, j = 0, mx = 0, ans = 0;
        while(j < n) {
            if(a[j] > b[0] && mx == b[0])
                ans += (j-i), mx = 0;
            while(a[j] > b[0])
                j++, i = j;
            mx = max(mx, a[j++]);
        }
        if(mx == b[0])
            ans += (j-i);
        printf("%d\n", ans);
    } else {
        int i = 0, ans = 0;
        while(i < n) {
            if(a[i] > b[i]) i++;
            else if(a[i] == b[i]) {
                ans++, i++;
                continue;
            } else {
                if(mp1.find(b[i]) == mp1.end()) continue;
                map<int, int> mp2;
                int res = 0;
                for(int j = i; j < mp1[b[i]]; j++) {
                    if(a[j] == b[j])
                        res++;
                    mp2[b[j]]++;
                }
                if(mp2.rbegin()->first == b[i]) {
                    ans += mp2[b[i]];
                    ans += res;
                    i = mp1[b[i]];
                } else
                    i++;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Compilation message

exam.cpp: In function 'int main()':
exam.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
exam.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
exam.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 246 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 237 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 240 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 229 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 246 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 246 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -