Submission #902852

# Submission time Handle Problem Language Result Execution time Memory
902852 2024-01-11T03:37:11 Z Sir_Ahmed_Imran Gondola (IOI14_gondola) C++17
100 / 100
45 ms 7204 KB
                              ///~~~LOTA~~~///
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long 
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define MAXN 100001
ll mod=1e9+9;
map<int,int> vis;
ll pwr(ll n,ll m){
    if(!m) return 1;
    ll o=pwr(n,m/2);
    o=(o*o)%mod;
    if(m%2) o=(o*n)%mod;
    return o;
}
int valid(int n, int a[]){
    for(int i=0;i<n;i++){
        if(vis[a[i]]) return 0;
        vis[a[i]]=1;
    }
    for(int i=0;i<n;i++){
        if(a[i]>n) continue;
        for(int j=i+1;j<i+n;j++){
            if(a[j%n]>n) continue;
            if(a[j%n]!=1+((a[i]+j-i-1)%n)) return 0;
        }
        return 1;
    }
    return 1;
}
int replacement(int n,int a[],int v[]){
    int m,o;
    set<pii> s;
    for(int i=m=o=0;i<n;i++){
        m=max(m,a[i]);
        if(a[i]>n) continue;
        for(int j=i+1;j<i+n;j++){
            m=max(m,a[j%n]);
            if(a[j%n]>n)
                s.insert({a[j%n],1+((a[i]+j-i-1)%n)});
        }
        o=1;
        break; 
    }
    pii pi;
    if(!o)
        for(int i=0;i<n;i++)
            s.insert({a[i],i+1});
    o=0;
    for(int i=n+1;i<=m;i++){
        pi=*s.begin();
        s.erase(s.begin());
        v[o]=pi.ss;
        pi.ss=i;
        o++;
        if(pi.ss!=pi.ff) 
            s.insert(pi);
    }
    return o;
}
int countReplacement(int n,int a[]){
    if(!valid(n,a)) return 0;
    vector<ll> v;
    for(int i=0;i<n;i++)
        if(a[i]>n) 
            v.append(a[i]); 
    ll o,m;
    m=v.size();
    o=1,
    v.append(n);
    sort(all(v));
    if(v.size()==n+1) o=n;
    for(int i=1;i<v.size();i++){
        o=(o*pwr(m,v[i]-v[i-1]-1))%mod;
        m--;
    }
    return o;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:78:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |     if(v.size()==n+1) o=n;
      |        ~~~~~~~~^~~~~
gondola.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i=1;i<v.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 372 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
6 Correct 12 ms 2140 KB Output is correct
7 Correct 9 ms 604 KB Output is correct
8 Correct 22 ms 3944 KB Output is correct
9 Correct 6 ms 1384 KB Output is correct
10 Correct 23 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 504 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
6 Correct 10 ms 2152 KB Output is correct
7 Correct 11 ms 616 KB Output is correct
8 Correct 24 ms 4076 KB Output is correct
9 Correct 8 ms 1380 KB Output is correct
10 Correct 24 ms 4444 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 19 ms 2184 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 35 ms 4800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 356 KB Output is correct
11 Correct 6 ms 604 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 17 ms 2544 KB Output is correct
14 Correct 10 ms 604 KB Output is correct
15 Correct 24 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 38 ms 4824 KB Output is correct
10 Correct 26 ms 4052 KB Output is correct
11 Correct 10 ms 1824 KB Output is correct
12 Correct 13 ms 2140 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 33 ms 4580 KB Output is correct
10 Correct 25 ms 4060 KB Output is correct
11 Correct 9 ms 1884 KB Output is correct
12 Correct 17 ms 2056 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 40 ms 6456 KB Output is correct
15 Correct 45 ms 7204 KB Output is correct
16 Correct 8 ms 1880 KB Output is correct
17 Correct 34 ms 4944 KB Output is correct
18 Correct 17 ms 3148 KB Output is correct