Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25b05b9

Browse files
committed
+ Codeforces Round #313 (Div. 1)
1 parent d49777e commit 25b05b9

File tree

5 files changed

+255
-0
lines changed

5 files changed

+255
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
typedef long long int64;
6+
7+
const int64 MOD = 1000000007;
8+
9+
const int
10+
MAXN = 1 << 11,
11+
MAX_SUM = 1 << 20;
12+
13+
int K;
14+
int a[MAXN];
15+
16+
int64 fact[MAX_SUM];
17+
int64 inv[MAX_SUM];
18+
int64 invFact[MAX_SUM];
19+
int64 sum;
20+
int64 ans;
21+
22+
int64 ways(int n, int k) {
23+
return fact[n + k - 1] * invFact[n] % MOD * invFact[k - 1] % MOD;
24+
}
25+
26+
int main() {
27+
ios_base::sync_with_stdio(0);
28+
29+
30+
inv[1] = 1;
31+
for (int i = 2; i < MAX_SUM; ++i)
32+
inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;
33+
34+
fact[0] = invFact[0] = 1;
35+
36+
for (int i = 1; i < MAX_SUM; ++i) {
37+
fact[i] = fact[i - 1] * i % MOD;
38+
invFact[i] = invFact[i - 1] * inv[i] % MOD;
39+
}
40+
41+
cin >> K;
42+
ans = 1;
43+
for (int i = 1; i <= K; ++i) {
44+
cin >> a[i];
45+
ans = ans * ways(a[i] - 1, sum + 1) % MOD;
46+
sum += a[i];
47+
}
48+
49+
cout << ans << endl;
50+
51+
return 0;
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
typedef long long int64;
5+
6+
int N;
7+
int64 K;
8+
int64 fib[60];
9+
10+
int main() {
11+
ios_base::sync_with_stdio(0);
12+
13+
fib[0] = 1;
14+
fib[1] = 1;
15+
fib[2] = 2;
16+
for (int i = 3; i < 60; ++i)
17+
fib[i] = fib[i - 1] + fib[i - 2];
18+
19+
cin >> N >> K;
20+
21+
int curFib = N;
22+
for (int i = 1; i <= N;)
23+
if (K <= fib[curFib - 1]) {
24+
cout << i << " ";
25+
i++;
26+
curFib--;
27+
} else {
28+
K -= fib[curFib - 1];
29+
cout << i+1 << " " << i << " ";
30+
i += 2 ;
31+
curFib -= 2;
32+
}
33+
34+
return 0;
35+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
typedef long long int64;
5+
6+
const int64 MOD = 1000000007;
7+
8+
const int
9+
MAXV = 1 << 17;
10+
11+
int V, E;
12+
int data[MAXV];
13+
int components;
14+
vector<int> hate[MAXV];
15+
vector<int> love[MAXV];
16+
17+
int findSet(int x) {
18+
return data[x] < 0 ? x : data[x] = findSet(data[x]);
19+
}
20+
21+
int getSize(int x) {
22+
return -data[findSet(x)];
23+
}
24+
25+
void join(int u, int v) {
26+
u = findSet(u);
27+
v = findSet(v);
28+
if (u == v)
29+
return ;
30+
31+
32+
components--;
33+
34+
if (getSize(u) > getSize(v))
35+
swap(u, v);
36+
37+
data[u] += data[v];
38+
data[v] = u;
39+
}
40+
41+
int mark[MAXV][2];
42+
int curMark;
43+
44+
void dfs(int u, int x) {
45+
if (mark[u][1 - x] == curMark) {
46+
cout << 0 << endl;
47+
exit(0);
48+
}
49+
if (mark[u][x] == curMark)
50+
return ;
51+
mark[u][x] = curMark;
52+
for (int v : love[u]) dfs(v, x);
53+
for (int v : hate[u]) dfs(v, 1 - x);
54+
}
55+
56+
int main() {
57+
ios_base::sync_with_stdio(0);
58+
59+
memset(data, -1, sizeof(data));
60+
61+
cin >> V >> E;
62+
63+
components = V;
64+
65+
for (int i = 0; i < E; ++i) {
66+
int u, v, w;
67+
cin >> u >> v >> w;
68+
--u;
69+
--v;
70+
if (w == 0) {
71+
hate[u].push_back(v);
72+
hate[v].push_back(u);
73+
} else {
74+
love[u].push_back(v);
75+
love[v].push_back(u);
76+
}
77+
join(u, v);
78+
}
79+
80+
// search for cycles with odd number of hate relations
81+
for (int i = 0; i < V; ++i) if (data[i] < 0) {
82+
curMark++;
83+
dfs(i, 0);
84+
}
85+
86+
int64 result = 1;
87+
for (int i = 0; i < components - 1; ++i)
88+
result = 2 * result % MOD;
89+
90+
cout << result << endl;
91+
92+
return 0;
93+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
#include <cmath>
3+
using namespace std;
4+
5+
typedef long long int64;
6+
#define endl ('\n')
7+
8+
const double PI = atan(1)*4;
9+
10+
double calc(double ab, double ad, double dc) {
11+
const double D_120 = 120 * PI / 180;
12+
double ac = sqrt(dc*dc + ad*ad - 2*dc*ad* cos(D_120));
13+
double t = (dc*dc - ad*ad - ac*ac) / (-2*ad*ac);
14+
double dac = acos(t);
15+
double bac = D_120 - dac;
16+
return 0.5*ab*ac*sin(bac) + 0.5*ad*dc*sin(D_120);
17+
}
18+
19+
int main() {
20+
ios_base::sync_with_stdio(0);
21+
#ifndef LOCAL
22+
cin.tie(0);
23+
#endif
24+
25+
double a1, a2, a3, a4 ,a5, a6;
26+
cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;
27+
28+
double area = calc(a1, a2, a3) + calc(a4, a5, a6);
29+
int ans = round(area / (sqrt(3) / 4));
30+
cout << ans << endl;
31+
32+
return 0;
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
typedef long long int64;
5+
#define endl ('\n')
6+
7+
const int
8+
MAXN = 1 << 18;
9+
10+
int N;
11+
char A[MAXN];
12+
char B[MAXN];
13+
14+
void normalize(char* s, int n) {
15+
if (n % 2 == 1)
16+
return ;
17+
int mid = n / 2;
18+
normalize(s, mid);
19+
normalize(s + mid, mid);
20+
int cmp = memcmp(s, s + mid, mid);
21+
if (cmp > 0) {
22+
for (int i = 0; i < mid; ++i)
23+
swap(s[i], s[i + mid]);
24+
}
25+
}
26+
27+
int main() {
28+
ios_base::sync_with_stdio(0);
29+
#ifndef LOCAL
30+
cin.tie(0);
31+
#endif
32+
33+
cin >> A >> B;
34+
N = strlen(A);
35+
36+
normalize(A, N);
37+
normalize(B, N);
38+
39+
cout << ((strcmp(A, B) == 0) ? "YES" : "NO") << endl;
40+
41+
return 0;
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /