Skip to content

Commit fbf0031

Browse files
committed
January Cook Off 2018
1 parent ad4eb51 commit fbf0031

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed

CP/DecemberCookOff2017/prob2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
t=input()
2+
for i in range(t):
3+
n=input()
4+
arr=map(int,raw_input().split())
5+
s=sum(arr)
6+
if s%4!=0:
7+
print -1
8+
else:
9+
a,b,c=[0,0,0]
10+
for i in arr:
11+
if i%4==1:
12+
a+=1
13+
elif i%4==2:
14+
b+=1
15+
elif i%4==3:
16+
c+=1
17+
#print a,b,c
18+
#a,b,c=[2,5,8]
19+
ans=0
20+
ans+=min(a,c)
21+
ans+=b/2
22+
oth=max(a,c)-min(a,c)
23+
#print a,b,c
24+
if b%2==0:
25+
ans+=3*(oth/4)
26+
else:
27+
ans+=2+3*((oth-2)/4)
28+
print ans

CP/JanuaryCookOff2018/prob1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import math
2+
for kohli in range(input()):
3+
n,k,s = map(int,raw_input().split())
4+
if(n<k or (6*n<7*k and s>=7)):
5+
print("-1")
6+
continue
7+
c = int(math.ceil(s*1.0/(n*1.0/k*1.0)))
8+
print(c)
9+
10+
11+
'''
12+
2
13+
16 2 10
14+
50 48 7
15+
'''

CP/JanuaryCookOff2018/prob2.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from __future__ import division
2+
from math import ceil
3+
from bisect import bisect_right as b_r
4+
from bisect import bisect_left as b_l
5+
for __ in range(int(input())):
6+
a = map(int,raw_input().split())
7+
s = (a[1]+a[2])%10
8+
lis = [a[1],a[2]]
9+
c=2
10+
if(s%2==1):
11+
lis.append(s)
12+
c+=1
13+
s = (s*2)%10
14+
#print(s)
15+
rem = (a[0]-c)%4
16+
loop = (a[0]-c)//4
17+
#print(rem,loop)
18+
summ = sum(lis)
19+
summ += (loop*20)%3
20+
tt = [4,8,6,2,4,8,6,2]
21+
st = '4862'
22+
i = st.find(str(s))
23+
for j in range(0,rem):
24+
summ+=tt[i+j]
25+
summ%=3
26+
if(a[0]==2):
27+
if((a[1]+a[2])%3==0):
28+
print 'YES'
29+
else:
30+
print 'NO'
31+
elif(s==0):
32+
print 'NO'
33+
elif(summ%3==0):
34+
print 'YES'
35+
else:
36+
print 'NO'
37+
38+
39+
40+
41+
'''
42+
2
43+
5 3 4
44+
13 8 1
45+
46+
'''

CP/JanuaryCookOff2018/prob3.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
const int oo = 1000000000;
6+
7+
const int N = 100005;
8+
9+
int a[N], val[N][2], f[N][2], g[N][2];
10+
11+
void solve() {
12+
int n;
13+
scanf("%d", &n);
14+
15+
for (int i = 1; i <= n; i++) {
16+
scanf("%d", a+i);
17+
}
18+
19+
if (n == 1) {
20+
printf("0\n");
21+
return;
22+
}
23+
24+
for (int i = 1; i <= n; i++) {
25+
val[i][0] = a[i];
26+
val[i][1] = a[n+1-i];
27+
}
28+
29+
int m = n/2;
30+
for (int i = 1; i <= m; i++)
31+
for (int k = 0; k < 2; k++)
32+
f[i][k] = g[i][k] = oo;
33+
f[1][0] = g[1][0] = 0;
34+
f[1][1] = g[1][1] = 1;
35+
for (int i = 1; i < m; i++) {
36+
for (int j = 0; j < 2; j++) {
37+
for (int k = 0; k < 2; k++) {
38+
int c1 = val[i][j];
39+
int c2 = val[i+1][k];
40+
if (((i & 1) && (c1 <= c2)) || (((i & 1) == 0) && c1 >= c2)) continue;
41+
int t = n+1-i;
42+
c1 = val[t][j];
43+
c2 = val[t-1][k];
44+
if (((t & 1) && (c1 <= c2)) || (((t & 1) == 0) && c1 >= c2)) continue;
45+
f[i+1][k] = min(f[i+1][k], f[i][j] + k);
46+
}
47+
for (int k = 0; k < 2; k++) {
48+
int c1 = val[i][j];
49+
int c2 = val[i+1][k];
50+
if (((i & 1) && (c1 >= c2)) || (((i & 1) == 0) && c1 <= c2)) continue;
51+
int t = n+1-i;
52+
c1 = val[t][j];
53+
c2 = val[t-1][k];
54+
if (((t & 1) && (c1 >= c2)) || (((t & 1) == 0) && c1 <= c2)) continue;
55+
g[i+1][k] = min(g[i+1][k], g[i][j] + k);
56+
}
57+
}
58+
}
59+
60+
int ans = oo;
61+
62+
if (n % 2 == 0) {
63+
for (int j = 0; j < 2; j++) {
64+
int c1 = val[m][j];
65+
int c2 = val[m+1][j];
66+
if (((m&1) && (c1 > c2)) || ((m&1) == 0 && (c1 < c2)))
67+
ans = min(ans, f[m][j]);
68+
if (((m&1) && (c1 < c2)) || ((m&1) == 0 && (c1 > c2)))
69+
ans = min(ans, g[m][j]);
70+
}
71+
}
72+
else {
73+
int c1 = a[m];
74+
int c2 = a[m+2];
75+
int b = a[m+1];
76+
if ((((m+1)&1) && b > c1 && b > c2) || (((m+1)&1) == 0 && b < c1 && b < c2))
77+
ans = min(ans, min(f[m][0], f[m][1]));
78+
if ((((m+1)&1) && b < c1 && b < c2) || (((m+1)&1) == 0 && b > c1 && b > c2))
79+
ans = min(ans, min(g[m][0], g[m][1]));
80+
}
81+
82+
if (ans >= oo) ans = -1;
83+
printf("%d\n", ans);
84+
}
85+
86+
int main() {
87+
int ct;
88+
scanf("%d", &ct);
89+
90+
while (ct--) solve();
91+
}

CP/JanuaryCookOff2018/prob4.cpp

Whitespace-only changes.

CP/JanuaryCookOff2018/prob5.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)