Submission #954435

#TimeUsernameProblemLanguageResultExecution timeMemory
954435Mher777Sequence (APIO23_sequence)C++17
0 / 100
54 ms20048 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <cassert> #include <fstream> #include "sequence.h" using namespace std; mt19937 rnd(7069); typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef float fl; typedef long double ld; using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"Yes\n" #define no cout<<"No\n" #define all(x) (x).begin(), (x).end() const int MAX = int(2e9 + 5); const ll MAXL = ll(1e18) + 5ll; const int N = 500005; int a[N]; int n; int sol() { vi cnt1(n + 1), cnt2(n + 1), pref1(n + 1), pref2(n + 1), v1, v2; int ret = 0; bool f = true; for (int i = 1; i < n; ++i) { if (a[i] <= a[i + 1] && f) { v1.pub(a[i]); } else { f = false; v2.pub(a[i]); } } if (a[n] >= a[n - 1] && f) { v1.pub(a[n]); } else { v2.pub(a[n]); } for (int i = v1.size() - 1; i >= 0; --i) { ++cnt1[v1[i]]; if (i == v1.size() - 1) pref1[v1[i]] = 1; else pref1[v1[i]] = pref1[v1[i + 1]] + 1; } for (int i = 0; i < v2.size(); ++i) { ++cnt2[v2[i]]; if (i == 0) pref2[v2[i]] = 1; else pref2[v2[i]] = pref2[v2[i - 1]] + 1; } for (int i = 1; i <= n; ++i) { ret = max({ ret,cnt1[i],cnt2[i] }); int len = pref1[i] + pref2[i], pref = cnt1[i] + cnt2[i]; if (pref >= len / 2 + len % 2) ret = max(ret, cnt1[i] + cnt2[i]); } return ret; } int sequence(int N, std::vector<int> A) { n = N; for (int i = 1; i <= n; ++i) { a[i] = A[i - 1]; } return sol(); } /* 7 1 2 3 1 2 1 3 3 9 1 1 2 3 4 3 2 1 1 2 14 2 6 2 5 3 4 2 1 4 3 5 6 3 2 3 */

Compilation message (stderr)

sequence.cpp: In function 'int sol()':
sequence.cpp:78:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         if (i == v1.size() - 1) pref1[v1[i]] = 1;
      |             ~~^~~~~~~~~~~~~~~~
sequence.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int i = 0; i < v2.size(); ++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...
#Verdict Execution timeMemoryGrader output
Fetching results...