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

Submission #6692482

Source Code Expand

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,k;
int a[525];

bool ok(int x){
vi v;
int sum = 0;
REP(i,n){
int aa = a[i] % x;
sum += aa;
if(aa!=0)v.push_back(aa);
}
if(v.size()==0)return true;
if(sum%x != 0)return false;
sort(ALL(v));
deque<int> Q;
for(int y : v)Q.push_back(y);
int rest = k;
while(Q.size()){
if(Q.size()==1)return false;
int s = Q.front();
int t = Q.back();
int sub = min(s, x-t);
Q.front() -= sub;
if(Q.front()==0)Q.pop_front();
Q.back() += sub;
if(Q.back()==x)Q.pop_back();
rest -= sub;
if(rest < 0)return false;
}
return true;
}

int main(){
scanf("%d%d",&n,&k);
REP(i,n)scanf("%d",a+i);
int sum = 0;
REP(i,n)sum += a[i];

int ans = 1;
for(int x=1; x*x<=sum; x++){
if(ok(x))CHMAX(ans,x);
if(ok(sum/x))CHMAX(ans,sum/x);
}
printf("%d\n",ans);
return 0;
}
```

#### Submission Info

Submission Time 2019-08-04 21:17:20+0900 E - Max GCD rickytheta C++14 (GCC 5.4.1) 500 1690 Byte AC 132 ms 384 KB

#### Compile Error

```./Main.cpp: In function ‘int main()’:
./Main.cpp:58:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
^
./Main.cpp:59:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i,n)scanf("%d",a+i);
^
```

#### 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 127 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 2 ms 256 KB
10.txt AC 4 ms 256 KB
11.txt AC 2 ms 256 KB
12.txt AC 3 ms 256 KB
13.txt AC 76 ms 256 KB
14.txt AC 117 ms 256 KB
15.txt AC 39 ms 256 KB
16.txt AC 18 ms 256 KB
17.txt AC 109 ms 256 KB
18.txt AC 109 ms 256 KB
19.txt AC 82 ms 256 KB
20.txt AC 61 ms 256 KB
21.txt AC 119 ms 256 KB
22.txt AC 120 ms 256 KB
23.txt AC 124 ms 256 KB
24.txt AC 120 ms 256 KB
25.txt AC 125 ms 256 KB
26.txt AC 124 ms 256 KB
27.txt AC 121 ms 256 KB
28.txt AC 127 ms 256 KB
29.txt AC 125 ms 256 KB
30.txt AC 126 ms 256 KB
31.txt AC 119 ms 256 KB
32.txt AC 124 ms 256 KB
33.txt AC 121 ms 256 KB
34.txt AC 117 ms 256 KB
35.txt AC 123 ms 256 KB
36.txt AC 118 ms 256 KB
37.txt AC 122 ms 256 KB
38.txt AC 116 ms 256 KB
39.txt AC 115 ms 256 KB
40.txt AC 125 ms 256 KB
41.txt AC 116 ms 256 KB
42.txt AC 119 ms 256 KB
43.txt AC 122 ms 256 KB
44.txt AC 121 ms 256 KB
45.txt AC 111 ms 256 KB
46.txt AC 116 ms 256 KB
47.txt AC 119 ms 256 KB
48.txt AC 109 ms 256 KB
49.txt AC 121 ms 256 KB
50.txt AC 91 ms 256 KB
51.txt AC 105 ms 256 KB
52.txt AC 107 ms 256 KB
53.txt AC 98 ms 256 KB
54.txt AC 106 ms 256 KB
55.txt AC 124 ms 256 KB
56.txt AC 122 ms 256 KB
57.txt AC 122 ms 384 KB
58.txt AC 125 ms 256 KB
59.txt AC 119 ms 256 KB
60.txt AC 124 ms 256 KB
61.txt AC 118 ms 256 KB
62.txt AC 125 ms 256 KB
63.txt AC 122 ms 256 KB
64.txt AC 123 ms 256 KB
65.txt AC 125 ms 256 KB
66.txt AC 122 ms 256 KB
67.txt AC 124 ms 256 KB
68.txt AC 127 ms 256 KB
69.txt AC 128 ms 256 KB
70.txt AC 123 ms 256 KB
71.txt AC 125 ms 256 KB
72.txt AC 123 ms 256 KB
73.txt AC 124 ms 256 KB
74.txt AC 123 ms 256 KB
75.txt AC 123 ms 256 KB
76.txt AC 125 ms 256 KB
77.txt AC 114 ms 256 KB
78.txt AC 132 ms 256 KB
79.txt AC 125 ms 256 KB
80.txt AC 132 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