Submission #1055806

# Submission time Handle Problem Language Result Execution time Memory
1055806 2024-08-13T05:41:08 Z 캐나다 선발고사 레전드(#11109) Pizza Party (CCO24_day1problem2) C++17
0 / 12
548 ms 52024 KB
#include <bits/stdc++.h>
using namespace std;

int n;
int a[1000001];
int b[1000001];
int ra[1000001];
int rb[1000001];
int r0[1000001];
int r1[1000001];
typedef pair<int,int> P;
vector<P> v;

int main(void) {
    scanf("%d",&n);
    memset(ra,-1,sizeof(ra));
    for(int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        v.push_back(P(a[i],i));
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++) {
        scanf("%d",&b[i]);
        int ind=lower_bound(v.begin(),v.end(),P(b[i],-1))-v.begin();
        if (v[ind].first!=b[i]) {
            printf("-1");
            return 0;
        }
        if (ra[v[ind].second]!=-1) {
            printf("-1");
            return 0;
        }
        ra[v[ind].second]=i;
        rb[i]=v[ind].second;
    }
    stack<int> si;
    priority_queue<P,vector<P>,greater<P>> pq;
    int cnt=0;
    for(int i=n;i>0;i--) {
        int now;
        if (pq.empty()) {
            cnt++;
            now=cnt;
        }
        else {
            if (pq.top().first>ra[i]) {
                cnt++;
                now=cnt;
            }
            else {
                now=pq.top().second;
                pq.pop();
            }
        }
        r0[i]=now;
        r1[ra[i]]=now;
        pq.push(P(ra[i],now));
    }
    printf("%d\n",cnt);
    for(int i=1;i<=n;i++) {
        printf("%d",r0[i]);
        if (i!=n) {
            printf(" ");
        }
    }
    printf("\n");
    for(int i=1;i<=n;i++) {
        printf("%d",r1[i]);
        if (i!=n) {
            printf(" ");
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d",&b[i]);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 16224 KB jury uses fewer stacks: jans = 2, pans = 1061109567
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4440 KB jury uses fewer stacks: jans = 134, pans = 1859
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 548 ms 52024 KB jury uses fewer stacks: jans = 1996, pans = 367925
2 Halted 0 ms 0 KB -