답안 #154371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154371 2019-09-21T10:07:50 Z PedroBigMan Doktor (COCI17_doktor) C++14
100 / 100
326 ms 48992 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF ((ll) pow(2,63) -1)
#define si signed
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll N; cin>>N; vector<ll> a; In(a,N);
    vector<ll> p; ll cur=0;
    REP(i,0,N)
    {
        if(a[i]==i+1) {cur++;}
        p.pb(cur);
    }
    ll ideal;
    vector<vector<ll> > cen; vector<ll> xx; REP(i,0,2*N-1) {cen.pb(xx);}
    REP(i,0,N)
    {
        ideal = i+a[i]-1;
        cen[ideal].pb(abs(i+1-a[i]));
    }
    REP(i,0,2*N-1) {sort(cen[i].begin(),cen[i].end());}
    ll A=1; ll B=1; ll best=0;
    REP(c,1,2*N-1)
    {
        REP(i,0,cen[c].size())
        {
            if(c-cen[c][i]==0)
            {
                if(i+1-p[c]>best)
                {
                    best=i+1-p[c]; A=a[0]; B=a[c];
                }
            }
            else
            {
                if(i+1-(p[(c+cen[c][i])/2]-p[(c-cen[c][i])/2 -1]) >best) 
                {
                    best=i+1-(p[(c+cen[c][i])/2]-p[(c-cen[c][i])/2 -1]); 
                    A=a[(c-cen[c][i])/2]; B=a[(c+cen[c][i])/2];
                }
            }
        }
    }
    cout<<A<<" "<<B<<endl;
    return 0;
}

Compilation message

doktor.cpp: In function 'void Out(std::vector<long long int>)':
doktor.cpp:10:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
doktor.cpp:20:29:
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                             ~~~~~~~~~~~~
doktor.cpp:20:25: note: in expansion of macro 'REP'
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                         ^~~
doktor.cpp: In function 'int main()':
doktor.cpp:10:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
doktor.cpp:44:13:
         REP(i,0,cen[c].size())
             ~~~~~~~~~~~~~~~~~    
doktor.cpp:44:9: note: in expansion of macro 'REP'
         REP(i,0,cen[c].size())
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1000 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1000 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1588 KB Output is correct
2 Correct 131 ms 34732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 9192 KB Output is correct
2 Correct 41 ms 9428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 46020 KB Output is correct
2 Correct 195 ms 43020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 192 ms 34456 KB Output is correct
2 Correct 163 ms 48992 KB Output is correct