# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
534492 |
2022-03-08T08:01:58 Z |
rk42745417 |
Rope (JOI17_rope) |
C++17 |
|
1 ms |
316 KB |
/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
cerr << "\e[1;33m" << s << " = [";
while(l != r) {
cerr << *l;
cerr << (++l == r ? ']' : ',');
}
cerr << "\e[0m\n";
}
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9+7;
static int Lamy_is_cute = []() {
EmiliaMyWife
return 48763;
}();
/*--------------------------------------------------------------------------------------*/
signed main() {
int n, m;
cin >> n >> m;
vector<int> arr(n);
for(int &a : arr)
cin >> a;
vector<int> ans(m + 1, INF);
for(int st : {1, 2}) {
vector<int> cost(m + 1);
vector<map<int, int>> adj(m + 1);
for(int i = st; i < n; i += 2) {
int a = arr[i - 1], b = arr[i];
if(a == b)
cost[a] += 2;
else {
adj[a][b]++;
adj[b][a]++;
cost[a]++;
cost[b]++;
}
}
if(st == 2)
cost[arr[0]]++;
if((st == 2) ^ (n % 2))
cost[arr.back()]++;
int mx = 0, smx = 0;
for(int i = 1; i <= m; i++) {
if(cost[i] > mx)
swap(mx, smx), mx = cost[i];
else
smx = max(smx, cost[i]);
}
for(int i = 1; i <= m; i++) {
int res = 0;
if(cost[i] == mx)
res = smx;
else
res = mx;
for(const auto &[a, c] : adj[i])
res = max(res, cost[a] - c);
ans[i] = min(ans[i], n - (res + cost[i]));
}
}
for(int i = 1; i <= m; i++)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |