답안 #152829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152829 2019-09-09T17:42:12 Z phillip Doktor (COCI17_doktor) C++14
60 / 100
147 ms 65576 KB
#include <bits/stdc++.h>

using namespace std;
int n,a[5009],c[5009][5009];
void o(int x)
{
    int l=x-1,r=x+1;
    while(l>0&&r<n+1)
    {
        c[l][r]=c[l+1][r-1];
        if(a[l]==r)c[l][r]++;
        if(a[r]==l)c[l][r]++;
        l--;
        r++;
    }
    l=x;r=x+1;
    //cout<<'.';
    while(l>0&&r<n+1)
    {
        c[l][r]=c[l+1][r-1];
        if(a[l]==r)c[l][r]++;
        if(a[r]==l)c[l][r]++;
        l--;
        r++;
    }
}
int l[5009],r[5009];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        l[i]=l[i-1];
        if(a[i]==i)l[i]++;
    }
    for(int i=n;i>=1;i--)
    {
        r[i]=r[i+1];
        if(a[i]==i)r[i]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(i==a[i])c[i][i]=1;
        o(i);
    }
    int sum,mx=0,x,y;
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            sum=c[i][j]+l[i-1]+r[j+1];
            mx=max(sum,mx);
            if(mx==sum)
            {
                x=i;
                y=j;
            }
        }
    }
    //cout<<c[1][3]<<"\n";
    cout<<a[x]<<" "<<a[y];//<<" "<<mx;
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:65:25: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout<<a[x]<<" "<<a[y];//<<" "<<mx;
                         ^
doktor.cpp:65:17: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout<<a[x]<<" "<<a[y];//<<" "<<mx;
                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1812 KB Output is correct
2 Correct 5 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16220 KB Output is correct
2 Correct 22 ms 12816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 57512 KB Output is correct
2 Correct 43 ms 22652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 64448 KB Output is correct
2 Correct 6 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 147 ms 65576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 604 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -