답안 #594438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
594438 2022-07-12T12:50:55 Z daisy2 Turnir (COCI17_turnir) C++14
100 / 100
486 ms 21580 KB
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
int n,r[1200000],p;
pair<int,int> a[1200000];
stack<int> st;
int main()
{
    cin>>n;

    int po=1;
    for(int i=1;i<=n;i++)
        po*=2;

    for(int i=0;i<po;i++)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a,a+po);

    for(int i=0;i<po;i++)
    {
        if(i!=po-1 && a[i].first==a[i+1].first)
        {st.push(a[i].second);continue;}

        r[a[i].second]=n;
        p=2;
        while(p-1<=i)
        {
            r[a[i].second]--;
            p*=2;
        }

        while(!st.empty())
        {
            r[st.top()]=r[a[i].second];
            st.pop();
        }
    }

  for(int i=0;i<po;i++)
    cout<<r[i]<<" ";
  cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 13 ms 820 KB Output is correct
6 Correct 27 ms 1516 KB Output is correct
7 Correct 57 ms 2844 KB Output is correct
8 Correct 105 ms 5092 KB Output is correct
9 Correct 229 ms 10876 KB Output is correct
10 Correct 486 ms 21580 KB Output is correct