제출 #793397

#제출 시각아이디문제언어결과실행 시간메모리
793397rainboyRPS string (innopolis2021_final_C)C11
37 / 100
14 ms1748 KiB
#include <stdio.h>
#include <string.h>

#define N	500000

int main() {
	int t;

	scanf("%d", &t);
	while (t--) {
		static char cc[N + 1], win[N + 1];
		int d, n, i, a, b, c;

		scanf("%d%s", &d, cc), n = strlen(cc);
		for (i = 0; i < n; i++)
			if (cc[i] == 'r')
				cc[i] = 0;
			else if (cc[i] == 'p')
				cc[i] = 1;
			else
				cc[i] = 2;
		memset(win, '1', n * sizeof *win), win[n] = 0;
		if (d == 1) {
			b = 0;
			for (i = 0; i < n; i++) {
				c = cc[i];
				if ((b & 1 << (c + 1) % 3) != 0 && (b & 1 << (c + 2) % 3) == 0)
					win[i] = '0';
				b |= 1 << c;
			}
			b = 0;
			for (i = n - 1; i >= 0; i--) {
				c = cc[i];
				if ((b & 1 << (c + 1) % 3) != 0 && (b & 1 << (c + 2) % 3) == 0)
					win[i] = '0';
				b |= 1 << c;
			}
		} else {
			a = 0, b = 0;
			for (i = 0; i < n; i++) {
				c = cc[i];
				if ((b & 1 << c) == 0) {
					if ((b & 1 << (c + 1) % 3) != 0 && (b & 1 << (c + 2) % 3) == 0)
						win[i] = '0';
				} else {
					if ((b & 1 << (c + 1) % 3) == 0)
						win[i] = '0';
					else if (cc[i - 1] != (c + 2) % 3 && (a & 1 << (c + 2) % 3) == 0)
						win[i] = '0';
				}
				if (b & 1 << (c + 1) % 3)
					a |= 1 << (c + 1) % 3;
				b |= 1 << c;
			}
			a = 0, b = 0;
			for (i = n - 1; i >= 0; i--) {
				c = cc[i];
				if ((b & 1 << c) == 0) {
					if ((b & 1 << (c + 1) % 3) != 0 && (b & 1 << (c + 2) % 3) == 0)
						win[i] = '0';
				} else {
					if ((b & 1 << (c + 1) % 3) == 0)
						win[i] = '0';
					else if (cc[i + 1] != (c + 2) % 3 && (a & 1 << (c + 2) % 3) == 0)
						win[i] = '0';
				}
				if (b & 1 << (c + 1) % 3)
					a |= 1 << (c + 1) % 3;
				b |= 1 << c;
			}
		}
		printf("%s\n", win);
	}
	return 0;
}

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

Main.c: In function 'main':
Main.c:9:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
Main.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d%s", &d, cc), n = strlen(cc);
      |   ^~~~~~~~~~~~~~~~~~~~~
#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...