Submission #236638

#TimeUsernameProblemLanguageResultExecution timeMemory
236638SortingICC (CEOI16_icc)C++14
100 / 100
150 ms760 KiB
#include <bits/stdc++.h> #include "icc.h" using namespace std; int query(int size_a, int size_b, int a[], int b[]); void setRoad(int a, int b); const int k_N = 100 + 3; vector<vector<int>> components; int log_table[k_N]; int query(const vector<int> &a_v, const vector<int> &b_v){ static int a[k_N], b[k_N]; for(int i = 0; i < a_v.size(); ++i) a[i] = a_v[i]; for(int i = 0; i < b_v.size(); ++i) b[i] = b_v[i]; return query(a_v.size(), b_v.size(), a, b); } void unite(int index_1, int index_2){ if(components[index_1].size() < components[index_2].size()) swap(index_1, index_2); for(int node: components[index_2]) components[index_1].push_back(node); swap(components[index_2], components.back()); components.pop_back(); } void run(int n){ components.clear(); components.resize(n); for(int i = 1; i <= n; ++i) components[i - 1].push_back(i); memset(log_table, 0, sizeof(log_table)); for(int i = 2; i < k_N; i *= 2) log_table[i]++; for(int i = 1; i < k_N; ++i) log_table[i] += log_table[i - 1]; for(int i = 0; i < n - 1; ++i){ int log_c = log_table[components.size() - 1]; int diff = 0; for(int bit = 0; bit <= log_c; ++bit){ vector<int> a, b; for(int j = 0; j < components.size(); ++j){ if(j & (1 << bit)){ for(int x: components[j]) a.push_back(x); } else{ for(int x: components[j]) b.push_back(x); } } if(query(a, b)) diff += (1 << bit); } vector<pair<int, int>> pairs; for(int i = 0; i < components.size(); ++i) if((i ^ diff) > i && (i ^ diff) < components.size()) pairs.push_back({i, (i ^ diff)}); int l = 0, r = pairs.size() - 1; while(l != r){ int mid = (l + r) >> 1; vector<int> a, b; for(int i = l; i <= mid; ++i){ for(int x: components[pairs[i].first]) a.push_back(x); for(int x: components[pairs[i].second]) b.push_back(x); } if(query(a, b)) r = mid; else l = mid + 1; } int c1 = pairs[l].first, c2 = pairs[l].second; l = 0, r = components[c1].size() - 1; while(l != r){ int mid = (l + r) >> 1; vector<int> a, b; for(int i = l; i <= mid; ++i) a.push_back(components[c1][i]); for(int x: components[c2]) b.push_back(x); if(query(a, b)) r = mid; else l = mid + 1; } int u = components[c1][l]; l = 0, r = components[c2].size() - 1; while(l != r){ int mid = (l + r) >> 1; vector<int> a, b; for(int i = l; i <= mid; ++i) a.push_back(components[c2][i]); for(int x: components[c1]) b.push_back(x); if(query(a, b)) r = mid; else l = mid + 1; } int v = components[c2][l]; setRoad(u, v); unite(c1, c2); } }

Compilation message (stderr)

icc.cpp: In function 'int query(const std::vector<int>&, const std::vector<int>&)':
icc.cpp:17:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < a_v.size(); ++i)
                    ~~^~~~~~~~~~~~
icc.cpp:19:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < b_v.size(); ++i)
                    ~~^~~~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:56:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j = 0; j < components.size(); ++j){
                            ~~^~~~~~~~~~~~~~~~~~~
icc.cpp:72:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < components.size(); ++i)
                        ~~^~~~~~~~~~~~~~~~~~~
icc.cpp:73:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if((i ^ diff) > i && (i ^ diff) < components.size())
                                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...