# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
155273 |
2019-09-27T12:42:04 Z |
ryansee |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
3384 KB |
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }
#define ll long long int
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (100006)
ll n, m, A[MAXN];
vector<pi> v;
ll ans[MAXN];
void solve() {
FOR(i,1,m) {
ll n=v.size();
ll add = 0;
unordered_map<ll, ll> mp;
FOR(j,0,n-1) {
if(v[j].f == i || v[j].s == i) {
add += (v[j].f!=i);
add += (v[j].s != -1 && v[j].s!=i);
} else { ++ mp[v[j].f]; if(~v[j].s) ++ mp[v[j].s]; }
}
ll nochange=0, ppl=0;
for(auto i:mp) ppl+=i.s, nochange=max(nochange,i.s);
ans[i]=min(ans[i],add+ppl-nochange);
}
}
int main()
{
FAST
cin>>n>>m;
if(m==1) {
cout<<0; return 0;
}
FOR(i,1,n) cin>>A[i];
for(ll i=1;i<=n;i+=2) v.eb(A[i], (i+1>n?-1:A[i+1]));
fill(ans, ans+MAXN, LLINF);
solve();
v.clear();
v.eb(A[1], -1);
for(ll i=2;i<=n;i+=2) v.eb(A[i], (i+1>n?-1:A[i+1]));
solve();
for(ll i=1;i<=m;++i) cout<<ans[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
2 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
4 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1144 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
1148 KB |
Output is correct |
24 |
Correct |
3 ms |
1144 KB |
Output is correct |
25 |
Correct |
3 ms |
1144 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
2 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
4 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1144 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
1148 KB |
Output is correct |
24 |
Correct |
3 ms |
1144 KB |
Output is correct |
25 |
Correct |
3 ms |
1144 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
51 ms |
2800 KB |
Output is correct |
28 |
Correct |
24 ms |
2800 KB |
Output is correct |
29 |
Correct |
47 ms |
2800 KB |
Output is correct |
30 |
Correct |
29 ms |
2796 KB |
Output is correct |
31 |
Correct |
51 ms |
2792 KB |
Output is correct |
32 |
Correct |
24 ms |
2804 KB |
Output is correct |
33 |
Correct |
47 ms |
2800 KB |
Output is correct |
34 |
Correct |
29 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
2 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
4 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1144 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
1148 KB |
Output is correct |
24 |
Correct |
3 ms |
1144 KB |
Output is correct |
25 |
Correct |
3 ms |
1144 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
51 ms |
2800 KB |
Output is correct |
28 |
Correct |
24 ms |
2800 KB |
Output is correct |
29 |
Correct |
47 ms |
2800 KB |
Output is correct |
30 |
Correct |
29 ms |
2796 KB |
Output is correct |
31 |
Correct |
51 ms |
2792 KB |
Output is correct |
32 |
Correct |
24 ms |
2804 KB |
Output is correct |
33 |
Correct |
47 ms |
2800 KB |
Output is correct |
34 |
Correct |
29 ms |
2772 KB |
Output is correct |
35 |
Correct |
2390 ms |
2888 KB |
Output is correct |
36 |
Correct |
2401 ms |
3312 KB |
Output is correct |
37 |
Correct |
2302 ms |
3252 KB |
Output is correct |
38 |
Correct |
2321 ms |
3248 KB |
Output is correct |
39 |
Correct |
2400 ms |
3384 KB |
Output is correct |
40 |
Execution timed out |
2522 ms |
3308 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
2 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
4 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1144 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
1148 KB |
Output is correct |
24 |
Correct |
3 ms |
1144 KB |
Output is correct |
25 |
Correct |
3 ms |
1144 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
51 ms |
2800 KB |
Output is correct |
28 |
Correct |
24 ms |
2800 KB |
Output is correct |
29 |
Correct |
47 ms |
2800 KB |
Output is correct |
30 |
Correct |
29 ms |
2796 KB |
Output is correct |
31 |
Correct |
51 ms |
2792 KB |
Output is correct |
32 |
Correct |
24 ms |
2804 KB |
Output is correct |
33 |
Correct |
47 ms |
2800 KB |
Output is correct |
34 |
Correct |
29 ms |
2772 KB |
Output is correct |
35 |
Correct |
2390 ms |
2888 KB |
Output is correct |
36 |
Correct |
2401 ms |
3312 KB |
Output is correct |
37 |
Correct |
2302 ms |
3252 KB |
Output is correct |
38 |
Correct |
2321 ms |
3248 KB |
Output is correct |
39 |
Correct |
2400 ms |
3384 KB |
Output is correct |
40 |
Execution timed out |
2522 ms |
3308 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1144 KB |
Output is correct |
6 |
Correct |
3 ms |
1144 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
2 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1144 KB |
Output is correct |
13 |
Correct |
4 ms |
1144 KB |
Output is correct |
14 |
Correct |
3 ms |
1144 KB |
Output is correct |
15 |
Correct |
3 ms |
1144 KB |
Output is correct |
16 |
Correct |
3 ms |
1144 KB |
Output is correct |
17 |
Correct |
3 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1144 KB |
Output is correct |
19 |
Correct |
3 ms |
1144 KB |
Output is correct |
20 |
Correct |
3 ms |
1272 KB |
Output is correct |
21 |
Correct |
3 ms |
1144 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
1148 KB |
Output is correct |
24 |
Correct |
3 ms |
1144 KB |
Output is correct |
25 |
Correct |
3 ms |
1144 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
51 ms |
2800 KB |
Output is correct |
28 |
Correct |
24 ms |
2800 KB |
Output is correct |
29 |
Correct |
47 ms |
2800 KB |
Output is correct |
30 |
Correct |
29 ms |
2796 KB |
Output is correct |
31 |
Correct |
51 ms |
2792 KB |
Output is correct |
32 |
Correct |
24 ms |
2804 KB |
Output is correct |
33 |
Correct |
47 ms |
2800 KB |
Output is correct |
34 |
Correct |
29 ms |
2772 KB |
Output is correct |
35 |
Correct |
2390 ms |
2888 KB |
Output is correct |
36 |
Correct |
2401 ms |
3312 KB |
Output is correct |
37 |
Correct |
2302 ms |
3252 KB |
Output is correct |
38 |
Correct |
2321 ms |
3248 KB |
Output is correct |
39 |
Correct |
2400 ms |
3384 KB |
Output is correct |
40 |
Execution timed out |
2522 ms |
3308 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |