Skip to content

Commit fed02cf

Browse files
committed
new: ACPC 2022
1 parent 79ff178 commit fed02cf

File tree

7 files changed

+374
-0
lines changed

7 files changed

+374
-0
lines changed
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
#define int ll
5+
6+
const int N = 3e6 + 100;
7+
const int mod = 1e9 + 7;
8+
9+
int binpow(int a, int b) {
10+
int res = 1;
11+
while (b) {
12+
if (b & 1) {
13+
res *= a;
14+
res %= mod;
15+
}
16+
b /= 2;
17+
a *= a;
18+
a %= mod;
19+
}
20+
return res;
21+
}
22+
int inv(int n) { return binpow(n, mod - 2) % mod; }
23+
int fact[N];
24+
int nck(int n, int k) {
25+
return (fact[n] * inv((fact[k] * fact[n - k]) % mod) % mod) % mod;
26+
}
27+
28+
void solve() {
29+
int n, s, g;
30+
cin >> n >> s >> g;
31+
if (s % g != 0 || s / g < n) {
32+
cout << 0 << endl;
33+
return;
34+
}
35+
int t = s / g;
36+
37+
if (t % n != 0) {
38+
int x = t % n;
39+
cout << nck(n, x) << endl;
40+
return;
41+
}
42+
if (t / n == 1) {
43+
cout << 1 << endl;
44+
return;
45+
}
46+
if (n == 2 && ((t / n) & 1)) {
47+
cout << 2 << endl;
48+
return;
49+
}
50+
int res = 0;
51+
for (int n1 = 1; n1 <= (n - (t / n) % 2) / 2; n1++) {
52+
res +=
53+
fact[n] * inv((fact[n1] * fact[n1] % mod * fact[n - 2 * n1]) % mod);
54+
res %= mod;
55+
}
56+
cout << res << endl;
57+
}
58+
59+
/*
60+
6
61+
2 6 15
62+
1 15 5
63+
2 15 2
64+
2 16 2
65+
2 6 1
66+
1 15 6
67+
0
68+
0
69+
0
70+
2
71+
2
72+
0
73+
*/
74+
75+
signed main() {
76+
ios::sync_with_stdio(false);
77+
cin.tie(0);
78+
79+
fact[0] = 1;
80+
for (int i = 1; i < N; i++) {
81+
fact[i] = fact[i - 1] * i;
82+
fact[i] %= mod;
83+
}
84+
85+
int tt = 1;
86+
cin >> tt;
87+
while (tt--) {
88+
solve();
89+
}
90+
}
+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define all(x) x.begin(), x.end()
4+
typedef long long ll;
5+
6+
struct P {
7+
ll x, y;
8+
P operator+(P p) const { return P{x + p.x, y + p.y}; }
9+
P operator-(P p) const { return P{x - p.x, y - p.y}; }
10+
ll dot(P p) const { return x * p.x + y * p.y; }
11+
ll cross(P p) const { return x * p.y - y * p.x; }
12+
bool between(P a, P b, P c, P d, bool strict) {
13+
auto s1 = (d - c).cross(*this - c);
14+
auto s2 = (a - b).cross(*this - b);
15+
if (strict) return s1 && s2 && ((s1 < 0) ^ (s2 < 0));
16+
return (s1 == 0) || (s2 == 0) || ((s1 < 0) ^ (s2 < 0));
17+
}
18+
};
19+
20+
const ll mod = 1e9 + 7;
21+
22+
void solve() {
23+
int n;
24+
cin >> n;
25+
vector<P> p(n);
26+
vector<ll> keys;
27+
28+
auto key = [](P &p) {
29+
auto [x, y] = p;
30+
return (x + 1e6) + (y + 1e6) * mod;
31+
};
32+
33+
for (auto &i : p) {
34+
cin >> i.x >> i.y;
35+
keys.push_back(key(i));
36+
}
37+
38+
sort(all(p), [&](auto x, auto y) { return key(x) <= key(y); });
39+
sort(all(keys));
40+
41+
auto cnt = [&](int a, int b, int c, int d) {
42+
int ans = 0;
43+
for (int i = 0; i < n; i++) {
44+
if (i == a || i == b || i == c || i == d) continue;
45+
if (p[i].between(p[a], p[b], p[c], p[d], true)) {
46+
auto s1 = (p[i] - p[b]).cross(p[c] - p[b]);
47+
auto s2 = (p[d] - p[b]).cross(p[c] - p[b]);
48+
if (s1 && s2 && ((s1 < 0) ^ (s2 < 0))) {
49+
// cout << a << " " << b << " " << c << " " << d << " " << i <<
50+
// endl;
51+
ans++;
52+
}
53+
}
54+
}
55+
return ans;
56+
};
57+
58+
int res = 0;
59+
for (int k = 0; k < n; k++) {
60+
for (int i = k + 1; i < n; i++) {
61+
for (int j = i + 1; j < n; j++) {
62+
auto a = p[k], b = p[i], c = p[j];
63+
if ((a - b).dot(c - b) != 0 || (a - b).cross(c - b) == 0) continue;
64+
65+
/**
66+
* A ---------- D
67+
* | |
68+
* | |
69+
* B ---------- C
70+
*/
71+
72+
auto d = a + (c - b); // OD = OB + BD = OB + BA + BC = OA + BC
73+
assert((b - a).dot(d - a) == 0);
74+
auto it = lower_bound(all(keys), key(d));
75+
if (it == keys.end() || *it != key(d)) continue;
76+
int idx = it - keys.begin();
77+
78+
// cout << "(" << a.x << "," << a.y << ") (" << b.x << "," << b.y
79+
// << ") (" << c.x << "," << c.y << ") => (" << d.x << "," <<
80+
// d.y
81+
// << ")" << endl;
82+
// cout << k << " " << i << " " << j << " " << idx << endl;
83+
84+
res += cnt(k, i, j, idx);
85+
res += cnt(j, idx, k, i);
86+
}
87+
}
88+
}
89+
90+
cout << res << endl;
91+
}
92+
93+
signed main() {
94+
ios::sync_with_stdio(false);
95+
cin.tie(0);
96+
97+
int tt = 1;
98+
cin >> tt;
99+
while (tt--) {
100+
solve();
101+
}
102+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
#define int ll
5+
6+
void solve() {
7+
int z, o;
8+
cin >> z >> o;
9+
if (o & 1) {
10+
cout << "Second" << endl;
11+
} else
12+
cout << "First" << endl;
13+
}
14+
15+
signed main() {
16+
ios::sync_with_stdio(false);
17+
cin.tie(0);
18+
19+
int tt = 1;
20+
cin >> tt;
21+
while (tt--) {
22+
solve();
23+
}
24+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
void solve() {
5+
int n;
6+
cin >> n;
7+
if (n == 2022 || n == 2023) {
8+
cout << "Egypt" << endl;
9+
} else {
10+
cout << "Elsewhere" << endl;
11+
}
12+
}
13+
14+
int main() {
15+
int tt = 1;
16+
// cin >> tt ;
17+
while (tt--) {
18+
solve();
19+
}
20+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
void solve() {
6+
int n;
7+
cin >> n;
8+
vector<string> s;
9+
vector<vector<int>> v;
10+
11+
int maxi = 0;
12+
for (int i = 0; i < n; i++) {
13+
string cur;
14+
int val;
15+
cin >> cur >> val;
16+
if (!s.empty() && s.back() == cur) {
17+
v.back().push_back(val);
18+
maxi = max(maxi, (int)v.back().size());
19+
} else {
20+
s.push_back(cur);
21+
v.push_back({val});
22+
maxi = max(maxi, (int)v.back().size());
23+
}
24+
}
25+
26+
for (int i = 0; i < maxi; i++) {
27+
for (int j = 0; j < s.size(); j++)
28+
if (i < v[j].size()) cout << s[j] << " " << v[j][i] << "\n";
29+
}
30+
}
31+
32+
signed main() {
33+
ios::sync_with_stdio(false);
34+
cin.tie(0);
35+
int tt = 1;
36+
cin >> tt;
37+
while (tt--) {
38+
solve();
39+
}
40+
}
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
#define all(x) x.begin(), x.end()
5+
#define int ll
6+
7+
const int N = 1e6 + 1;
8+
9+
pair<int, int> good(int x) {
10+
int l = 0;
11+
int r = 1e6 + 100;
12+
int ans = 0;
13+
while (l <= r) {
14+
int m = (l + r) / 2;
15+
int sum = (m * (m + 1)) / 2;
16+
if (sum >= x) {
17+
r = m - 1;
18+
ans = m;
19+
} else {
20+
l = m + 1;
21+
}
22+
}
23+
return {(x - (ans * (ans - 1)) / 2), ans};
24+
}
25+
26+
void solve() {
27+
int n, k;
28+
cin >> n >> k;
29+
auto [nb, m] = good(k);
30+
vector<int> ans(n);
31+
for (int i = 0; i < n - m; i++) ans[i] = i + 1;
32+
for (int i = n - m, j = n; i < n; i++, j--) ans[i] = j;
33+
34+
// for (auto i : ans) cout << i << " ";
35+
// cout << endl;
36+
// cout << n - m - 1 << " " << k << endl ;
37+
38+
// if (n - m - 1 == -1) {
39+
// for (auto i : ans) cout << i << " ";
40+
// cout << endl;
41+
// return;
42+
// }
43+
44+
int idx = n - 1;
45+
while (idx >= 0 && nb--) {
46+
swap(ans[n - m - 1], ans[idx]);
47+
idx--;
48+
}
49+
50+
// // cout << idx << " " << k << endl;
51+
for (auto i : ans) cout << i << " ";
52+
cout << endl;
53+
}
54+
55+
signed main() {
56+
// freopen("a.txt", "w", stdout);
57+
ios::sync_with_stdio(false);
58+
cin.tie(0);
59+
60+
int tt = 1;
61+
cin >> tt;
62+
while (tt--) {
63+
solve();
64+
}
65+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
5+
void solve() {
6+
int n, m;
7+
cin >> n >> m;
8+
set<pair<int, int>> s;
9+
for (int i = 0; i < m; i++) {
10+
int x, y;
11+
cin >> x >> y;
12+
s.insert({x, y});
13+
}
14+
for (int i = 0; i < n - 1; i++) {
15+
if (s.count({i + 1, i + 2})) {
16+
cout << 0 << " ";
17+
} else {
18+
cout << 1 << " ";
19+
}
20+
}
21+
cout << 0;
22+
cout << endl;
23+
}
24+
25+
signed main() {
26+
ios::sync_with_stdio(false);
27+
cin.tie(0);
28+
int tt = 1;
29+
// cin >> tt;
30+
while (tt--) {
31+
solve();
32+
}
33+
}

0 commit comments

Comments
 (0)