| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1357477 | lkjlkajfa | Gingerbread (BOI25_gcd) | C++20 | 180 ms | 23824 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[1000005];
ll n;
ll res=30;
void solve(ll sl, ll i,ll gcd){
if (sl>=res) return;
if (i>n){
if (gcd==1){
res=min(res,sl);
}
return;
}
for (int j=0;j<20;j++){
a[i]+=j;
solve(sl+j,i+1,__gcd(gcd,a[i]));
a[i]-=j;
}
return;
}
ll prf[1000005],sf[1000005];
int main(){
//ll n;
cin>>n;
ll gcdd=0;
for (int i=1;i<=n;i++){
cin>>a[i];
//gcdd=__gcd(a[i],gcdd);
prf[i]=__gcd(prf[i-1],a[i]);
}
for(int i=n;i>=1;i--){
sf[i]=__gcd(sf[i+1],a[i]);
}
if (prf[n]==1){
cout<<0;
return 0;
}
for (int i=1;i<=n;i++){
if (__gcd(a[i]+1,__gcd(prf[i-1],sf[i+1]))==1){
cout<<1;
//cout<<i<<' '<<prf[i-1]<<' '<<sf[i+1]<<'\n';
// cout<<a[i]+1;
return 0;
}
}
solve(0,1,0);
cout<<res;
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
