Submission #600515

# Submission time Handle Problem Language Result Execution time Memory
600515 2022-07-21T00:25:53 Z penguinhacker Sob (COCI19_sob) C++17
110 / 110
88 ms 9700 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> v(n);
	iota(v.begin(), v.end(), m);
	int offset=0;
	while(__builtin_popcount(n)>1) {
		int high=31-__builtin_clz(n);
		vector<ar<int, 2>> p;
		vector<bool> vis(1<<high);
		vector<int> mp(1<<high, -1);
		for (int i : v) {
			int mask=i&((1<<high+1)-1);
			if (mask<(1<<high)) {
				cout << mask+offset << " " << i << "\n";
				vis[mask]=1;
			} else
				mp[mask-(1<<high)]=i;
		}
		v.clear();
		for (int i=0; i<1<<high; ++i) {
			if (!vis[i]) {
				assert(mp[i]!=-1);
				cout << i+offset << " " << mp[i] << "\n";
			} else if (mp[i]!=-1)
				v.push_back(mp[i]);
		}
		n-=1<<high;
		offset+=1<<high;
	}
	for (int i : v)
		cout << (i&n-1)+offset << " " << i << "\n";
	return 0;
}

Compilation message

sob.cpp: In function 'int main()':
sob.cpp:21:24: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   21 |    int mask=i&((1<<high+1)-1);
      |                    ~~~~^~
sob.cpp:40:15: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   40 |   cout << (i&n-1)+offset << " " << i << "\n";
      |              ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 41 ms 4820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 41 ms 4836 KB Output is correct
7 Correct 21 ms 2512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 316 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 41 ms 4820 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 41 ms 4836 KB Output is correct
11 Correct 21 ms 2512 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 316 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 11 ms 1308 KB Output is correct
20 Correct 33 ms 4032 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 45 ms 6020 KB Output is correct
24 Correct 88 ms 9700 KB Output is correct
25 Correct 83 ms 9560 KB Output is correct