# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1051795 |
2024-08-10T09:49:16 Z |
SamAnd |
Rope (JOI17_rope) |
C++17 |
|
2500 ms |
6836 KB |
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1000006;
int n, m;
int c[N];
pair<int, int> a[N];
int ans[N];
void solvv()
{
for (int x = 1; x <= m; ++x)
{
for (int y = 1; y <= m; ++y)
{
int yans = 0;
for (int j = 1; j <= n; ++j)
{
if (a[j].fi == x || a[j].se == x)
{
if (a[j].fi && a[j].fi != x)
++yans;
if (a[j].se && a[j].se != x)
++yans;
continue;
}
if (a[j].fi && a[j].fi != y)
++yans;
if (a[j].se && a[j].se != y)
++yans;
}
ans[x] = min(ans[x], yans);
}
}
}
void solv()
{
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> c[i];
for (int i = 1; i <= m; ++i)
ans[i] = n;
if (n % 2 == 0)
{
for (int i = 1; i <= n; i += 2)
{
a[i / 2 + 1] = m_p(c[i], c[i + 1]);
}
n = n / 2;
solvv();
n *= 2;
a[1] = m_p(c[1], 0);
a[2] = m_p(c[n], 0);
for (int i = 2; i < n; i += 2)
{
a[i / 2 + 2] = m_p(c[i], c[i + 1]);
}
n = 2 + (n - 2) / 2;
solvv();
}
else
{
a[1] = m_p(c[1], 0);
for (int i = 2; i <= n; i += 2)
a[i / 2 + 1] = m_p(c[i], c[i + 1]);
n = (n - 1) / 2 + 1;
solvv();
n = (n - 1) * 2 + 1;
a[1] = m_p(c[n], 0);
for (int i = 1; i < n; i += 2)
a[i / 2 + 2] = m_p(c[i], c[i + 1]);
solvv();
}
for (int i = 1; i <= m; ++i)
cout << ans[i] << "\n";
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // SOMETHING
ios_base::sync_with_stdio(false), cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solv();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4572 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4568 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4700 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4572 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4568 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4700 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
25 ms |
6836 KB |
Output is correct |
28 |
Correct |
13 ms |
6816 KB |
Output is correct |
29 |
Correct |
25 ms |
6748 KB |
Output is correct |
30 |
Correct |
13 ms |
6744 KB |
Output is correct |
31 |
Correct |
23 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6824 KB |
Output is correct |
33 |
Correct |
25 ms |
6828 KB |
Output is correct |
34 |
Correct |
13 ms |
6736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4572 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4568 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4700 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
25 ms |
6836 KB |
Output is correct |
28 |
Correct |
13 ms |
6816 KB |
Output is correct |
29 |
Correct |
25 ms |
6748 KB |
Output is correct |
30 |
Correct |
13 ms |
6744 KB |
Output is correct |
31 |
Correct |
23 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6824 KB |
Output is correct |
33 |
Correct |
25 ms |
6828 KB |
Output is correct |
34 |
Correct |
13 ms |
6736 KB |
Output is correct |
35 |
Execution timed out |
2572 ms |
6748 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4572 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4568 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4700 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
25 ms |
6836 KB |
Output is correct |
28 |
Correct |
13 ms |
6816 KB |
Output is correct |
29 |
Correct |
25 ms |
6748 KB |
Output is correct |
30 |
Correct |
13 ms |
6744 KB |
Output is correct |
31 |
Correct |
23 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6824 KB |
Output is correct |
33 |
Correct |
25 ms |
6828 KB |
Output is correct |
34 |
Correct |
13 ms |
6736 KB |
Output is correct |
35 |
Execution timed out |
2572 ms |
6748 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4572 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4568 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
0 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4700 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
25 ms |
6836 KB |
Output is correct |
28 |
Correct |
13 ms |
6816 KB |
Output is correct |
29 |
Correct |
25 ms |
6748 KB |
Output is correct |
30 |
Correct |
13 ms |
6744 KB |
Output is correct |
31 |
Correct |
23 ms |
6748 KB |
Output is correct |
32 |
Correct |
9 ms |
6824 KB |
Output is correct |
33 |
Correct |
25 ms |
6828 KB |
Output is correct |
34 |
Correct |
13 ms |
6736 KB |
Output is correct |
35 |
Execution timed out |
2572 ms |
6748 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |