답안 #978456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978456 2024-05-09T08:40:48 Z alexdd popa (BOI18_popa) C++17
61 / 100
115 ms 1932 KB
#include "popa.h"
#include<bits/stdc++.h>
using namespace std;
map<pair<pair<int,int>,pair<int,int>>,int> mp;
int myquery(int a, int b, int c, int d)
{
    if(a==c && b==d)
        return 1;
    int na=min(a,b),nb=max(a,b),nc=min(c,d),nd=max(c,d);
    if(make_pair(na,nb) < make_pair(nc,nd))
    {
        swap(na,nc);
        swap(nb,nd);
    }
    if(mp[{{na,nb},{nc,nd}}]==0) mp[{{na,nb},{nc,nd}}] = query(na,nb,nc,nd)+1;
    return mp[{{na,nb},{nc,nd}}]-1;
}
int limle[1005];
void precalc(int N)
{
    limle[0]=0;
    for(int i=1;i<N;i++)
    {
        if(myquery(i-1,i,i,i))
        {
            limle[i] = limle[i-1];
            while(limle[i]>0 && myquery(limle[i]-1,i,i,i))
                limle[i]--;
        }
        else
        {
            limle[i]=i;
        }
    }
}
int tole[1005],tori[1005];
int calc(int le, int ri)
{
    if(le>ri)
        return -1;
    if(le==ri)
    {
        tole[le]=tori[le]=-1;
        return le;
    }
    for(int root=ri;root>=le;root--)
    {
        if(limle[root]<=le)
        {
            tole[root] = calc(le,root-1);
            tori[root] = calc(root+1,ri);
            return root;
        }
    }
    return -5;
}
int solve(int N, int* Left, int* Right)
{
    mp.clear();
    precalc(N);
    for(int i=0;i<N;i++)
        tole[i]=tori[i]=-1;
    int root = calc(0,N-1);
    for(int i=0;i<N;i++)
    {
        Left[i]=tole[i];
        Right[i]=tori[i];
    }
    return root;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 696 KB Output is correct
2 Correct 5 ms 460 KB Output is correct
3 Correct 7 ms 704 KB Output is correct
4 Correct 5 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 1744 KB Output is correct
2 Correct 69 ms 1392 KB Output is correct
3 Correct 60 ms 1404 KB Output is correct
4 Correct 115 ms 1860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1932 KB too many queries
2 Halted 0 ms 0 KB -