Submission #320360

# Submission time Handle Problem Language Result Execution time Memory
320360 2020-11-08T11:01:08 Z tigicha Gondola (IOI14_gondola) C++17
100 / 100
75 ms 8168 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+9;
long long k, l, b[100005], sum=1;
map <long long,long long> mp;
vector<pair<int, int> >v;
vector<int>vec;
long long power(long long x, long long y){
    long long s=1;
    while(y>0){
        if(y%2==1){
            s*=x;
            s%=mod;
        }
        x*=x;
        x%=mod;
        y/=2;
    }
    return s;
}
int valid(int n, int a[]){
    l=-1;
    for(int i=0; i<n; i++)
    if(mp[a[i]]==1) return 0;
    else mp[a[i]]=1;
    for(int i=0; i<n; i++) 
    if(a[i]<=n){
    	l=i;
    	break;
	}
    if(l==-1) return 1;
    k=a[l];
    for(int i=l; i<n; i++)
    if(a[i]!=k && a[i]<=n) return 0;
	else{
		k++;
		if(k==n+1) k=1;
	}
    for(int i=0; i<l; i++)
    if(a[i]!=k && a[i]<=n) return 0;
	else{
		k++;
		if(k==n+1) k-=n;
	}
    return 1;
}
int replacement(int n, int a[], int ans[]){
    l=-1;
    for(int i=0; i<n; i++)
    if(a[i]<=n){
    	l=i;
    	break;
	}
    k=a[l];
    for(int i=l; i<n; i++){
        b[i]=k;
        k++;
        if(k==n+1) k-=n;
    }
    for(int i=0; i<l; i++){
        b[i]=k;
        k++;
        if(k==n+1) k=1;
    }
    for(int i=0; i<n; i++)
    if(a[i]>n) v.push_back({a[i], i});
    sort(v.begin(), v.end());
    l=n;
    k=0;
    for(int i=0; i<v.size(); i++)
    while(b[v[i].second]<a[v[i].second]){
        ans[k]=b[v[i].second];
        k++;
        l++;
        b[v[i].second]=l;
    }
    return k;
}
int countReplacement(int n, int a[]){
    if(valid(n, a)==0) return 0;
    vec.push_back(n);
    for(int i=0; i<n; i++)
    if(a[i]>n) vec.push_back(a[i]);
    sort(vec.begin(), vec.end());
    for(int i=0; i<vec.size()-1; i++){
        sum*=power(vec.size()-i-1, vec[i+1]-vec[i]-1);
        sum%=mod;
    }
    if(vec.size()==n+1) sum=(sum*n)%mod;
    return sum;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i=0; i<v.size(); i++)
      |                  ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for(int i=0; i<vec.size()-1; i++){
      |                  ~^~~~~~~~~~~~~
gondola.cpp:90:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   90 |     if(vec.size()==n+1) sum=(sum*n)%mod;
      |        ~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 17 ms 2796 KB Output is correct
7 Correct 17 ms 748 KB Output is correct
8 Correct 35 ms 5092 KB Output is correct
9 Correct 10 ms 1900 KB Output is correct
10 Correct 38 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 17 ms 2796 KB Output is correct
7 Correct 12 ms 748 KB Output is correct
8 Correct 36 ms 5100 KB Output is correct
9 Correct 10 ms 1900 KB Output is correct
10 Correct 40 ms 5860 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 19 ms 2668 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 56 ms 6116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 10 ms 1260 KB Output is correct
12 Correct 12 ms 1388 KB Output is correct
13 Correct 17 ms 1768 KB Output is correct
14 Correct 11 ms 1260 KB Output is correct
15 Correct 25 ms 2536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 54 ms 6116 KB Output is correct
10 Correct 44 ms 5092 KB Output is correct
11 Correct 14 ms 2156 KB Output is correct
12 Correct 18 ms 2540 KB Output is correct
13 Correct 4 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 57 ms 6120 KB Output is correct
10 Correct 48 ms 5216 KB Output is correct
11 Correct 14 ms 2156 KB Output is correct
12 Correct 18 ms 2540 KB Output is correct
13 Correct 4 ms 876 KB Output is correct
14 Correct 68 ms 7400 KB Output is correct
15 Correct 75 ms 8168 KB Output is correct
16 Correct 12 ms 1900 KB Output is correct
17 Correct 47 ms 5612 KB Output is correct
18 Correct 25 ms 3436 KB Output is correct