답안 #562596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
562596 2022-05-14T17:56:45 Z illyakr Exam (eJOI20_exam) C++14
14 / 100
1000 ms 352 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 fnd = false;
            for (int j = hv[id].second; j < n; j++) {
                if (a[j] > hv[id].first)break;
                if ((1 & (mask >> j)) &&  b[j] < hv[id].first)break;
                if (a[j] == hv[id].first){fnd = true;break;}
            }
            bool scnd = false;
            for (int j = hv[id].second; j >= 0; j--) {
                if (a[j] > hv[id].first)break;
                if ((1 & (mask >> j)) && b[j] < hv[id].first)break;
                if (a[j] == hv[id].first){fnd = true;break;}
            }

            if (fnd)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:48:18: warning: unused variable 'scnd' [-Wunused-variable]
   48 |             bool scnd = false;
      |                  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1091 ms 352 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Execution timed out 1091 ms 352 KB Time limit exceeded
9 Halted 0 ms 0 KB -