답안 #562595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
562595 2022-05-14T17:54:40 Z illyakr Exam (eJOI20_exam) C++14
0 / 100
12 ms 468 KB
//#pragma GCC optimize("inline,Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,avx,abm")
#include <bits/stdc++.h>
#define ll long long
#define int ll
typedef long double ld;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define y0 dfgoert
#define y1 kjsjofd
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1000000007;
const int INF1e9 = 1010101010;
const int INF1e18 = 1010101010101010101;
const ld PI =  3.14159265358979323846264338327950288419716939937510;

int n;
int a[101010];
int b[101010];
int ans = 0;
void solve() {
    cin >> n;
    for (int i = 0; i < n; i++)cin >> a[i];
    for (int i = 0; i < n; i++)cin >> b[i];
    for (int mask = 1; mask < (1 << n); mask++) {
        bool ok = true;
        vector<pair<int, int> > hv;
        for (int i = 0; i < n; i++) {
            if (1 & (mask >> i)) {
//                cout << 1;
                hv.push_back({b[i], i});
            } else {
//                cout << 0;
            }
        }
//        cout << endl;

        sort(hv.begin(), hv.end(), [](pair<int, int> q, pair<int, int> w) {
             return q.first < w.first;
        });
        for (int id = 0; id < hv.size(); id++) {
            bool frst = false;
            int rgh = -1;
            for (int j = hv[id].second; j < n; j++) {
                if (a[j] > hv[id].first)break;
                if (b[j] < hv[id].first)break;
                if (a[j] == hv[id].first){rgh = j;frst = true;break;}
            }
            bool scnd = false;
            int lft = -1;
            for (int j = hv[id].second; j >= 0; j--) {
                if (a[j] > hv[id].first)break;
                if (b[j] < hv[id].first)break;
                if (a[j] == hv[id].first){lft = j;scnd = true;break;}
            }

            if (frst || scnd)continue;
            ok = false;break;
        }

        if (ok) {
//            cout << "OK ^" << endl;
            ans = max(ans, (ll)__builtin_popcount(mask));
        }
    }
    cout << ans;
}

int32_t main() {
    fast
    int t = 1;
//    cin >> t;
    for (int id = 1; id <= t; id++) {
//        cout << "Case " << id << ": ";
        solve();
    }
}
/**
10 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10


6 5
4 10
6 8
3 5
4 14
10 9
4 20
*/

Compilation message

exam.cpp: In function 'void solve()':
exam.cpp:41:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int id = 0; id < hv.size(); id++) {
      |                          ~~~^~~~~~~~~~~
exam.cpp:43:17: warning: variable 'rgh' set but not used [-Wunused-but-set-variable]
   43 |             int rgh = -1;
      |                 ^~~
exam.cpp:50:17: warning: variable 'lft' set but not used [-Wunused-but-set-variable]
   50 |             int lft = -1;
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -