제출 #600515

#제출 시각아이디문제언어결과실행 시간메모리
600515penguinhackerSob (COCI19_sob)C++17
110 / 110
88 ms9700 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...