Skip to content

Commit 2f0286b

Browse files
committed
I participated in Goodbye 1400 on March 14th.
1 parent 1df69bf commit 2f0286b

File tree

5 files changed

+168
-0
lines changed

5 files changed

+168
-0
lines changed
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# خداحافظ 1400 (Goodbye 1400)
2+
- I participated in Goodbye 1400 competition which was held by Quera on [Quera.ir](https://quera.org/contest/assignments/40731/problems/137872)
3+
- My rank in this contest: 50th
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* https://quera.org/contest/assignments/40731/problems/137871
3+
* Author: https://github.com/smh997/
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
8+
int n, C;
9+
int f[21];
10+
int dp[(1<<18)+3];
11+
int cap[(1<<18)+3];
12+
13+
int main()
14+
{
15+
ios_base::sync_with_stdio(false);
16+
cin.tie(NULL);
17+
int csum = 0;
18+
cin >> n >> C;
19+
for (int i = 0; i < n; ++i) {
20+
cin >> f[i];
21+
if(f[i] == C)
22+
csum++;
23+
}
24+
dp[0] = 0;
25+
if(csum == n || csum == n-1){
26+
cout << n << endl;
27+
return 0;
28+
}
29+
for (int i = 1; i < (1<<n); ++i) {
30+
dp[i] = 1e9;
31+
int sum = 0;
32+
for (int b = 0; b < n; ++b) {
33+
if(i & (1<<b)){
34+
sum += f[b];
35+
}
36+
}
37+
cap[i] = sum;
38+
if(cap[i] <= C)
39+
dp[i] = 1;
40+
}
41+
for (int mask = 1; mask < (1<<n); ++mask) {
42+
if(dp[mask] != 1e9)
43+
continue;
44+
int prevy = mask & (mask-1);
45+
while(prevy != 0){
46+
dp[mask] = min(dp[mask], dp[mask-prevy] + dp[prevy]);
47+
prevy = mask & (prevy-1);
48+
}
49+
}
50+
cout << dp[(1<<n)-1] << endl;
51+
return 0;
52+
}
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
https://quera.org/contest/assignments/40731/problems/137869
3+
Author: https://github.com/smh997/
4+
"""
5+
n = int(input())
6+
li = []
7+
for i in range(n):
8+
l, r = map(int, input().split())
9+
li.append((l, r))
10+
li.sort()
11+
l, r = -1, -1
12+
arr = set()
13+
for rang in li:
14+
if (l, r) == (-1, -1):
15+
l, r = rang[0], rang[1]
16+
continue
17+
if rang[0] <= r < rang[1]:
18+
r = rang[1]
19+
elif rang[0] > r:
20+
arr.add((l, r))
21+
l, r = rang[0], rang[1]
22+
arr.add((l, r))
23+
arr = sorted(list(arr))
24+
one_flag, hundred_flag = True, True
25+
for rang in arr:
26+
if rang[0] == 1 or rang[1] == 1:
27+
one_flag = False
28+
if rang[0] == 100 or rang[1] == 100:
29+
hundred_flag = False
30+
if hundred_flag or one_flag:
31+
print(-1)
32+
else:
33+
print(len(arr)-1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
https://quera.org/contest/assignments/40731/problems/137872
3+
Author: https://github.com/smh997/
4+
"""
5+
a, b = map(int, input().split())
6+
c, d = max(a, b), min(a, b)
7+
bb = c / 2
8+
aa = bb
9+
cc = d
10+
li = [aa, bb, cc]
11+
li.sort()
12+
if li[2] < li[1] + li[0]:
13+
print('YES')
14+
else:
15+
print('NO')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* https://quera.org/contest/assignments/40731/problems/137866
3+
* Author: https://github.com/smh997/
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
8+
#define inf INT_MAX
9+
#define num long long int
10+
11+
const int maxn = 503;
12+
13+
int n, m, q;
14+
num sp[maxn][maxn];
15+
num a[500003], b[500003];
16+
17+
int main(){
18+
cin >> n >> m;
19+
for(int i = 0; i < n; i++)
20+
for(int j = 0; j < n; j++){
21+
if(i == j)
22+
sp[i][j] = 0;
23+
else
24+
sp[i][j] = inf;
25+
}
26+
for(int i = 0; i < m; i++){
27+
int u, v;
28+
cin >> u >> v;
29+
u--;v--;
30+
sp[u][v] = (num)1;
31+
sp[v][u] = sp[u][v];
32+
}
33+
for(int k = 0; k < n; k++)
34+
for(int i = 0; i < n; i++)
35+
for(int j = 0; j < n; j++)
36+
if(sp[i][k] != inf && sp[k][j] != inf && sp[i][k] + sp[k][j] < sp[i][j])
37+
sp[i][j] = sp[i][k] + sp[k][j];
38+
cin >> q;
39+
num res = 0;
40+
bool fff = false;
41+
for (int i = 0; i < q; ++i) {
42+
cin >> a[i];
43+
a[i]--;
44+
}
45+
for (int i = 0; i < q; ++i) {
46+
cin >> b[i];
47+
b[i]--;
48+
if(!fff){
49+
if(b[i] != a[i]){
50+
if(sp[b[i]][a[i]] == inf){
51+
res = inf;
52+
fff = true;
53+
}
54+
else{
55+
res += sp[b[i]][a[i]];
56+
}
57+
}
58+
}
59+
}
60+
if(fff)
61+
cout << -1 << endl;
62+
else
63+
cout << res << endl;
64+
}

0 commit comments

Comments
 (0)