1 solutions

  • 0
    @ 2025-11-5 15:53:29

    C :

    #include<stdio.h>
    long long a[100010],ans[1000];
    int main()
    {
        long long b,x,y,m,l,c,rec;
        int i;
        while(scanf("%lld",&b)!=EOF)
        {
            for(i=0;i<b;i++)
                scanf("%d",&a[i]);
            if(b==1||b==2)
                printf("%lld\n",b);
            else
            {
                m=2;l=0;c=0;
                for(i=0;i<b-2;i++)
                {
                    x=a[i+1]-a[i];
                    y=a[i+2]-a[i+1];
                    if(x==y)
                    {
                        m++;
                        l=x;
                    }
                    else
                    {
                        ans[c]=m;
                        m=2;
                        c++;
                    }
                    ans[c]=m;
                }
                rec=ans[0];
                for(i=1;i<c;i++)
                {
                    if(ans[i]>rec)
                        rec=ans[i];
                }
                printf("%lld\n",rec);
            }
        }
        return 0;
    }
    
    
    

    C++ :

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstdlib>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <queue>
    using namespace std;
    #define out(v) cerr << #v << ": " << (v) << endl
    #define SZ(v) ((int)(v).size())
    const int maxint = -1u>>1;
    template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
    template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}
    
    const int maxn = 100000 + 5;
    int seq[maxn], n;
    
    int main() {
        //freopen("ap.out", "w", stdout);
        while(scanf("%d", &n) == 1) {
            for(int i = 0; i < n; i++) {
                scanf("%d", seq + i);
            }
            int ans = 1, s = 0, t, d;
            while(s < n - 1) {
                t = s + 1, d = seq[t] - seq[s];
                while(t < n && seq[t] - seq[t - 1] == d) t++;
                t--;
                get_max(ans, t - s + 1);
                s = t;
            }
            printf("%d\n", ans);
        }
        return 0;
    }
    
    
    • 1

    Information

    ID
    17297
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By