Submission #229225

#TimeUsernameProblemLanguageResultExecution timeMemory
229225VEGAnnSob (COCI19_sob)C++14
110 / 110
600 ms11768 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) using namespace std; const int N = 1000100; int kol = 0, n, m, nm[N], ans[N], val; bool mrk[N]; bool cmp(int x, int y){ return (val & x) < (val & y); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("in.txt","r",stdin); cin >> n >> m; kol = 0; while ((1 << kol) < n) kol++; for (int it = 0; it < n; it++) nm[it] = m + it; int mem = n, id = 0; val = (1 << kol) - 1; sort(nm, nm + n, cmp); while (id < n) { for (int i = (nm[id] & val); ; i = ((i - 1) & (nm[id] & val))){ if (mrk[i] || i >= n) continue; mrk[i] = 1; ans[i] = nm[id]; id++; break; } } for (int i = n - 1; i >= 0; i--) { assert((ans[i] & i) == i); cout << i << " " << ans[i] << '\n'; } return 0; }

Compilation message (stderr)

sob.cpp: In function 'int main()':
sob.cpp:27:9: warning: unused variable 'mem' [-Wunused-variable]
     int mem = n, id = 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...