Submission #155296

#TimeUsernameProblemLanguageResultExecution timeMemory
155296ryanseeRope (JOI17_rope)C++14
100 / 100
1524 ms76172 KiB
#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 INF// ((long long) 1e18)//1234567890987654321 #define INF 1234567890ll // #define cerr if(0)cout #define MAXN (1000006) ll n, m, A[MAXN]; ll N; vector<pi> v; ll ans[MAXN]; vector<ll> cnt; vector<ll> o; void solve() { ll n=v.size(); vector<vector<ll>> adj(m+1, vector<ll>()); FOR(i,0,n-1) if(v[i].s!=-1 && v[i].f^v[i].s) { adj[v[i].f].eb(v[i].s); adj[v[i].s].eb(v[i].f); } FOR(i,1,m) { // ll n=v.size(); ll add = 0; ll mx = 0; for(auto j:adj[i]) --cnt[j]; for(ll j=0;j<siz(o)&&j<=siz(adj[i])+1; ++ j) if(o[j] ^ i) { mx=max(mx, cnt[o[j]]); } add = N-cnt[i]-mx; ans[i]=min(ans[i], add); for(auto j:adj[i]) ++ cnt[j]; } } #define gc getchar_unlocked void in(ll &x) { x=0; char ch=gc(); while(ch<'0'||ch>'9') ch=gc(); while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-48; ch=gc(); } } int main() { FAST in(n),in(m);N=n; if(m==1) { cout<<0; return 0; } FOR(i,1,n) in(A[i]); cnt.resize(m+1, 0); for(ll i=1;i<=n;++i) cnt[A[i]] ++; FOR(i,1,m) o.eb(i); sort(all(o), [](ll x,ll y){return cnt[x]>cnt[y];}); 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'; }

Compilation message (stderr)

rope.cpp: In function 'int main()':
rope.cpp:24:25: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
 #define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
                         ^
rope.cpp:73:2: note: in expansion of macro 'FOR'
  FOR(i,1,n) in(A[i]); cnt.resize(m+1, 0); for(ll i=1;i<=n;++i) cnt[A[i]] ++; FOR(i,1,m) o.eb(i); sort(all(o), [](ll x,ll y){return cnt[x]>cnt[y];});
  ^~~
rope.cpp:73:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  FOR(i,1,n) in(A[i]); cnt.resize(m+1, 0); for(ll i=1;i<=n;++i) cnt[A[i]] ++; FOR(i,1,m) o.eb(i); sort(all(o), [](ll x,ll y){return cnt[x]>cnt[y];});
                       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...