Submission #447499

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

const int mxN = 1e5+5;
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(n+1);
    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:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
exam.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
exam.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 6 ms 1016 KB Output is correct
3 Correct 28 ms 5572 KB Output is correct
4 Correct 20 ms 2240 KB Output is correct
5 Correct 43 ms 7008 KB Output is correct
6 Correct 20 ms 2252 KB Output is correct
7 Correct 21 ms 2452 KB Output is correct
8 Correct 43 ms 5780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 5 ms 316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 1284 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -