Submission #562596

#TimeUsernameProblemLanguageResultExecution timeMemory
562596illyakrExam (eJOI20_exam)C++14
14 / 100
1091 ms352 KiB
//#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 (stderr)

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;
      |                  ^~~~
#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...