Submission #411605

#TimeUsernameProblemLanguageResultExecution timeMemory
411605aris12345678Exam (eJOI20_exam)C++14
12 / 100
259 ms1048 KiB
#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);
    for(int i = 0; i < n; i++)
        scanf("%d", &a[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 ans = 0;
        for(int mask = 0; mask < 1 << n; mask++) {
            int res = 0, prev_i = 0;
            map<int, int> left, right;
            for(int i = 0; i < n; i++) {
                if(mask&(1 << i)) {
                    for(int j = prev_i+1; j < i; j++) {
                        if(a[j] < a[i])
                            left[b[j]]++;
                    }
                    for(int j = i+1; j < n; j++) {
                        if(mask&(1 << j)) break;
                        if(a[j] < a[i])
                            right[b[j]]++;
                    }
                    res += left[a[i]]+right[a[i]];
                    left.clear();
                    right.clear();
                    prev_i = i;
                }
            }
            left.clear();
            right.clear();
            ans = max(ans, res);
        }
        for(int i = 0; i < n; i++) {
            if(a[i] == b[i])
                ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Compilation message (stderr)

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:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
exam.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...