Submission #887529

#TimeUsernameProblemLanguageResultExecution timeMemory
887529rainboyLock Puzzle (innopolis2018_final_A)C11
100 / 100
11 ms608 KiB
#include <stdio.h>
#include <string.h>

#define N	2000
#define M	(N / 2 * 5)

char aa[N + 1], bb[N + 1], cc[N + 1]; int n;
int qu[M], m;

void shift(int k) {
	int i;

	if (k == 0)
		return;
	for (i = 0; i < n; i++)
		cc[i] = i < k ? aa[n - 1 - i] : aa[i - k];
	strcpy(aa, cc);
	qu[m++] = k;
}

int main() {
	int h, i, j;

	scanf("%d%*d%s%s", &n, aa, bb);
	m = 0;
	for (i = 0; i + 1 < n; i += 2) {
		for (j = 0; j < n - i; j++)
			if (aa[j] == bb[i])
				break;
		if (j == n - i) {
			printf("-1\n");
			return 0;
		}
		shift(n - 1 - j), shift(1);
		for (j = i + 1; j < n; j++)
			if (aa[j] == bb[i + 1])
				break;
		if (j == n) {
			printf("-1\n");
			return 0;
		}
		shift(n - j), shift(n), shift(n - j - 1);
	}
	if (i < n) {
		if (aa[0] != bb[n - 1]) {
			printf("-1\n");
			return 0;
		}
		shift(n - 1), shift(1), shift(n);
	}
	printf("%d\n", m);
	for (h = 0; h < m; h++)
		printf("%d ", qu[h]);
	printf("\n");
	return 0;
}

Compilation message (stderr)

A.c: In function 'main':
A.c:24:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d%*d%s%s", &n, aa, bb);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...