Submission #1062640

#TimeUsernameProblemLanguageResultExecution timeMemory
1062640thieunguyenhuyAirline Route Map (JOI18_airline)C++17
100 / 100
490 ms29440 KiB
#ifndef hwe #include "Alicelib.h" #endif #include <bits/stdc++.h> using namespace std; #define popcount(n) (__builtin_popcountll((n))) #define clz(n) (__builtin_clzll((n))) #define ctz(n) (__builtin_ctzll((n))) #define lg(n) (63 - __builtin_clzll((n))) #define BIT(n, i) (((n) >> (i)) & 1ll) #define MASK(i) (1ll << (i)) #define FLIP(n, i) ((n) ^ (1ll << (i))) #define ON(n, i) ((n) | MASK(i)) #define OFF(n, i) ((n) & ~MASK(i)) #define Int __int128 #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long long, int> pli; typedef pair<int, long long> pil; typedef vector<pair<int, int>> vii; typedef vector<pair<long long, long long>> vll; typedef vector<pair<long long, int>> vli; typedef vector<pair<int, long long>> vil; template <class T1, class T2> bool maximize(T1 &x, T2 y) { if (x < y) { x = y; return true; } return false; } template <class T1, class T2> bool minimize(T1 &x, T2 y) { if (x > y) { x = y; return true; } return false; } template <class T> void remove_duplicate(vector<T> &ve) { sort (ve.begin(), ve.end()); ve.resize(unique(ve.begin(), ve.end()) - ve.begin()); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template <class T> T random(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <class T> T random(T r) { return rng() % r; } const int N = 1e6 + 5; const int MOD = 1e9 + 7; const int inf = 1e9; const ll INF = 1e18; int sz = 0; int c[N], d[N]; #ifdef hwe void InitG(int v, int u) { cerr << "Init G: " << v << ' ' << u << '\n'; } void MakeG(int pos, int C, int D) { cerr << "Make G: " << pos << ' ' << C << ' ' << D << '\n'; maximize(sz, pos); c[pos] = C, d[pos] = D; } #endif void Alice(int n, int m, int a[], int b[]) { vii edges; for (int i = 0; i < m; ++i) edges.emplace_back(a[i], b[i]); // edge (bit node i, j) when BIT(j, i) == 0 for (int i = 0; i < 10; ++i) for (int j = 0; j < n; ++j) { if (!BIT(j, i)) edges.emplace_back(n + i, j); } // connect all bit-nodes for (int i = n; i + 1 < n + 10; ++i) edges.emplace_back(i, i + 1); // create two unique nodes for (int i = 0; i < n; ++i) edges.emplace_back(n + 10, i); edges.emplace_back(n + 10, n + 11); InitG(n + 12, edges.size()); for (int i = 0; i < edges.size(); ++i) MakeG(i, edges[i].fi, edges[i].se); } #ifdef hwe signed main() { int n, m; cin >> n >> m; int a[m], b[m]; for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i]; } Alice(n, m, a, b); for (int i = 0; i <= sz; ++i) cerr << c[i] << ' '; cerr << '\n'; for (int i = 0; i <= sz; ++i) cerr << d[i] << ' '; cerr << '\n'; cerr << '\n'; return 0; } #endif
#ifndef hwe #include "Boblib.h" #endif #include <bits/stdc++.h> using namespace std; #define popcount(n) (__builtin_popcountll((n))) #define clz(n) (__builtin_clzll((n))) #define ctz(n) (__builtin_ctzll((n))) #define lg(n) (63 - __builtin_clzll((n))) #define BIT(n, i) (((n) >> (i)) & 1ll) #define MASK(i) (1ll << (i)) #define FLIP(n, i) ((n) ^ (1ll << (i))) #define ON(n, i) ((n) | MASK(i)) #define OFF(n, i) ((n) & ~MASK(i)) #define Int __int128 #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long long, int> pli; typedef pair<int, long long> pil; typedef vector<pair<int, int>> vii; typedef vector<pair<long long, long long>> vll; typedef vector<pair<long long, int>> vli; typedef vector<pair<int, long long>> vil; template <class T1, class T2> bool maximize(T1 &x, T2 y) { if (x < y) { x = y; return true; } return false; } template <class T1, class T2> bool minimize(T1 &x, T2 y) { if (x > y) { x = y; return true; } return false; } template <class T> void remove_duplicate(vector<T> &ve) { sort (ve.begin(), ve.end()); ve.resize(unique(ve.begin(), ve.end()) - ve.begin()); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template <class T> T random(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <class T> T random(T r) { return rng() % r; } const int N = 1100 + 5; const int MOD = 1e9 + 7; const int inf = 1e9; const ll INF = 1e18; int cnt[N], ans[N]; vector<int> adj[N]; bitset<N> mark, in_chain; #ifdef hwe void InitMap(int n, int m) { cerr << "Init map: " << n << ' ' << m << '\n'; } void MakeMap(int a, int b) { cerr << "Make map: " << a << ' ' << b << '\n'; } #endif void Bob(int v, int u, int C[], int D[]) { int n = v - 12; for (int i = 0; i < v; ++i) { adj[i].clear(); ans[i] = MASK(10) - 1; mark[i] = in_chain[i] = false; } for (int i = 0; i < u; ++i) { adj[C[i]].emplace_back(D[i]); adj[D[i]].emplace_back(C[i]); } cerr << "hehe\n"; int only_with_one = -1; for (int i = 0; i < v; ++i) { if (adj[i].size() == 1) { assert(only_with_one == -1); only_with_one = i; } } int connect_with_all_non = adj[only_with_one].back(); cerr << "Done all non " << connect_with_all_non << '\n'; mark[connect_with_all_non] = true; for (auto &x : adj[connect_with_all_non]) mark[x] = true; vector<int> bitnodes; for (int i = 0; i < v; ++i) if (!mark[i]) { bitnodes.emplace_back(i); } cerr << "Bitnodes: "; for (auto &x : bitnodes) cerr << x << ' '; cerr << '\n'; for (int i = 0; i < 10; ++i) for (int j = 0; j < n; ++j) { if (!BIT(j, i)) ++cnt[i]; } int start = -1; for (auto node : bitnodes) { int counter = 0; for (auto x : adj[node]) if (!mark[x]) ++counter; if (counter == 1) { start = node; break; } } cerr << "Done start\n"; vector<int> chain = {start}; int cur = start; in_chain[start] = true; for (int _ = 0; _ < 11; ++_) { for (auto x : adj[cur]) if (!mark[x] && !in_chain[x]) { chain.emplace_back(x), in_chain[x] = true; cur = x; break; } } for (auto &x : chain) cerr << x << ' '; cerr << '\n'; auto valid_chain = [&](vector<int> chain) { for (int i = 1; i + 1 < chain.size(); ++i) if (adj[chain[i]].size() - 2 != cnt[i]) return false; return adj[chain[0]].size() - 1 == cnt[0] && adj[chain.back()].size() - 1 == cnt[chain.size() - 1]; }; if (!valid_chain(chain)) reverse(chain.begin(), chain.end()); assert(valid_chain(chain)); cerr << "Done chain\n"; for (int i = 0; i < chain.size(); ++i) { for (auto &x : adj[chain[i]]) if (mark[x]) { ans[x] = OFF(ans[x], i); } } vii edges; mark[only_with_one] = mark[connect_with_all_non] = false; for (int i = 0; i < u; ++i) { if (!mark[C[i]] || !mark[D[i]]) continue; edges.emplace_back(ans[C[i]], ans[D[i]]); } InitMap(n, edges.size()); for (auto it : edges) MakeMap(it.fi, it.se); } #ifdef hwe signed main() { int v, u; cin >> v >> u; int C[u], D[u]; for (int i = 0; i < u; ++i) { cin >> C[i]; } for (int i = 0; i < u; ++i) { cin >> D[i]; } Bob(v, u, C, D); cerr << '\n'; return 0; } #endif

Compilation message (stderr)

Alice.cpp: In function 'void Alice(int, int, int*, int*)':
Alice.cpp:103:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |  for (int i = 0; i < edges.size(); ++i) MakeG(i, edges[i].fi, edges[i].se);
      |                  ~~^~~~~~~~~~~~~~

Bob.cpp: In lambda function:
Bob.cpp:150:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |   for (int i = 1; i + 1 < chain.size(); ++i)
      |                   ~~~~~~^~~~~~~~~~~~~~
Bob.cpp:151:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  151 |    if (adj[chain[i]].size() - 2 != cnt[i]) return false;
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
Bob.cpp:152:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  152 |   return adj[chain[0]].size() - 1 == cnt[0] && adj[chain.back()].size() - 1 == cnt[chain.size() - 1];
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
Bob.cpp:152:77: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  152 |   return adj[chain[0]].size() - 1 == cnt[0] && adj[chain.back()].size() - 1 == cnt[chain.size() - 1];
      |                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Bob.cpp: In function 'void Bob(int, int, int*, int*)':
Bob.cpp:161:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  161 |  for (int i = 0; i < chain.size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...