답안 #818167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
818167 2023-08-10T03:04:33 Z andecaandeci 곤돌라 (IOI14_gondola) C++17
100 / 100
50 ms 5920 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
const int MAX=25e4;
int valid(int n, int a[]) {
  int next=-1, ret=0;
  map<int, bool> occ;
  for(int i=0; i<n; i++) {
    if(occ[a[i]]) return 0;
    occ[a[i]]=1;
    if(next!=-1) next=next%n+1;
    if(a[i]<=0) return 0;
    if(a[i]<=n) {
      if(next==-1) next=a[i];
      if(a[i]!=next) return 0;
    }
  }
  return 1;
}
int replacement(int n, int a[], int b[]) {
  int idx=0, next=-1;
  priority_queue<pair<int, int>> pq;
  int init[n];
  for(int i=0; i<n; i++) {
    if(next!=-1) init[i]=next=next%n+1;
    else if(a[i]<=n) init[i]=next=a[i];
  }
  if(next==-1) next=n;
  for(int i=0; i<n; i++) init[i]=next=next%n+1;
  for(int i=0; i<n; i++)
    if(a[i]>n) pq.push({-a[i], init[i]});
  next=n+1;
  while(!pq.empty()) {
    int u=pq.top().first, v=pq.top().second;
    u=-u; b[idx++]=v;
    while(next<u) b[idx++]=next++;
    next++;
    pq.pop();
  }
  return idx;
}
const int MOD=1e9+9;
int binpow(int b, int exp) {
  long long base=b, ret=1;
  while(exp) {
    if(exp&1) ret=ret*base%MOD;
    base=base*base%MOD;
    exp>>=1;
  }
  return ret;
}
int countReplacement(int n, int a[]) {
  if(!valid(n, a)) return 0;
  long long ans=1;
  int las=n+1, cnt=0;
  priority_queue<int> pq;
  for(int i=0; i<n; i++)
    if(a[i]>n) pq.push(-a[i]), cnt++;
  while(!pq.empty()) {
    int u=-pq.top(); pq.pop();
    ans=ans*binpow(cnt, u-las)%MOD;
    las=u+1;
    cnt--;
  }
  bool nperm=0;
  for(int i=0; i<n; i++) if(a[i]<=n) nperm=1;
  return (nperm ? 1 : n)*ans%MOD;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:6:16: warning: unused variable 'ret' [-Wunused-variable]
    6 |   int next=-1, ret=0;
      |                ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 2132 KB Output is correct
7 Correct 6 ms 596 KB Output is correct
8 Correct 23 ms 3904 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 23 ms 4540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 2132 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 19 ms 3816 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 27 ms 4408 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 6 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 6 ms 852 KB Output is correct
12 Correct 8 ms 980 KB Output is correct
13 Correct 12 ms 1380 KB Output is correct
14 Correct 10 ms 852 KB Output is correct
15 Correct 17 ms 2200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 42 ms 3916 KB Output is correct
10 Correct 39 ms 3388 KB Output is correct
11 Correct 11 ms 1492 KB Output is correct
12 Correct 13 ms 1596 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 43 ms 4104 KB Output is correct
10 Correct 28 ms 3284 KB Output is correct
11 Correct 10 ms 1544 KB Output is correct
12 Correct 13 ms 1616 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 44 ms 4428 KB Output is correct
15 Correct 50 ms 5920 KB Output is correct
16 Correct 9 ms 1320 KB Output is correct
17 Correct 33 ms 4144 KB Output is correct
18 Correct 19 ms 2472 KB Output is correct