Contest Duration: - (local time) (100 minutes) Back to Home

Submission #6706696

Source Code Expand

Copy
```   #include <bits/stdc++.h>

//    #include <boost/multiprecision/cpp_int.hpp>
#define int long long
#define inf  1000000007
#define pa pair<int,int>
#define ll long long
#define pal pair<double,double>
#define ppap pair<pa,int>
#define PI 3.14159265358979323846
#define paa pair<int,char>
#define  mp make_pair
#define  pb push_back
#define EPS (1e-10)

int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,-1,1,1,-1};
using namespace std;
class pa3{
public:
int x;
int y,z;
pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
bool operator < (const pa3 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
return z<p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa3 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
return z>p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa3 &p) const{
return x==p.x && y==p.y && z==p.z;
}
bool operator != (const pa3 &p) const{
return !( x==p.x && y==p.y && z==p.z);
}

};

class pa4{
public:
int x;
int y,z,w;
pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
bool operator < (const pa4 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
if(z!=p.z)return z<p.z;
return w<p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa4 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
if(z!=p.z)return z>p.z;
return w>p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa4 &p) const{
return x==p.x && y==p.y && z==p.z &&w==p.w;
}

};
class pa2{
public:
int x,y;
pa2(int x=0,int y=0):x(x),y(y) {}
pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
bool operator < (const pa2 &p) const{
return y != p.y ? y<p.y: x<p.x;
}
bool operator > (const pa2 &p) const{
return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa2 &p) const{
return abs(x-p.x)==0 && abs(y-p.y)==0;
}
bool operator != (const pa2 &p) const{
return !(abs(x-p.x)==0 && abs(y-p.y)==0);
}

};

string itos( int i ) {
ostringstream s ;
s << i ;
return s.str() ;
}

int gcd(int v,int b){
if(v>b) return gcd(b,v);
if(v==b) return b;
if(b%v==0) return v;
return gcd(v,b%v);
}

int mod;
int extgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = extgcd(b, a%b, y, x);
y -= a/b * x;
return d;
}
pa operator+(const pa & l,const pa & r) {
return {l.first+r.first,l.second+r.second};
}
pa operator-(const pa & l,const pa & r) {
return {l.first-r.first,l.second-r.second};
}

int pr[200010];
int inv[200010];

int beki(int wa,int rr,int warukazu){
if(rr==0) return 1%warukazu;
if(rr==1) return wa%warukazu;
wa%=warukazu;
if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
ll zx=beki(wa,rr/2,warukazu);
return (zx*zx)%warukazu;
}

int comb(int nn,int rr){
if(rr<0 || rr>nn || nn<0) return 0;
int r=pr[nn]*inv[rr];
r%=mod;
r*=inv[nn-rr];
r%=mod;
return r;
}

void gya(int ert){
pr[0]=1;
for(int i=1;i<=ert;i++){
pr[i]=(pr[i-1]*i)%mod;
}
inv[ert]=beki(pr[ert],mod-2,mod);
for(int i=ert-1;i>=0;i--){
inv[i]=inv[i+1]*(i+1)%mod;
}
}

//   cin.tie(0);
//	ios::sync_with_stdio(false);
//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
//sort(ve.begin(),ve.end(),greater<int>());
//    mt19937(clock_per_sec);

int dp[100020][50];

int ans[100020];

int solve(int r){
int re=1000000000;

for(int i=0;i<40;i++)if(re&(1ll<<i)){
r=dp[r][i];
}
//	cout<<r<<endl;
return r;

}

signed main(){

cin.tie(0);
ios::sync_with_stdio(false);

int n,k;
cin>>n>>k;
int wa=0;
vector<int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
wa+=a[i];
}

vector<int> yaku;

for(int i=1;i*i<=wa;i++)if(wa%i==0){
if(i*i==wa) yaku.pb(i);
else{
yaku.pb(i);
yaku.pb(wa/i);
}

}

int ans=1;

for(auto v:yaku){
vector<pa> w;

for(auto t:a){
if(t%v==0) continue;
w.pb(mp(t%v,v-t%v));
}
sort(w.begin(),w.end());

int l=w.size();
int mae=0;
int ato=0;
for(int i=0;i<l;i++)ato+=w[i].second;
for(int i=0;i<=l;i++){
if(mae==ato){
if(mae<=k)ans=max(ans,v);
break;
}
if(i==l){
cout<<"dame"<<endl;
break;
}
mae+=w[i].first;
ato-=w[i].second;
}

}

cout<<ans<<endl;
return 0;

}```

#### Submission Info

Submission Time 2019-08-04 22:14:26+0900 E - Max GCD smiken C++14 (GCC 5.4.1) 500 9217 Byte AC 29 ms 256 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
 AC × 4
 AC × 84
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt, 67.txt, 68.txt, 69.txt, 70.txt, 71.txt, 72.txt, 73.txt, 74.txt, 75.txt, 76.txt, 77.txt, 78.txt, 79.txt, 80.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KB
02.txt AC 2 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 1 ms 256 KB
12.txt AC 1 ms 256 KB
13.txt AC 2 ms 256 KB
14.txt AC 2 ms 256 KB
15.txt AC 1 ms 256 KB
16.txt AC 1 ms 256 KB
17.txt AC 2 ms 256 KB
18.txt AC 2 ms 256 KB
19.txt AC 1 ms 256 KB
20.txt AC 2 ms 256 KB
21.txt AC 6 ms 256 KB
22.txt AC 5 ms 256 KB
23.txt AC 3 ms 256 KB
24.txt AC 3 ms 256 KB
25.txt AC 3 ms 256 KB
26.txt AC 2 ms 256 KB
27.txt AC 2 ms 256 KB
28.txt AC 3 ms 256 KB
29.txt AC 3 ms 256 KB
30.txt AC 7 ms 256 KB
31.txt AC 3 ms 256 KB
32.txt AC 3 ms 256 KB
33.txt AC 4 ms 256 KB
34.txt AC 4 ms 256 KB
35.txt AC 2 ms 256 KB
36.txt AC 4 ms 256 KB
37.txt AC 6 ms 256 KB
38.txt AC 2 ms 256 KB
39.txt AC 2 ms 256 KB
40.txt AC 3 ms 256 KB
41.txt AC 5 ms 256 KB
42.txt AC 4 ms 256 KB
43.txt AC 2 ms 256 KB
44.txt AC 4 ms 256 KB
45.txt AC 1 ms 256 KB
46.txt AC 2 ms 256 KB
47.txt AC 2 ms 256 KB
48.txt AC 2 ms 256 KB
49.txt AC 2 ms 256 KB
50.txt AC 2 ms 256 KB
51.txt AC 2 ms 256 KB
52.txt AC 2 ms 256 KB
53.txt AC 2 ms 256 KB
54.txt AC 2 ms 256 KB
55.txt AC 2 ms 256 KB
56.txt AC 2 ms 256 KB
57.txt AC 3 ms 256 KB
58.txt AC 2 ms 256 KB
59.txt AC 2 ms 256 KB
60.txt AC 5 ms 256 KB
61.txt AC 2 ms 256 KB
62.txt AC 2 ms 256 KB
63.txt AC 2 ms 256 KB
64.txt AC 2 ms 256 KB
65.txt AC 2 ms 256 KB
66.txt AC 2 ms 256 KB
67.txt AC 2 ms 256 KB
68.txt AC 3 ms 256 KB
69.txt AC 2 ms 256 KB
70.txt AC 2 ms 256 KB
71.txt AC 2 ms 256 KB
72.txt AC 2 ms 256 KB
73.txt AC 2 ms 256 KB
74.txt AC 2 ms 256 KB
75.txt AC 2 ms 256 KB
76.txt AC 28 ms 256 KB
77.txt AC 29 ms 256 KB
78.txt AC 19 ms 256 KB
79.txt AC 28 ms 256 KB
80.txt AC 26 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB
s4.txt AC 1 ms 256 KB