Submission #420685

# Submission time Handle Problem Language Result Execution time Memory
420685 2021-06-08T13:18:33 Z Pyqe MalnaRISC (COI21_malnarisc) C++14
100 / 100
1 ms 292 KB
#include <bits/stdc++.h>

using namespace std;

long long n,nn;
bool bad;

void ad(long long x,long long w)
{
	if(x+(1ll<<w)<n)
	{
		if(bad)
		{
			printf(" ");
		}
		printf("CMPSWP R%lld R%lld",x+1,x+(1ll<<w)+1);
		bad=1;
	}
}

int main()
{
	long long i,j,r,c=0;
	
	scanf("%lld",&n);
	for(nn=1;nn<n;nn*=2,c++);
	printf("%lld\n",c*(c+1)/2);
	for(i=1;1ll<<i<=nn;i++)
	{
		bad=0;
		for(j=0;j<nn;j++)
		{
			if(!(j>>i-1&1))
			{
				ad(j,i-1);
			}
		}
		printf("\n");
		for(j=i-2;j+1;j--)
		{
			bad=0;
			for(r=0;r<nn;r++)
			{
				if(!((r^r+(1ll<<j))>>i&1)&&(r>>j&1))
				{
					ad(r,j);
				}
			}
			printf("\n");
		}
	}
}

Compilation message

malnarisc.cpp: In function 'int main()':
malnarisc.cpp:33:13: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   33 |    if(!(j>>i-1&1))
      |            ~^~
malnarisc.cpp:44:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   44 |     if(!((r^r+(1ll<<j))>>i&1)&&(r>>j&1))
      |             ~^~~~~~~~~
malnarisc.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct