Skip to content

Commit bb7e631

Browse files
committed
add AtCoder
1 parent 33e14fb commit bb7e631

File tree

8 files changed

+234
-0
lines changed

8 files changed

+234
-0
lines changed

AtCoder/abc139/.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"ostream": "cpp"
4+
}
5+
}

AtCoder/abc139/A - Tenki.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
string s;
4+
string t;
5+
int main()
6+
{
7+
cin >> t;
8+
cin >> s;
9+
int cnt = 0;
10+
for (int i = 0; i < t.size(); i++)
11+
{
12+
if (s[i] == t[i])
13+
{
14+
cnt++;
15+
}
16+
}
17+
cout << cnt << endl;
18+
return 0;
19+
}

AtCoder/abc139/B - Power Socket.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int a, b;
8+
cin >> a >> b;
9+
if (b <= 1)
10+
{
11+
cout << 0 << endl;
12+
exit(0);
13+
}
14+
int now = 1;
15+
int ans = 0;
16+
while (now < b)
17+
{
18+
ans += 1;
19+
now -= 1;
20+
now += a;
21+
}
22+
cout << ans << endl;
23+
return 0;
24+
}

AtCoder/abc139/C - Lower.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n;
7+
cin >> n;
8+
int v;
9+
cin >> v;
10+
int tmp = v;
11+
int ans = 0, cnt = 0;
12+
for (int i = 1; i < n; i++)
13+
{
14+
cin >> v;
15+
if (v <= tmp)
16+
{
17+
cnt += 1;
18+
tmp = v;
19+
}
20+
else
21+
{
22+
cnt = 0;
23+
tmp = v;
24+
}
25+
ans = max(ans, cnt);
26+
}
27+
cout << ans << endl;
28+
return 0;
29+
}

AtCoder/abc139/D - ModSum.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#include <bits/stdc++.h>
3+
4+
using namespace std;
5+
6+
// {1, 2, 3} => {3, 1, 2} => 3
7+
// {1, 2, 3 4 } => {4, 1, 2, 3} => 6
8+
int main()
9+
{
10+
long long n;
11+
cin >> n;
12+
cout << n * (n - 1) / 2 << endl;
13+
return 0;
14+
}

AtCoder/abc139/E - League.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+
3+
using namespace std;
4+
5+
const int maxn = 1234;
6+
vector<int> edge[maxn * maxn], tmp[maxn * maxn];
7+
8+
/*
9+
2 -> 3 <- 1
10+
^ |
11+
| |
12+
_ _ _ _ _
13+
14+
2 -> 3 1
15+
^ |
16+
| |
17+
_ _ _ _ _
18+
19+
topoSort to check cycle + longest path on the path, O(n^2)
20+
*/
21+
int color[maxn * maxn];
22+
int dp[maxn * maxn];
23+
24+
bool dfs1(int u)
25+
{
26+
if (color[u] == 2)
27+
return true;
28+
color[u] = 1; // visited
29+
for (auto v : edge[u])
30+
{
31+
if (color[v] > 0)
32+
{
33+
if (color[v] == 1)
34+
return false; // cycle
35+
}
36+
if (!dfs1(v))
37+
{
38+
return false;
39+
}
40+
}
41+
color[u] = 2;
42+
return true;
43+
}
44+
45+
int dfs2(int u)
46+
{
47+
if (dp[u])
48+
{
49+
return dp[u];
50+
}
51+
int cnt = 0;
52+
for (auto v : edge[u])
53+
{
54+
cnt = max(cnt, dfs2(v));
55+
}
56+
dp[u] = cnt + 1;
57+
return dp[u];
58+
}
59+
int main()
60+
{
61+
int n;
62+
cin >> n;
63+
for (int i = 1; i <= n; i++)
64+
{
65+
for (int j = 0; j < n - 1; j++)
66+
{
67+
int a;
68+
cin >> a;
69+
tmp[i].push_back(a);
70+
}
71+
}
72+
for (int i = 1; i <= n; i++)
73+
{
74+
for (int j = 1; j < n - 1; j++)
75+
{
76+
int r1 = i, c1 = tmp[i][j - 1];
77+
int r2 = i, c2 = tmp[i][j];
78+
if (r1 > c1)
79+
swap(r1, c1);
80+
if (r2 > c2)
81+
swap(r2, c2);
82+
int s = r1 * n + c1;
83+
int t = r2 * n + c2;
84+
edge[s].push_back(t);
85+
}
86+
}
87+
for (int i = 0; i < n * n; i++)
88+
{
89+
if (color[i] == 0 && !dfs1(i))
90+
{
91+
cout << "-1" << endl;
92+
exit(0);
93+
}
94+
}
95+
int ans = 0;
96+
for (int i = 0; i < n * n; i++)
97+
{
98+
ans = max(ans, dfs2(i));
99+
}
100+
cout << ans << endl;
101+
return 0;
102+
}

AtCoder/abc139/F - Engines.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
const int maxn = 1e4;
6+
struct node
7+
{
8+
int x, y;
9+
} point[maxn];
10+
11+
bool cmp(node a, node b)
12+
{
13+
return atan2(a.x, a.y) < atan2(b.x, b.y);
14+
}
15+
int main()
16+
{
17+
int n;
18+
cin >> n;
19+
for (int i = 0; i < n; i++)
20+
{
21+
cin >> point[i].x >> point[i].y;
22+
}
23+
long long ans = 0;
24+
int tx, ty;
25+
sort(point, point + n, cmp);
26+
for (int i = 0; i < n; i++)
27+
{
28+
tx = point[i].x;
29+
ty = point[i].y;
30+
ans = max(ans, 1LL * tx * tx + 1LL * ty * ty);
31+
for (int j = (i + 1) % n; j != i; j = (j + 1) % n)
32+
{
33+
tx += point[j].x;
34+
ty += point[j].y;
35+
ans = max(ans, 1LL * tx * tx + 1LL * ty * ty);
36+
}
37+
}
38+
double res = sqrt(ans);
39+
printf("%.13f\n", res);
40+
return 0;
41+
}

AtCoder/abc139/main

13.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)