답안 #978434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978434 2024-05-09T08:21:23 Z alexdd popa (BOI18_popa) C++17
61 / 100
211 ms 500 KB
#include "popa.h"
#include<bits/stdc++.h>
using namespace std;
int myquery(int a, int b, int c, int d)
{
    return query(min(a,b),max(a,b),min(c,d),max(c,d));
}
vector<int> ord;
void precalc(int limle[1005])
{
    limle[ord[0]]=0;
    for(int i=1;i<ord.size();i++)
    {
        if(myquery(ord[i-1],ord[i],ord[i],ord[i]))
        {
            limle[ord[i]] = limle[ord[i-1]];
            while(limle[ord[i]]>0 && myquery(ord[limle[ord[i]]-1],ord[i],ord[i],ord[i]))
                limle[ord[i]]--;
        }
        else
        {
            limle[ord[i]] = i;
        }
    }
    for(int i=0;i<ord.size();i++)
        limle[i] = ord[limle[i]];
}
int tole[1005],tori[1005];
int limle[1005],limri[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=le;root<=ri;root++)
    {
        if(limle[root]<=le && limri[root]>=ri)
        {
            tole[root] = calc(le,root-1);
            tori[root] = calc(root+1,ri);
            return root;
        }
    }
    return -5;
}
int solve(int N, int* Left, int* Right)
{
    ord.clear();
    for(int i=0;i<N;i++)
        ord.push_back(i);
    precalc(limle);
    reverse(ord.begin(),ord.end());
    precalc(limri);
    //for(int i=0;i<N;i++) cout<<i<<"  "<<limle[i]<<" "<<limri[i]<<" lim\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;
}

Compilation message

popa.cpp: In function 'void precalc(int*)':
popa.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=1;i<ord.size();i++)
      |                 ~^~~~~~~~~~~
popa.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=0;i<ord.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 444 KB Output is correct
2 Correct 10 ms 444 KB Output is correct
3 Correct 16 ms 440 KB Output is correct
4 Correct 10 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 468 KB Output is correct
2 Correct 120 ms 472 KB Output is correct
3 Correct 128 ms 468 KB Output is correct
4 Correct 211 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 344 KB too many queries
2 Halted 0 ms 0 KB -