Skip to content

Commit 86275c2

Browse files
committedMay 24, 2017
Add submissions for May17 Cookoff
1 parent fcab3b9 commit 86275c2

File tree

13 files changed

+409
-0
lines changed

13 files changed

+409
-0
lines changed
 

‎CookOff/May17/COOK82A.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define ull unsigned long long
4+
#define vi vector<ll>
5+
#define pp pair<ll,ll>
6+
#define mp make_pair
7+
#define PI acos(-1.0)
8+
#define all(v) v.begin(),v.end()
9+
#define pb push_back
10+
#define FOR(i,a,b) for(i=a;i<b;i++)
11+
#define FREV(i,a,b) for(i=a;i>=b;i--)
12+
#define SULL(n) scanf("%llu", &n)
13+
#define INF 1e18
14+
15+
#ifndef ONLINE_JUDGE
16+
#define gc getchar
17+
#define pc putchar
18+
#else
19+
#define gc getchar_unlocked
20+
#define pc putchar_unlocked
21+
#endif
22+
23+
using namespace std;
24+
25+
int read_int() {
26+
char c = gc();
27+
while((c < '0' || c > '9') && c != '-') c = gc();
28+
int ret = 0, neg = 0;
29+
if (c == '-') neg = 1, c = gc();
30+
while(c >= '0' && c <= '9') {
31+
ret = 10 * ret + c - 48;
32+
c = gc();
33+
}
34+
return neg ? -ret : ret;
35+
}
36+
37+
ll read_ll() {
38+
char c = gc();
39+
while((c < '0' || c > '9') && c != '-') c = gc();
40+
ll ret = 0;
41+
int neg = 0;
42+
if (c == '-') neg = 1, c = gc();
43+
while(c >= '0' && c <= '9') {
44+
ret = 10 * ret + c - 48;
45+
c = gc();
46+
}
47+
return neg ? -ret : ret;
48+
}
49+
50+
int main() {
51+
ll i,j,t,n;
52+
ll goals[4];
53+
t = read_ll();
54+
string s;
55+
while(t--) {
56+
FOR(i,0,4) {
57+
cin >> s;
58+
if(s[0] == 'B') {
59+
cin >> goals[0];
60+
}
61+
else if(s[0] == 'E') {
62+
cin >> goals[1];
63+
}
64+
else if(s[0] == 'R') {
65+
cin >> goals[2];
66+
}
67+
else {
68+
cin >> goals[3];
69+
}
70+
}
71+
if (goals[0] > goals[1] && goals[2] < goals[3]) {
72+
cout << "Barcelona\n";
73+
}
74+
else {
75+
cout << "RealMadrid\n";
76+
}
77+
}
78+
return 0;
79+
}

‎CookOff/May17/COOK82B.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define ull unsigned long long
4+
#define vi vector<ll>
5+
#define pp pair<ll,ll>
6+
#define mp make_pair
7+
#define PI acos(-1.0)
8+
#define all(v) v.begin(),v.end()
9+
#define pb push_back
10+
#define FOR(i,a,b) for(i=a;i<b;i++)
11+
#define FREV(i,a,b) for(i=a;i>=b;i--)
12+
#define SULL(n) scanf("%llu", &n)
13+
#define INF 1e18
14+
15+
#ifndef ONLINE_JUDGE
16+
#define gc getchar
17+
#define pc putchar
18+
#else
19+
#define gc getchar_unlocked
20+
#define pc putchar_unlocked
21+
#endif
22+
23+
using namespace std;
24+
25+
int read_int() {
26+
char c = gc();
27+
while((c < '0' || c > '9') && c != '-') c = gc();
28+
int ret = 0, neg = 0;
29+
if (c == '-') neg = 1, c = gc();
30+
while(c >= '0' && c <= '9') {
31+
ret = 10 * ret + c - 48;
32+
c = gc();
33+
}
34+
return neg ? -ret : ret;
35+
}
36+
37+
ll read_ll() {
38+
char c = gc();
39+
while((c < '0' || c > '9') && c != '-') c = gc();
40+
ll ret = 0;
41+
int neg = 0;
42+
if (c == '-') neg = 1, c = gc();
43+
while(c >= '0' && c <= '9') {
44+
ret = 10 * ret + c - 48;
45+
c = gc();
46+
}
47+
return neg ? -ret : ret;
48+
}
49+
50+
const ll MAX = 1e9+7;
51+
map<ll,ll> prime_factors;
52+
vi primes;
53+
map<ll,ll>::iterator it;
54+
55+
void sieve()
56+
{
57+
ll n = 1e5;
58+
bool prime[n+1];
59+
memset(prime, true, sizeof(prime));
60+
61+
for (ll p=2; p*p<=n; p++)
62+
{
63+
if (prime[p] == true)
64+
{
65+
for (ll i=p*2; i<=n; i += p)
66+
prime[i] = false;
67+
}
68+
}
69+
for (ll p=2; p<=n; p++)
70+
if (prime[p])
71+
primes.pb(p);
72+
}
73+
74+
void factorize(ll n) {
75+
if (n == 1) {
76+
return;
77+
}
78+
ll power,i,j;
79+
for(j=0; j<primes.size(); j++) {
80+
i = primes[j];
81+
power = 0;
82+
while (n%i == 0) {
83+
n = n / i;
84+
power++;
85+
}
86+
if(power != 0) {
87+
prime_factors[i] += power;
88+
}
89+
}
90+
if (n != 1) {
91+
prime_factors[n] += 1;
92+
}
93+
}
94+
95+
ll find_pow(ll base, ll exponent) {
96+
ll res = 1;
97+
base = base % MAX;
98+
while(exponent > 0) {
99+
if(exponent%2) {
100+
res = (res*base)%MAX;
101+
}
102+
base = (base*base)%MAX;
103+
exponent /= 2;
104+
}
105+
return res;
106+
}
107+
108+
int main() {
109+
ll i,j,t,n;
110+
sieve();
111+
n = read_ll();
112+
FOR(i,0,n) {
113+
j = read_ll();
114+
factorize(j);
115+
}
116+
bool flag = true;
117+
for(it = prime_factors.begin(); it != prime_factors.end(); it++) {
118+
//cout<<it->first<<" "<<it->second<<endl;
119+
if(it->second % n != 0) {
120+
flag = false;
121+
break;
122+
}
123+
}
124+
if (flag == true) {
125+
printf("justdoit");
126+
return 0;
127+
}
128+
ll res = 1;
129+
for(it = prime_factors.begin(); it != prime_factors.end(); it++) {
130+
if (it->second % (n+1) != 0)
131+
res = (res * find_pow(it->first,n+1 - (it->second % (n+1)))) % MAX;
132+
}
133+
printf("%lld", res);
134+
135+
return 0;
136+
}

‎CookOff/May17/COOK82C.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define ull unsigned long long
4+
#define vi vector<ll>
5+
#define pp pair<ll,ll>
6+
#define mp make_pair
7+
#define PI acos(-1.0)
8+
#define all(v) v.begin(),v.end()
9+
#define pb push_back
10+
#define FOR(i,a,b) for(i=a;i<b;i++)
11+
#define FREV(i,a,b) for(i=a;i>=b;i--)
12+
#define SULL(n) scanf("%llu", &n)
13+
#define INF 1e18
14+
#define MOD 1000000007
15+
16+
#ifndef ONLINE_JUDGE
17+
#define gc getchar
18+
#define pc putchar
19+
#else
20+
#define gc getchar_unlocked
21+
#define pc putchar_unlocked
22+
#endif
23+
24+
using namespace std;
25+
26+
int read_int() {
27+
char c = gc();
28+
while((c < '0' || c > '9') && c != '-') c = gc();
29+
int ret = 0, neg = 0;
30+
if (c == '-') neg = 1, c = gc();
31+
while(c >= '0' && c <= '9') {
32+
ret = 10 * ret + c - 48;
33+
c = gc();
34+
}
35+
return neg ? -ret : ret;
36+
}
37+
38+
ll read_ll() {
39+
char c = gc();
40+
while((c < '0' || c > '9') && c != '-') c = gc();
41+
ll ret = 0;
42+
int neg = 0;
43+
if (c == '-') neg = 1, c = gc();
44+
while(c >= '0' && c <= '9') {
45+
ret = 10 * ret + c - 48;
46+
c = gc();
47+
}
48+
return neg ? -ret : ret;
49+
}
50+
51+
stack<ll> stk;
52+
queue<ll> q;
53+
vi a;
54+
55+
void solve(ll n, ll m) {
56+
ll i,cur,ans,prev = 1;
57+
sort(all(a));
58+
FOR(i,0,n) {
59+
stk.push(a[i]);
60+
}
61+
// ans = stk.top();
62+
FOR(i,0,m) {
63+
cur = read_ll();
64+
while (prev <= cur) {
65+
if (q.empty() && !stk.empty()) {
66+
ans = stk.top();
67+
stk.pop();
68+
}
69+
else if (!q.empty() && !stk.empty()) {
70+
if (stk.top() > q.front()) {
71+
ans = stk.top();
72+
stk.pop();
73+
}
74+
else {
75+
ans = q.front();
76+
q.pop();
77+
}
78+
}
79+
else if (stk.empty() && !q.empty()) {
80+
ans = q.front();
81+
q.pop();
82+
}
83+
if (ans / 2 > 0) {
84+
q.push(ans / 2);
85+
}
86+
prev++;
87+
}
88+
printf("%lld\n", ans);
89+
}
90+
}
91+
92+
int main() {
93+
ll i,j,t,n,m;
94+
n = read_ll();
95+
m = read_ll();
96+
a.resize(n);
97+
FOR(i,0,n) {
98+
a[i] = read_ll();
99+
}
100+
solve(n,m);
101+
return 0;
102+
}

‎CookOff/May17/COOK82D.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define ull unsigned long long
4+
#define vi vector<ll>
5+
#define pp pair<ll,ll>
6+
#define mp make_pair
7+
#define PI acos(-1.0)
8+
#define all(v) v.begin(),v.end()
9+
#define pb push_back
10+
#define FOR(i,a,b) for(i=a;i<b;i++)
11+
#define FREV(i,a,b) for(i=a;i>=b;i--)
12+
#define SULL(n) scanf("%llu", &n)
13+
#define INF 1e18
14+
#define MOD 1000000007
15+
16+
#ifndef ONLINE_JUDGE
17+
#define gc getchar
18+
#define pc putchar
19+
#else
20+
#define gc getchar_unlocked
21+
#define pc putchar_unlocked
22+
#endif
23+
24+
using namespace std;
25+
26+
int read_int() {
27+
char c = gc();
28+
while((c < '0' || c > '9') && c != '-') c = gc();
29+
int ret = 0, neg = 0;
30+
if (c == '-') neg = 1, c = gc();
31+
while(c >= '0' && c <= '9') {
32+
ret = 10 * ret + c - 48;
33+
c = gc();
34+
}
35+
return neg ? -ret : ret;
36+
}
37+
38+
ll read_ll() {
39+
char c = gc();
40+
while((c < '0' || c > '9') && c != '-') c = gc();
41+
ll ret = 0;
42+
int neg = 0;
43+
if (c == '-') neg = 1, c = gc();
44+
while(c >= '0' && c <= '9') {
45+
ret = 10 * ret + c - 48;
46+
c = gc();
47+
}
48+
return neg ? -ret : ret;
49+
}
50+
51+
int main() {
52+
ll i,j,t,n,m,l,r,u,v;
53+
n = read_ll();
54+
m = read_ll();
55+
vi hash(n+1);
56+
vi edges(2*m+1);
57+
FOR(i,1,n+1) {
58+
hash[i] = (rand() * 1LL * rand()) % MOD;
59+
}
60+
FOR(i,0,m) {
61+
u = read_ll();
62+
v = read_ll();
63+
edges[2*i + 1] = hash[u];
64+
edges[2*i + 2] = hash[v];
65+
}
66+
FOR(i,1,2*m+1) {
67+
edges[i] = edges[i] ^ edges[i-1];
68+
}
69+
t = read_ll();
70+
FOR(i,0,t) {
71+
l = read_ll();
72+
r = read_ll();
73+
l = 2*l - 2;
74+
r = 2*r;
75+
if (edges[l] == edges[r]) {
76+
printf("Yes\n");
77+
}
78+
else {
79+
printf("No\n");
80+
}
81+
}
82+
83+
return 0;
84+
}

‎CookOff/May17/input

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
4 6
2+
8 5 3 1
3+
1
4+
2
5+
3
6+
4
7+
6
8+
8
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)
Please sign in to comment.