Submission #603129

#TimeUsernameProblemLanguageResultExecution timeMemory
603129definitelynotmeeSplit the Attractions (IOI19_split)C++17
40 / 100
173 ms42620 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using matrix = vector<vector<T>>; #define ff first #define ss second #define all(x) x.begin(), x.end() vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { matrix<int> g(n), tree(n); for(int i = 0; i < p.size(); i++) g[p[i]].push_back(q[i]), g[q[i]].push_back(p[i]); vector<int> sub(n), low(n); matrix<int> indep(n), dep(n); vector<int> pai(n); int cen = 0; vector<int> tin(n); int timer = -1; auto dfs =[&](int id, auto dfs)->void{ sub[id] = 1; tin[id] = ++timer; low[id] = tin[id]; int maxi = 0; for(int i : g[id]){ if(sub[i]){ low[id] = min(low[id],tin[i]); continue; } tree[id].push_back(i); tree[i].push_back(id); pai[i] = id; indep[i].push_back(id); dfs(i,dfs); int cur = sub[i]; maxi = max(maxi,cur); sub[id] += cur; if(low[i] < tin[id]) indep[id].push_back(i); else dep[id].push_back(i); low[id] = min(low[id],low[i]); } maxi = max(maxi,n-sub[id]); if(maxi <= n/2) cen = id; }; dfs(0,dfs); sub[pai[cen]] = n-sub[pai[cen]]; vector<int> v = {a,b,c}; vector<int> o = {0,1,2}; sort(all(o),[&](int a, int b){ return v[a] < v[b]; }); vector<int> sz = {v[o[0]],v[o[1]], v[o[2]]}; array<vector<int>,3> group; vector<int> resp(n,2); auto filltree =[&](int id, int last, int color, auto dfs)->void{ group[color].push_back(id); resp[id] = color; for(int i : tree[id]){ if(i == last) continue; if(group[color].size() < sz[color]) dfs(i,id,color,dfs); } }; auto fillgraph =[&](int id, int color, auto dfs)->void{ group[color].push_back(id); resp[id] = color; for(int i : g[id]){ if(resp[i] != 2) continue; if(group[color].size() < sz[color]) dfs(i,color,dfs); } }; auto buildresp =[&](){ for(int& i : resp) i = o[i]+1; }; for(int i : tree[cen]){ if(sub[i] >= sz[0]){ filltree(i,cen,0,filltree); fillgraph(cen,1,fillgraph); buildresp(); assert(group[0].size() == sz[0] && group[1].size() == sz[1]); return resp; } } int depsize = 1; for(int i : dep[cen]) depsize+=sub[i]; if(depsize >= sz[1]){ if(n-depsize >= sz[0]){ group[1].push_back(cen); resp[cen] = 1; for(int i : dep[cen]){ if(group[1].size() < sz[1]) filltree(i,cen,1,filltree); } fillgraph(indep[cen].back(),0,fillgraph); buildresp(); assert(group[0].size() == sz[0] && group[1].size() == sz[1]); } else resp = vector<int>(n); return resp; } group[0].push_back(cen); resp[cen] = 0; for(int i : dep[cen]){ if(group[0].size() < sz[0]) filltree(i,cen,0,filltree); } while(group[0].size() < sz[0]){ filltree(indep[cen].back(),cen,0,filltree); } fillgraph(indep[cen].back(),1,fillgraph); buildresp(); assert(group[0].size() == sz[0] && group[1].size() == sz[1]); return resp; }

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i < p.size(); i++)
      |                    ~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from split.cpp:2:
split.cpp:99:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   99 |             assert(group[0].size() == sz[0] && group[1].size() == sz[1]);
split.cpp:99:64: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   99 |             assert(group[0].size() == sz[0] && group[1].size() == sz[1]);
split.cpp:112:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
  112 |                 if(group[1].size() < sz[1])
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from split.cpp:2:
split.cpp:117:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
  117 |             assert(group[0].size() == sz[0] && group[1].size() == sz[1]);
split.cpp:117:64: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
  117 |             assert(group[0].size() == sz[0] && group[1].size() == sz[1]);
split.cpp:124:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
  124 |         if(group[0].size() < sz[0])
split.cpp:127:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
  127 |     while(group[0].size() < sz[0]){
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from split.cpp:2:
split.cpp:132:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
  132 |     assert(group[0].size() == sz[0] && group[1].size() == sz[1]);
split.cpp:132:56: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
  132 |     assert(group[0].size() == sz[0] && group[1].size() == sz[1]);
split.cpp: In instantiation of 'find_split(int, int, int, int, std::vector<int>, std::vector<int>)::<lambda(int, int, int, auto:24)> [with auto:24 = find_split(int, int, int, int, std::vector<int>, std::vector<int>)::<lambda(int, int, int, auto:24)>]':
split.cpp:96:38:   required from here
split.cpp:73:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   73 |             if(group[color].size() < sz[color])
split.cpp: In instantiation of 'find_split(int, int, int, int, std::vector<int>, std::vector<int>)::<lambda(int, int, auto:25)> [with auto:25 = find_split(int, int, int, int, std::vector<int>, std::vector<int>)::<lambda(int, int, auto:25)>]':
split.cpp:97:38:   required from here
split.cpp:84:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   84 |             if(group[color].size() < sz[color])
#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...