Submission #1055810

# Submission time Handle Problem Language Result Execution time Memory
1055810 2024-08-13T05:44:02 Z 캐나다 선발고사 레전드(#11109) Pizza Party (CCO24_day1problem2) C++17
9 / 12
688 ms 92516 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 (ind==n||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;
    }
    set<P> s;
    int cnt=0;
    for(int i=n;i>0;i--) {
        int now;
        if (s.empty()) {
            cnt++;
            now=cnt;
        }
        else {
            auto it=s.lower_bound(P(ra[i],-1));
            if (it==s.begin()) {
                cnt++;
                now=cnt;
            }
            else {
                it--;
                now=(*it).second;
                s.erase(it);
            }
        }
        r0[i]=now;
        r1[ra[i]]=now;
        s.insert(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 88 ms 16048 KB jury uses fewer stacks: jans = 2, pans = 1061109567
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4440 KB good job!
2 Correct 2 ms 4444 KB good job!
3 Correct 4 ms 4576 KB good job!
4 Correct 2 ms 4444 KB good job!
5 Correct 4 ms 4444 KB good job!
6 Correct 2 ms 4444 KB good job!
7 Correct 2 ms 4444 KB good job!
8 Correct 3 ms 4444 KB good job!
9 Correct 3 ms 4444 KB good job!
10 Correct 4 ms 4440 KB good job!
11 Correct 3 ms 4700 KB good job!
12 Correct 3 ms 4444 KB good job!
13 Correct 4 ms 4700 KB good job!
14 Correct 3 ms 4444 KB good job!
15 Correct 2 ms 4444 KB good job!
# Verdict Execution time Memory Grader output
1 Correct 607 ms 40584 KB good job!
2 Correct 151 ms 17064 KB good job!
3 Correct 592 ms 40616 KB good job!
4 Correct 255 ms 19880 KB good job!
5 Correct 599 ms 40620 KB good job!
6 Correct 213 ms 18856 KB good job!
7 Correct 238 ms 19884 KB good job!
8 Correct 604 ms 40616 KB good job!
9 Correct 605 ms 40620 KB good job!
10 Correct 614 ms 40596 KB good job!
11 Correct 688 ms 92328 KB good job!
12 Correct 470 ms 35752 KB good job!
13 Correct 665 ms 92516 KB good job!
14 Correct 461 ms 35856 KB good job!
15 Correct 271 ms 21420 KB good job!
16 Correct 267 ms 21416 KB good job!