Submission #530272

# Submission time Handle Problem Language Result Execution time Memory
530272 2022-02-25T00:41:17 Z gg123_pe Gondola (IOI14_gondola) C++14
100 / 100
44 ms 5724 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std; 

typedef long long ll; 
#define f(i,a,b) for(int i = a; i < b; i++)
const int N = 250005; 
const ll mod = 1e9 + 9; 

int cant[N], m[N]; 
bool on[N];

int valid(int n, int X[]){
    int mini = X[0]; 
    f(i,0,n) mini = min(mini, X[i]);

    set <int> s; 
    f(i,0,n) s.insert(X[i]); 
    if(s.size() != n) return 0; 
    if(mini > n) return 1; 
    
    int id; 
    f(i,0,n) if(X[i] <= n) id = i; 
    vector <int> a, v1, v2;

    int pr = X[id]-1;
    f(i,0,n-id){
        pr++; 
        if(pr == n+1) pr = 1;
        v2.push_back(pr);
    }
    f(i,0,id){
        pr++; 
        if(pr == n+1) pr = 1;
        v1.push_back(pr); 
    }
    for(int x: v1) a.push_back(x);
    for(int x: v2) a.push_back(x);
    int ans = 1; 
    f(i,0,n) if(X[i] <= n and a[i] != X[i]) ans = 0;
    return ans; 
}

int replacement(int n, int X[], int res[]){
    int id = -1; 
    f(i,0,n) if(X[i] <= n) id = i;
    vector <int> a, v1, v2;

    if(id != -1){ 
        int pr = X[id]-1;
        f(i,0,n-id){
            pr++; 
            if(pr == n+1) pr = 1;
            v2.push_back(pr);
        }
        f(i,0,id){
            pr++; 
            if(pr == n+1) pr = 1;
            v1.push_back(pr); 
        }
        for(int x: v1) a.push_back(x);
        for(int x: v2) a.push_back(x);
    }
    else f(i,0,n) a.push_back(i+1);

    int maxi = 0; 
    f(i,0,n) {
        if(X[i] > n) m[X[i]] = a[i], on[X[i]] = 1;
        maxi = max(maxi, X[i]);
    }
    vector <int> ans; 
    id = n+1;
    while(id <= maxi){
        int l = id;
        while(!on[id]) id++;
        ans.push_back(m[id]);
        f(i,l,id) ans.push_back(i);
        id++;  
    }
    int l = ans.size();
    f(i,0,l) res[i] = ans[i]; 
    return l;
}
ll bp(ll x, ll y){
    if(y == 0) return 1; 
    ll ans = bp(x, y/2); ans = (ans*ans)%mod; 
    if(y%2 == 0) return ans; 
    return (ans*x)%mod; 
}
int countReplacement(int n, int X[]){
    if(!valid(n, X)) return 0;
    ll ans = 1;
    vector <ll> v = {n};  
    f(i,0,n) if(X[i] > n) v.push_back(X[i]); 

    sort(v.begin(), v.end()); 

    ll l = v.size(); 
    for(ll i = 1; i < l; i++) ans = (ans*bp(l-i, v[i]-v[i-1]-1LL))%mod;
    if(v.size() > n) {
        ll wi = n; 
        ans = (ans*wi)%mod; 
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:19:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |     if(s.size() != n) return 0;
      |        ~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:100:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |     if(v.size() > n) {
      |        ~~~~~~~~~^~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:26:16: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |     int pr = X[id]-1;
      |                ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 2760 KB Output is correct
7 Correct 24 ms 3648 KB Output is correct
8 Correct 19 ms 4980 KB Output is correct
9 Correct 6 ms 1740 KB Output is correct
10 Correct 24 ms 5576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 14 ms 2676 KB Output is correct
7 Correct 28 ms 3556 KB Output is correct
8 Correct 20 ms 4908 KB Output is correct
9 Correct 6 ms 1740 KB Output is correct
10 Correct 27 ms 5516 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 11 ms 2636 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 38 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 216 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 416 KB Output is correct
11 Correct 7 ms 1700 KB Output is correct
12 Correct 9 ms 1752 KB Output is correct
13 Correct 13 ms 1740 KB Output is correct
14 Correct 11 ms 1604 KB Output is correct
15 Correct 19 ms 3040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 35 ms 5084 KB Output is correct
10 Correct 25 ms 4016 KB Output is correct
11 Correct 9 ms 1740 KB Output is correct
12 Correct 12 ms 1944 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 33 ms 4988 KB Output is correct
10 Correct 33 ms 3976 KB Output is correct
11 Correct 9 ms 1740 KB Output is correct
12 Correct 15 ms 2040 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 37 ms 4492 KB Output is correct
15 Correct 44 ms 5060 KB Output is correct
16 Correct 7 ms 1212 KB Output is correct
17 Correct 27 ms 3512 KB Output is correct
18 Correct 15 ms 2432 KB Output is correct