Submission #855427

# Submission time Handle Problem Language Result Execution time Memory
855427 2023-10-01T08:39:11 Z MilosMilutinovic Sequence (APIO23_sequence) C++17
11 / 100
2000 ms 152668 KB
#include "sequence.h"
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int readint(){
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

const int N=5000500;

int n,a[N],val[N],pref[N];
vector<int> pos[N];

int sequence(int N,vector<int> A) {
    n=N; for(int i=1;i<=n;i++) a[i]=A[i-1];
    for(int i=1;i<=n;i++) pos[a[i]].pb(i);
    //build(1,1,n);
    for(int i=1;i<=n;i++) val[i]=1;
    int ans=0;
    for(int v=1;v<=n;v++){
        if(pos[v].empty()) continue;
        for(int j:pos[v]) val[j]=0;
//      for(int j:pos[v]) modify(1,1,n,j,n,-1);
        for(int i=1;i<=n;i++) pref[i]=pref[i-1]+val[i];
        for(int l=1;l<=n;l++){
            int cnt=0;
            for(int r=l;r<=n;r++){
                cnt+=(a[r]==v?1:0);
                if(abs(pref[r]-pref[l-1])<=cnt) ans=max(ans,cnt);
            }
        }
//      for(int j:pos[v]) modify(1,1,n,j,n,-1);
        for(int j:pos[v]) val[j]=-1;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123740 KB Output is correct
2 Correct 27 ms 123484 KB Output is correct
3 Correct 25 ms 123480 KB Output is correct
4 Correct 26 ms 123736 KB Output is correct
5 Correct 26 ms 123740 KB Output is correct
6 Correct 26 ms 123740 KB Output is correct
7 Correct 26 ms 123736 KB Output is correct
8 Correct 26 ms 123676 KB Output is correct
9 Correct 26 ms 123740 KB Output is correct
10 Correct 25 ms 123740 KB Output is correct
11 Correct 25 ms 123740 KB Output is correct
12 Correct 25 ms 123736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123740 KB Output is correct
2 Correct 27 ms 123484 KB Output is correct
3 Correct 25 ms 123480 KB Output is correct
4 Correct 26 ms 123736 KB Output is correct
5 Correct 26 ms 123740 KB Output is correct
6 Correct 26 ms 123740 KB Output is correct
7 Correct 26 ms 123736 KB Output is correct
8 Correct 26 ms 123676 KB Output is correct
9 Correct 26 ms 123740 KB Output is correct
10 Correct 25 ms 123740 KB Output is correct
11 Correct 25 ms 123740 KB Output is correct
12 Correct 25 ms 123736 KB Output is correct
13 Execution timed out 2021 ms 123740 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123740 KB Output is correct
2 Execution timed out 2047 ms 147032 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 123484 KB Output is correct
2 Execution timed out 2037 ms 136956 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2061 ms 152668 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123740 KB Output is correct
2 Correct 27 ms 123484 KB Output is correct
3 Correct 25 ms 123480 KB Output is correct
4 Correct 26 ms 123736 KB Output is correct
5 Correct 26 ms 123740 KB Output is correct
6 Correct 26 ms 123740 KB Output is correct
7 Correct 26 ms 123736 KB Output is correct
8 Correct 26 ms 123676 KB Output is correct
9 Correct 26 ms 123740 KB Output is correct
10 Correct 25 ms 123740 KB Output is correct
11 Correct 25 ms 123740 KB Output is correct
12 Correct 25 ms 123736 KB Output is correct
13 Execution timed out 2021 ms 123740 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 123740 KB Output is correct
2 Correct 27 ms 123484 KB Output is correct
3 Correct 25 ms 123480 KB Output is correct
4 Correct 26 ms 123736 KB Output is correct
5 Correct 26 ms 123740 KB Output is correct
6 Correct 26 ms 123740 KB Output is correct
7 Correct 26 ms 123736 KB Output is correct
8 Correct 26 ms 123676 KB Output is correct
9 Correct 26 ms 123740 KB Output is correct
10 Correct 25 ms 123740 KB Output is correct
11 Correct 25 ms 123740 KB Output is correct
12 Correct 25 ms 123736 KB Output is correct
13 Execution timed out 2021 ms 123740 KB Time limit exceeded
14 Halted 0 ms 0 KB -