제출 #290958

#제출 시각아이디문제언어결과실행 시간메모리
290958Plurm"The Lyuboyn" code (IZhO19_lyuboyn)C++11
100 / 100
312 ms35192 KiB
#include <bits/stdc++.h>
using namespace std;
int lsb[300005];
int rmp[300005];
int seq[300005];
set<string> s;
int main(){
	int n,k,t;
	scanf("%d%d%d",&n,&k,&t);
	if(k % 2 == 0 || k >= n){
		printf("-1\n");
		return 0;
	}
	for(int i = 0; i <= 18; i++) rmp[1 << i] = i;
	for(int i = 0; i < (1 << n); i += 2){
		int lsb1 = rmp[i+1 & -(i+1)];
		int lsb2 = rmp[i+2 & -(i+2)];
		int c = 1;
		for(int j = 0; j < n; j++){
			if(j != lsb1 && j != lsb2 && c < k){
				c++;
				seq[i] |= 1 << j;
			}
		}
		seq[i+1] = seq[i];
	}
	printf("%d\n", 1 << n);
	char bs[32];
	scanf("%s",bs);
	if(strlen(bs) != n) while(true);
	int parsed = 0;
	for(int i = 0; i < n; i++){
		parsed *= 2;
		parsed += bs[i] == '1' ? 1 : 0;
	}
	printf("%s\n",bs);
	s.insert(bs);
	for(int i = 1; i < (1 << n); i++){
		int bit = rmp[i & -i];
		int toggidx = bit;
		toggidx = n-toggidx-1;
		bs[toggidx] = '0'+'1'-bs[toggidx];
		for(int j = 0; j < n; j++){
			if(seq[i-1] & (1 << j)) bs[n-j-1] = '0'+'1'-bs[n-j-1];
		}
		if(s.count(bs)) while(true);
		s.insert(bs);
		printf("%s\n",bs);
	}
	return 0;
}

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

lyuboyn.cpp: In function 'int main()':
lyuboyn.cpp:16:19: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   16 |   int lsb1 = rmp[i+1 & -(i+1)];
      |                  ~^~
lyuboyn.cpp:17:19: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   17 |   int lsb2 = rmp[i+2 & -(i+2)];
      |                  ~^~
lyuboyn.cpp:30:16: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |  if(strlen(bs) != n) while(true);
      |     ~~~~~~~~~~~^~~~
lyuboyn.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |  scanf("%d%d%d",&n,&k,&t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
lyuboyn.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%s",bs);
      |  ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...