Submission #760259

# Submission time Handle Problem Language Result Execution time Memory
760259 2023-06-17T11:02:12 Z danikoynov Sequence (APIO23_sequence) C++17
0 / 100
2000 ms 35484 KB
#include "sequence.h"

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 10;
vector < int > occ[maxn];
int val[maxn], pref[maxn];
int sequence(int N, vector<int> A)
{
    A.insert(A.begin(), 0);
    for (int i = 1; i <= N; i ++)
        occ[A[i]].push_back(i);

    int ans = 0;
    for (int x = 1; x <= N; x ++)
    {
        for (int i = 1; i <= N; i ++)
        {
            if (A[i] < x)
                val[i] = -1;
            else
            if (A[i] == x)
            val[i] = 0;
            else
                val[i] = 1;
            pref[i] = pref[i - 1] + val[i];
        }


        for (int i = 0; i < occ[x].size(); i ++)
        {
            for (int j = i; j < occ[x].size(); j ++)
            {
            //cout << "-----------" << endl;
            //cout << x << " " << i << " " << j << " " << ans << endl;
            ///cout << pref[r] << endl;
            int l = occ[x][i], r = occ[x][j];
            int min_lf = 1e9, max_lf = -1e9;
            int min_rf = 1e9, max_rf = -1e9;
            int d = 0;
            for (int p = l - 1; p >= 0; p --)
            {
                if (A[p] == i)
                    d ++;
                min_lf = min(min_lf, pref[p] - d);
                max_lf = max(max_lf, pref[p] + d);
            }
            d = 0;
            for (int p = r; p <= N; p ++)
            {
                if (A[p] == i && p != r)
                    d ++;
                min_rf = min(min_rf, pref[p] - d);
                max_rf = max(max_rf, pref[p] + d);
            }

            max_rf += (j - i + 1);
            min_rf -= (j - i + 1);
            //cout << min_lf << " " << max_lf << " " << min_rf << " " << max_rf << endl;
            if (max(min_rf, min_lf) <= min(max_rf, max_lf))
            {
                ///cout << x << " " << i << " " << j << endl;
                ans = max(ans, j - i + 1);
            }

            }
        }
    }
    return ans;
}

Compilation message

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for (int i = 0; i < occ[x].size(); i ++)
      |                         ~~^~~~~~~~~~~~~~~
sequence.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int j = i; j < occ[x].size(); j ++)
      |                             ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11956 KB Output is correct
2 Execution timed out 2064 ms 24652 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 35484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -