Submission #439324

#TimeUsernameProblemLanguageResultExecution timeMemory
439324SaraSob (COCI19_sob)C++14
110 / 110
333 ms11320 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define ll long long #define F first #define S second #define pb push_back #define md ((b + e) >> 1) #define lc (ind << 1) #define rc (lc | 1) const ll N = 1e6+ 10; const ll lg = 15; const ll oo = 1e9 + 10; const ll mod = 1e9 + 7; vector < pair <int, int> > solve(int n, int m){ vector < pair <int, int> > ret = {}; if (n <= 3){ vector <int> A = {}, B = {}; for (int i = 0; i < n; i ++){ A.pb(i); B.pb(m + i); } do { bool ok = 1; for (int i = 0; i < n; i ++){ ok &= ((A[i] & B[i]) == A[i]); } if (ok){ break; } } while (next_permutation(B.begin(), B.end())); for (int i = 0; i < n; i ++){ ret.pb({A[i], B[i]}); } return ret; } vector < pair <int, int> > o = {}, e = {}; if (n & 1){ if (m & 1){ o = solve((n - 2) / 2 + 1, (m + 2) / 2); e = solve((n - 1) / 2 + 1, m / 2); } else { o = solve((n - 2) / 2 + 1, (m + 1) / 2); e = solve((n - 1) / 2 + 1, m / 2); } } else { if (m & 1){ o = solve((n - 1) / 2 + 1, m / 2); e = solve((n - 2) / 2 + 1, (m + 1) / 2); } else { o = solve((n - 1) / 2 + 1, (m + 1) / 2); e = solve((n - 2) / 2 + 1, m / 2); } } for (auto it : o){ ret.pb({it.F * 2 + 1, it.S * 2 + 1}); } for (auto it : e){ ret.pb({it.F * 2, it.S * 2}); if (it.S == m / 2 && (n & 1) && (m & 1)){ ret.back().S ++; } } return ret; } int n, m; vector < pair <int, int> > ans; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; ans = solve(n, m); for (auto it : ans){ cout << it.F << ' ' << it.S << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...