제출 #1350824

#제출 시각아이디문제언어결과실행 시간메모리
1350824AzeTurk810Sequence (APIO23_sequence)C++17
컴파일 에러
0 ms0 KiB
/*
Telebe of Adicto && Mamedov yani AzeTurk810
I see humans but no humanity
*/
#include "sequence.h"
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using ll = long long;
using namespace std;

#define ln '\n'
#define INFi 1e9
#define INFll 1e18

#ifdef ONPC
#include <algo.hpp>
#else
#define dbg(...)
#define dbg_out(...)
##define assert(...)
#endif

int _n, ans;
vector<int> A;
map<int, vector<int>> ind;

inline void systemd() {
    ans = 1;
    for (size_t i = 0; i < _n; i++) {
        ind[A[i]].push_back(i);
    }
}

int W(int l, int r, int x) {
    auto itl = lower_bound(ind[x].begin(), ind[x].end(), l);
    auto itr = upper_bound(ind[x].begin(), ind[x].end(), r);
    itr--;
    return itr - itl + 1;
}

int W(int l, int r, set<int> st) {
    int res = 0;
    for (int x : st) {
        dbg(make_pair(l, r));
        dbg(x);
        res = max(res, W(l, r, x));
        dbg(res);
    }
    return res;
}

char solve() {
    systemd();
    for (size_t i = 0; i < _n; i++) {
        multiset<int> mst;
        mst.insert(A[i]);
        auto it1 = mst.begin(), it2 = mst.begin();
        for (size_t j = i + 1; j < _n; j++) {
            mst.insert(A[j]);
            set<int> st;
            dbg(mst);
            dbg(*it1);
            dbg(*it2);
            dbg(*(++it1));
            it1--;
            dbg(i);
            dbg(j);
            if (A[j] >= *it2) {
                if (it1 != it2)
                    it1++;
                else 
                    it2++;
                goto nxt;
            } 
            if (A[j] >= *it1) {
                if (it1 != it2) {
                    it1++;
                    it2--;
                    assert(it1 == it2);
                } else {
                    it1++;
                }
                goto nxt;
            }
            if (it1 != it2) {
                it2--;
            } else {
                it1--;
            }
nxt:
            dbg(*it1);
            dbg(*it2);
            assert(*it1 <= *it2);
            if (mst.size() & 1) {
                assert(it1 == it2);
            }
            st.insert(*it1);
            st.insert(*it2);
            ans = max(ans, W(i, j, st));
        }
    }
    return 0;
}

int sequence(int N, std::vector<int> _a) {
    _n = N;
    A = _a;
    assert(!solve());
    return ans;
}

// Attack on titan<3

// Just Imaginary
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠀⠀⠀⢀⣴⣾⠀⠀⠀⡀⢀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣦⣾⣿⣿⣿⣿⣿⡆⠁⠀⢀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⡠⠂⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠠⠔⠚⣿⣿⣿⣿⣿⣦⡄⠀⠁⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢀⠠⠐⢂⠉⡀⣀⣤⣄⢻⣿⣿⡟⢈⡹⣿⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⡀⠄⠂⠈⠀⣶⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠘⣷⡀⠀⡀⠐⠂⠐⢄
⠀⠀⠀⠀⠀⠀⠀⣿⣿⠟⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣀⣾⣷⠯⠀⠤⠤⠄⠈
⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⣹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣰⣿⠋⠀⠀⢠⣾⣿⣿⣿⣿⣿⣭⠟⢻⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀
⠀⠀⠀⣀⣶⡟⠁⠀⢾⣶⣿⠟⠉⠈⢻⣿⣿⣿⣦⣜⠀⠛⠛⠿⠁⠀⠀⠀⠀⠀
⠚⠻⠿⠿⡿⠁⠀⢠⣿⣿⠁⠀⣠⠖⠋⠉⠻⣿⣿⣿⣶⡀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣰⣿⡿⠃⠠⠊⠁⠀⠀⠀⠀⠈⢿⣿⣿⠟⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⣴⡿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⣠⣾⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢀⣴⠾⠟⠛⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
7
1 2 3 1 2 1 3

14
2 6 2 5 3 4 2 1 4 3 5 6 3 2

9
1 1 2 3 4 3 2 1 1
*/

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp:28:1: error: stray '##' in program
   28 | ##define assert(...)
      | ^~
In file included from /usr/include/c++/13/cassert:44,
                 from sequence.cpp:7:
sequence.cpp:28:10: error: expected constructor, destructor, or type conversion before '(' token
   28 | ##define assert(...)
      |          ^~~~~~
sequence.cpp: In function 'void systemd()':
sequence.cpp:36:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   36 |     ans = 1;
      |     ^~~
      |     abs
sequence.cpp:37:28: error: '_n' was not declared in this scope; did you mean 'ln'?
   37 |     for (size_t i = 0; i < _n; i++) {
      |                            ^~
      |                            ln
sequence.cpp: In function 'char solve()':
sequence.cpp:62:28: error: '_n' was not declared in this scope; did you mean 'ln'?
   62 |     for (size_t i = 0; i < _n; i++) {
      |                            ^~
      |                            ln
sequence.cpp:107:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
  107 |             ans = max(ans, W(i, j, st));
      |             ^~~
      |             abs
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:114:5: error: '_n' was not declared in this scope; did you mean '_a'?
  114 |     _n = N;
      |     ^~
      |     _a
sequence.cpp:117:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
  117 |     return ans;
      |            ^~~
      |            abs